diff --git a/src/api/05_placement/api.placement.ts b/src/api/05_placement/api.placement.ts index cc5248697..76ac2d2de 100644 --- a/src/api/05_placement/api.placement.ts +++ b/src/api/05_placement/api.placement.ts @@ -2,7 +2,7 @@ import env from "../index" const placement = `${env.API_URI}/Placement/placement` export default { - MainDetail: () => `${placement}`, + MainDetail: (year:number) => `${placement}/exam/${year}`, yearOptions: () => `${placement}/fiscal`, redirectToPage: (examId:string) => `${placement}/pass/${examId}`, } \ No newline at end of file diff --git a/src/modules/05_placement/components/Main.vue b/src/modules/05_placement/components/Main.vue index 384a9cb6c..b01465ec0 100644 --- a/src/modules/05_placement/components/Main.vue +++ b/src/modules/05_placement/components/Main.vue @@ -33,73 +33,73 @@ const columns = ref([ style: "font-size: 14px", }, { - name: "name", + name: "examRound", align: "left", label: "รอบการสอบ", sortable: true, - field: "name", + field: "examRound", headerStyle: "font-size: 14px", style: "font-size: 14px", sort: (a: string, b: string) => a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }), }, { - name: "round", + name: "examOrder", align: "left", label: "ครั้งที่", sortable: true, - field: "round", + field: "examOrder", headerStyle: "font-size: 14px", style: "font-size: 14px", }, { - name: "year", + name: "fiscalYear", align: "left", label: "ปีงบประมาณ", sortable: true, - field: "year", + field: "fiscalYear", headerStyle: "font-size: 14px", style: "font-size: 14px", }, { - name: "number", + name: "numberOfCandidates", align: "left", label: "จำนวนผู้สอบได้", sortable: false, - field: "number", + field: "numberOfCandidates", headerStyle: "font-size: 14px", style: "font-size: 14px", sort: (a: string, b: string) => a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }), }, { - name: "placementType", + name: "examTypeName", align: "left", label: "ประเภทการสอบ", sortable: false, - field: "placementType", + field: "examTypeName", headerStyle: "font-size: 14px", style: "font-size: 14px", sort: (a: string, b: string) => a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }), }, { - name: "startDate", + name: "accountStartDate", align: "left", label: "วันที่เริ่มคำสั่ง", sortable: true, - field: "startDate", + field: "accountStartDate", headerStyle: "font-size: 14px", style: "font-size: 14px", sort: (a: string, b: string) => a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }), }, { - name: "endDate", + name: "accountExpirationDate", align: "left", label: "วันที่บัญชีหมดอายุ", sortable: true, - field: "endDate", + field: "accountExpirationDate", headerStyle: "font-size: 14px", style: "font-size: 14px", sort: (a: string, b: string) => @@ -111,23 +111,23 @@ const columns = ref([ const rows = ref([ { id: 0, - name: "", - round:0 , - year: 0, - number: 0, - placementType: 0, - startDate: "", - endDate: "", + examRound: "", + examOrder: 0, + fiscalYear: 0, + numberOfCandidates: 0, + examTypeValue:"", + examTypeName: "", + accountStartDate: "", + accountExpirationDate: "", }, - ]); let OriginalData = ref([]); let UpdataData = ref([]); -const OriginalDataFetch = async () => { +const OriginalDataFetch = async (year: number) => { await http - .get(config.API.MainDetail()) + .get(config.API.MainDetail(year)) // ส่งปีที่เลือกมาเป็นอาร์กิวเมนต์ในการเรียก API .then(async (res: any) => { console.log("🚀 ~ file: Main.vue:160 ~ .then ~ res:", res.data.result); await DataStore.DataMain(res.data.result); @@ -141,12 +141,12 @@ const OriginalDataFetch = async () => { }; onMounted(async () => { - await OriginalDataFetch(); - fiscalYearFilter(); + await fiscalYearFilter(); // เรียกใช้ await เพื่อรอให้ fiscalYearFilter() เสร็จสิ้น + await OriginalDataFetch(fiscalyear.value); // ส่งค่าปีที่เลือกจาก fiscalyear เป็นอาร์กิวเมนต์ให้กับ OriginalDataFetch() examTimeFilter(); - examTypeFilter(); - await expiredAccountFilter(); - searchFilterTable(); + await examTypeFilter(); + expiredAccountFilter(); + await searchFilterTable(); }); // ดูรายการสอบแข่งขัน หน้าต่อไป @@ -156,25 +156,30 @@ const redirectToPage = (examId?: number) => { }; // เลือกปีงบประมาณ -const fiscalyear = ref(0); -const fiscalyearOP = reactive([{ id: 0, name: "ทั้งหมด" }]); +const fiscalyear = ref(0); +const fiscalyearOP = reactive([{ id: "", name: "ทั้งหมด" }]); const addedfiscalYearValues: number[] = []; const fiscalYearFilter = async () => { - // API + let maxYear = 0; // เพิ่มตัวแปร maxYear await http .get(config.API.yearOptions()) .then((res: any) => { console.log("🚀 ", res.data.result); for (let data of res.data.result) { fiscalyearOP.push(data); + + if (data.id > maxYear) { + maxYear = data.id; // อัพเดตค่า maxYear ถ้าพบปีที่มากกว่า + } } - // DataStore.DataMainYearSet(rows.value); - // fiscalyearOP.value = DataStore.DataMainYearGet; }) .catch((e: any) => { messageError($q, e); }) - .finally(async () => {}); + .finally(async () => { + // ตั้งค่า fiscalyear เป็นค่าหลักปีที่มากที่สุด + fiscalyear.value = maxYear; + }); }; // เลือกปีงบประมาณตาม API @@ -202,14 +207,15 @@ const resetFilter = () => { const attrs = ref(useAttrs()); const visibleColumns = ref([ -"id", -"name", -"round", -"year", -"number", -"placementType", -"startDate", -"endDate", + "id", + "examRound", + "examOrder", + "fiscalYear", + "numberOfCandidates", + "examTypeValue", + "examTypeName", + "accountStartDate", + "accountExpirationDate", ]); //ค้นหา คอลัมน์ คอลัมน์ที่แสดง // ครั้งที่สอบ @@ -217,38 +223,48 @@ const examTime = ref(null); const examTimeOP = ref([]); const examTimeFilter = async () => { for (let data of OriginalData.value) { - if (!examTimeOP.value.includes(data.round)) { - examTimeOP.value.push(data.round); + if (!examTimeOP.value.includes(data.examOrder)) { + examTimeOP.value.push(data.examOrder); } } examTimeOP.value.sort((a, b) => a - b); // เรียงลำดับ }; // ประเภทการสอบ -const examType = ref(0); -const examTypeOP = reactive([{ id: 0, name: "ทั้งหมด" }]); -const addedexamTypeValues: number[] = []; -const examTypeFilter = async () => { - for (let data of OriginalData.value) { - const examTypeValue = data.placementType; - if (examTypeValue == 1 && !addedexamTypeValues.includes(1)) { - examTypeOP.push({ id: 1, name: "คัดเลือก" }); - addedexamTypeValues.push(1); - } else if (examTypeValue == 2 && !addedexamTypeValues.includes(2)) { - examTypeOP.push({ id: 2, name: "สอบแข่งขัน" }); - addedexamTypeValues.push(2); + +const examType = ref(""); +const examTypeOP = reactive([ + { id: "", name: "ทั้งหมด" }, +]); +const addedExamTypeValues: Set = new Set(); + const examTypeFilter = async () => { + for (const data of OriginalData.value) { + const examTypeName = data.examTypeName; + const examTypeValue = data.examTypeValue; + + if ( + examTypeName && + !addedExamTypeValues.has(examTypeName) + ) { + examTypeOP.push({ + id: examTypeValue, + name: examTypeName, + }); + addedExamTypeValues.add(examTypeName); } } }; + const searchFilterTable = async () => { - // console.log('Input value changed:', examTime.value, examType.value, expiredAccount.value); - await DataStore.DataUpdateMain( - examTime.value, - examType.value, - expiredAccount.value - ); - UpdataData.value = DataStore.DataMainUpdate; + if (examType.value !== undefined && examType.value !== null) { + await DataStore.DataUpdateMain( + examTime.value, + examType.value, + expiredAccount.value + ); + UpdataData.value = DataStore.DataMainUpdate; + } }; // บัญชีหมดอายุ @@ -256,7 +272,7 @@ const expiredAccount = ref(false); const expiredAccountFilter = async () => { const currentDate = new Date(); const updatedRows = OriginalData.value.map((data) => { - let expirationDate = new Date(data.endDate); + let expirationDate = new Date(data.accountExpirationDate); let isExpired = expirationDate < currentDate; return { ...data, isExpired }; @@ -366,9 +382,9 @@ const paginationLabel = (start: string, end: string, total: string) => { dense emit-value map-options - option-label="name" + option-label="examTypeName" :options="examTypeOP" - option-value="id" + option-value="examTypeValue" lazy-rules hide-bottom-space :readonly="false" @@ -421,28 +437,28 @@ const paginationLabel = (start: string, end: string, total: string) => { @click="redirectToPage(props.row.id)" > - {{ props.rowIndex+1 }} + {{ props.rowIndex + 1 }} - - {{ props.row.name }} + + {{ props.row.examRound }} - - {{ props.row.round }} + + {{ props.row.examOrder }} - - {{ props.row.year + 543 }} + + {{ props.row.fiscalYear }} - - {{ props.row.number }} + + {{ props.row.numberOfCandidates }} - - {{ props.row.placementType == 1 ? "คัดเลือก" : "สอบแข่งขัน" }} + + {{ props.row.examTypeName }} - - {{ textDate(props.row.startDate) }} + + {{ textDate(props.row.accountStartDate) }} - - {{ textDate(props.row.endDate) }} + + {{ textDate(props.row.accountExpirationDate) }} diff --git a/src/modules/05_placement/interface/index/Main.ts b/src/modules/05_placement/interface/index/Main.ts index 1e46a9961..9a87a2ece 100644 --- a/src/modules/05_placement/interface/index/Main.ts +++ b/src/modules/05_placement/interface/index/Main.ts @@ -1,7 +1,7 @@ import type { zipCodeOption } from "../../components/PersonalDetail/profileType"; interface DataOption { - id: number | string; - name: string; + id: string|null; + name:string|null; disable?: boolean; } diff --git a/src/modules/05_placement/interface/request/Main.ts b/src/modules/05_placement/interface/request/Main.ts index 13d6cd0a9..a86e0dce2 100644 --- a/src/modules/05_placement/interface/request/Main.ts +++ b/src/modules/05_placement/interface/request/Main.ts @@ -1,13 +1,14 @@ // ข้อมูลรายการสอบแข่งขัน/คัดเลือก interface FormPlacementMainData { id: number; - name: string; - round: number; - year: number; - number: number; - placementType: number; - startDate: string; - endDate: string; + examRound: string; + examOrder: number; + fiscalYear: number; + numberOfCandidates: number; + examTypeValue:string; + examTypeName: string; + accountStartDate: string; + accountExpirationDate: string; isExpired?: boolean; } diff --git a/src/modules/05_placement/store.ts b/src/modules/05_placement/store.ts index 4d0c90cc0..cc7bd90b5 100644 --- a/src/modules/05_placement/store.ts +++ b/src/modules/05_placement/store.ts @@ -105,76 +105,76 @@ export const usePlacementDataStore = defineStore("placement", () => { const DataMain = (val: FormPlacementMainData[]) => (DataMainOrig.value = val); const DataUpdateMain = ( filter_1: number | null, - filter_2: number | null, + filter_2: string | null, filter_3: boolean ) => { DataMainUpdate.value = []; - if (filter_1 === null && filter_2 === 0 && filter_3 === false) { + if (filter_1 === null && filter_2 === "" && filter_3 === false) { // console.log('case 1'); // return DataMainUpdate.value = DataMainOrig.value; อันเก่า return (DataMainUpdate.value = DataMainOrig.value.filter( (item) => item.isExpired === filter_3 )); - } else if (filter_1 === null && filter_2 === null && filter_3 === false) { + } else if (filter_1 === null && filter_2 === "" && filter_3 === false) { // console.log('case 1.1'); return (DataMainUpdate.value = DataMainOrig.value.filter( (item) => item.isExpired === filter_3 )); - } else if (filter_1 !== null && filter_2 === 0 && filter_3 === false) { + } else if (filter_1 !== null && filter_2 === "" && filter_3 === false) { // console.log('case 2'); return (DataMainUpdate.value = DataMainOrig.value.filter( - (item) => item.round === filter_1 && item.isExpired === filter_3 + (item) => item.examOrder === filter_1 && item.isExpired === filter_3 )); - } else if (filter_1 !== null && filter_2 === null && filter_3 === false) { + } else if (filter_1 !== null && filter_2 === "" && filter_3 === false) { // console.log('case 2.1'); return (DataMainUpdate.value = DataMainOrig.value.filter( - (item) => item.round === filter_1 && item.isExpired === filter_3 + (item) => item.examOrder === filter_1 && item.isExpired === filter_3 )); - } else if (filter_1 !== null && filter_2 !== 0 && filter_3 === false) { + } else if (filter_1 !== null && filter_2 !== "" && filter_3 === false) { // console.log('case 2.2'); return (DataMainUpdate.value = DataMainOrig.value.filter( (item) => - item.round === filter_1 && - item.placementType === filter_2 && + item.examOrder === filter_1 && + item.examTypeValue === filter_2 && item.isExpired === filter_3 )); - } else if (filter_1 === null && filter_2 !== 0 && filter_3 === false) { + } else if (filter_1 === null && filter_2 !== "" && filter_3 === false) { // console.log('case 3'); return (DataMainUpdate.value = DataMainOrig.value.filter( - (item) => item.placementType === filter_2 && item.isExpired === filter_3 + (item) => item.examTypeValue === filter_2 && item.isExpired === filter_3 )); - } else if (filter_1 === null && filter_2 === 0 && filter_3 === true) { + } else if (filter_1 === null && filter_2 === "" && filter_3 === true) { // console.log('case 3.1'); return (DataMainUpdate.value = DataMainOrig.value.filter( (item) => item.isExpired === filter_3 )); - } else if (filter_1 === null && filter_2 === null && filter_3 === true) { + } else if (filter_1 === null && filter_2 === "" && filter_3 === true) { // console.log('case 3.2'); return (DataMainUpdate.value = DataMainOrig.value.filter( (item) => item.isExpired === filter_3 )); - } else if (filter_1 !== null && filter_2 === 0 && filter_3 === true) { + } else if (filter_1 !== null && filter_2 === "" && filter_3 === true) { // console.log('case 3.3'); return (DataMainUpdate.value = DataMainOrig.value.filter( - (item) => item.round == filter_1 && item.isExpired == filter_3 + (item) => item.examOrder == filter_1 && item.isExpired == filter_3 )); - } else if (filter_1 !== null && filter_2 === null && filter_3 === true) { + } else if (filter_1 !== null && filter_2 === "" && filter_3 === true) { // console.log('case 3.4'); return (DataMainUpdate.value = DataMainOrig.value.filter( - (item) => item.round == filter_1 && item.isExpired == filter_3 + (item) => item.examOrder == filter_1 && item.isExpired == filter_3 )); - } else if (filter_1 !== null && filter_2 !== 0 && filter_3 === true) { + } else if (filter_1 !== null && filter_2 !== "" && filter_3 === true) { // console.log('case 3.5'); return (DataMainUpdate.value = DataMainOrig.value.filter( (item) => - item.round == filter_1 && - item.placementType == filter_2 && + item.examOrder == filter_1 && + item.examTypeValue == filter_2 && item.isExpired == filter_3 )); - } else if (filter_1 === null && filter_2 !== 0 && filter_3 === true) { + } else if (filter_1 === null && filter_2 !== "" && filter_3 === true) { // console.log('case 3.6'); return (DataMainUpdate.value = DataMainOrig.value.filter( - (item) => item.placementType == filter_2 && item.isExpired == filter_3 + (item) => item.examTypeValue == filter_2 && item.isExpired == filter_3 )); } };