ผูก api หน้า รายการหน้าเเข่งขัน

This commit is contained in:
setthawutttty 2023-07-07 09:47:46 +07:00
parent 27b966291c
commit f3ad4d21fb
2 changed files with 58 additions and 62 deletions

View file

@ -115,7 +115,7 @@ const rows = ref<FormPlacementMainData[]>([
examOrder: 0,
fiscalYear: 0,
numberOfCandidates: 0,
examTypeValue:"",
examTypeValue: "",
examTypeName: "",
accountStartDate: "",
accountExpirationDate: "",
@ -126,23 +126,21 @@ let OriginalData = ref<FormPlacementMainData[]>([]);
let UpdataData = ref<FormPlacementMainData[]>([]);
const OriginalDataFetch = async (year: number) => {
await http
.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);
OriginalData.value = await DataStore.DataMainOrig;
UpdataData.value = OriginalData.value;
})
.catch((e: any) => {
messageError($q, e);
})
.finally(async () => {});
try {
const response = await http.get(config.API.MainDetail(year));
const apiData = response.data.result;
console.log("🚀 ~ file: Main.vue:160 ~ .then ~ res:", apiData);
await DataStore.DataMain(apiData);
OriginalData.value = await DataStore.DataMainOrig;
UpdataData.value = OriginalData.value;
} catch (error) {
messageError($q, error);
}
};
onMounted(async () => {
await fiscalYearFilter(); // await fiscalYearFilter()
await OriginalDataFetch(fiscalyear.value); // fiscalyear OriginalDataFetch()
await fiscalYearFilter();
await OriginalDataFetch(fiscalyear.value);
examTimeFilter();
await examTypeFilter();
expiredAccountFilter();
@ -151,13 +149,12 @@ onMounted(async () => {
//
const redirectToPage = (examId?: number) => {
// router.push({ name: 'placementDetail'});
router.push(`/placement/pass/${examId}`);
};
//
//-------------------||-----------------------//
const fiscalyear = ref<number>(0);
const fiscalyearOP = reactive<DataOption[]>([{ id: "", name: "ทั้งหมด" }]);
const fiscalyearOP = reactive<DataOption[]>([{ id: null, name: "ทั้งหมด" }]);
const addedfiscalYearValues: number[] = [];
const fiscalYearFilter = async () => {
let maxYear = 0; // maxYear
@ -182,22 +179,19 @@ const fiscalYearFilter = async () => {
});
};
// API
//-------------------| API|--------------------//
const searchfiscalyear = async () => {
console.log("Input value changed:", fiscalyear.value);
// API
await http
.get(config.API.yearOptions())
.then((res: any) => {
console.log("🚀date", res);
})
.then((res: any) => {})
.catch((e: any) => {
messageError($q, e);
})
.finally(async () => {});
};
//
//-------------------||-----------------//
const filterKeyword = ref<string>("");
const filterRef = ref<any>(null);
const resetFilter = () => {
@ -216,37 +210,40 @@ const visibleColumns = ref<any[]>([
"examTypeName",
"accountStartDate",
"accountExpirationDate",
]); //
]);
//-------------------||------------------------------//
const examTime = ref<number | string>("all");
const examTimeOP = reactive<DataOption[]>([]);
const addedExamTimeValues: Set<number> = new Set();
//
const examTime = ref<number | null>(null);
const examTimeOP = ref<number[]>([]);
const examTimeFilter = async () => {
for (let data of OriginalData.value) {
if (!examTimeOP.value.includes(data.examOrder)) {
examTimeOP.value.push(data.examOrder);
examTimeOP.push({ id: "all", name: "ทั้งหมด" });
for (const data of OriginalData.value) {
const examOrder = data.examOrder;
if (examOrder !== null && !addedExamTimeValues.has(examOrder)) {
examTimeOP.push({ id: examOrder.toString(), name: examOrder.toString() });
addedExamTimeValues.add(examOrder);
}
}
examTimeOP.value.sort((a, b) => a - b); //
examTimeOP.sort((a, b) => {
if (a.id === "all") return -1; // ""
if (b.id === "all") return 1;
return Number(a.id) - Number(b.id);
}); // id
};
//
const examType = ref<string | null>("");
const examTypeOP = reactive<DataOption[]>([
{ id: "", name: "ทั้งหมด" },
]);
const examType = ref<string | null>("all");
const examTypeOP = ref<DataOption[]>([{ id: "all", name: "ทั้งหมด" }]);
const addedExamTypeValues: Set<string> = new Set();
const examTypeFilter = async () => {
const examTypeFilter = () => {
for (const data of OriginalData.value) {
const examTypeName = data.examTypeName;
const examTypeValue = data.examTypeValue;
if (
examTypeName &&
!addedExamTypeValues.has(examTypeName)
) {
examTypeOP.push({
if (examTypeName && !addedExamTypeValues.has(examTypeName)) {
examTypeOP.value.push({
id: examTypeValue,
name: examTypeName,
});
@ -254,8 +251,7 @@ const addedExamTypeValues: Set<string> = new Set();
}
}
};
//--------------||--------------------------------------//
const searchFilterTable = async () => {
if (examType.value !== undefined && examType.value !== null) {
await DataStore.DataUpdateMain(
@ -267,7 +263,7 @@ const searchFilterTable = async () => {
}
};
//
//----------------||-----------------------------//
const expiredAccount = ref<boolean>(false);
const expiredAccountFilter = async () => {
const currentDate = new Date();
@ -382,9 +378,9 @@ const paginationLabel = (start: string, end: string, total: string) => {
dense
emit-value
map-options
option-label="examTypeName"
option-label="name"
:options="examTypeOP"
option-value="examTypeValue"
option-value="id"
lazy-rules
hide-bottom-space
:readonly="false"

View file

@ -104,33 +104,33 @@ export const usePlacementDataStore = defineStore("placement", () => {
(DataMainYear.value = val);
const DataMain = (val: FormPlacementMainData[]) => (DataMainOrig.value = val);
const DataUpdateMain = (
filter_1: number | null,
filter_1: number | string,
filter_2: string | null,
filter_3: boolean
) => {
DataMainUpdate.value = [];
if (filter_1 === null && filter_2 === "" && filter_3 === false) {
if (filter_1 === "all" && filter_2 === "all" && 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 === "" && filter_3 === false) {
} else if (filter_1 === "all" && filter_2 === "all" && 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 === "" && filter_3 === false) {
} else if (filter_1 !== "all" && filter_2 === "all" && filter_3 === false) {
// console.log('case 2');
return (DataMainUpdate.value = DataMainOrig.value.filter(
(item) => item.examOrder === filter_1 && item.isExpired === filter_3
));
} else if (filter_1 !== null && filter_2 === "" && filter_3 === false) {
} else if (filter_1 !== "all" && filter_2 === "all" && filter_3 === false) {
// console.log('case 2.1');
return (DataMainUpdate.value = DataMainOrig.value.filter(
(item) => item.examOrder === filter_1 && item.isExpired === filter_3
));
} else if (filter_1 !== null && filter_2 !== "" && filter_3 === false) {
} else if (filter_1 !== "all" && filter_2 !== "all" && filter_3 === false) {
// console.log('case 2.2');
return (DataMainUpdate.value = DataMainOrig.value.filter(
(item) =>
@ -138,32 +138,32 @@ export const usePlacementDataStore = defineStore("placement", () => {
item.examTypeValue === filter_2 &&
item.isExpired === filter_3
));
} else if (filter_1 === null && filter_2 !== "" && filter_3 === false) {
} else if (filter_1 === "all" && filter_2 !== "all" && filter_3 === false) {
// console.log('case 3');
return (DataMainUpdate.value = DataMainOrig.value.filter(
(item) => item.examTypeValue === filter_2 && item.isExpired === filter_3
));
} else if (filter_1 === null && filter_2 === "" && filter_3 === true) {
} else if (filter_1 === "all" && filter_2 === "all" && 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 === "" && filter_3 === true) {
} else if (filter_1 === "all" && filter_2 === "all" && 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 === "" && filter_3 === true) {
} else if (filter_1 !== "all" && filter_2 === "all" && filter_3 === true) {
// console.log('case 3.3');
return (DataMainUpdate.value = DataMainOrig.value.filter(
(item) => item.examOrder == filter_1 && item.isExpired == filter_3
));
} else if (filter_1 !== null && filter_2 === "" && filter_3 === true) {
} else if (filter_1 !== "all" && filter_2 === "all" && filter_3 === true) {
// console.log('case 3.4');
return (DataMainUpdate.value = DataMainOrig.value.filter(
(item) => item.examOrder == filter_1 && item.isExpired == filter_3
));
} else if (filter_1 !== null && filter_2 !== "" && filter_3 === true) {
} else if (filter_1 !== "all" && filter_2 !== "all" && filter_3 === true) {
// console.log('case 3.5');
return (DataMainUpdate.value = DataMainOrig.value.filter(
(item) =>
@ -171,7 +171,7 @@ export const usePlacementDataStore = defineStore("placement", () => {
item.examTypeValue == filter_2 &&
item.isExpired == filter_3
));
} else if (filter_1 === null && filter_2 !== "" && filter_3 === true) {
} else if (filter_1 === "all" && filter_2 !== "all" && filter_3 === true) {
// console.log('case 3.6');
return (DataMainUpdate.value = DataMainOrig.value.filter(
(item) => item.examTypeValue == filter_2 && item.isExpired == filter_3