แก้ไข pagination specialTime
This commit is contained in:
parent
e0fa2d9632
commit
581229caa9
2 changed files with 94 additions and 115 deletions
|
|
@ -26,33 +26,6 @@ export const useSpecialTimeStore = defineStore("LeaveSpecialTime", () => {
|
|||
const selectDate = ref<Date | null>(new Date());
|
||||
const fiscalYear = ref<string | null>("0");
|
||||
const DataMainOrig = ref<DataRows[]>([]); // ข้อมูลหลักดั้งเดิม
|
||||
// async function fecthList(data: ListData[]) {
|
||||
// let datalist: DataRows[] = data.map((e: ListData) => ({
|
||||
// id: e.id,
|
||||
// fullname: e.fullname,
|
||||
// date: date2Thai(new Date(e.date), false, true),
|
||||
// dateFix: date2Thai(new Date(e.dateFix)),
|
||||
// timeMorning:
|
||||
// e.startTimeMorning == null
|
||||
// ? "-"
|
||||
// : e.startTimeMorning + " - " + e.endTimeMorning,
|
||||
// timeAfternoon:
|
||||
// e.startTimeAfternoon == null
|
||||
// ? "-"
|
||||
// : e.startTimeAfternoon + " - " + e.endTimeAfternoon,
|
||||
// startTimeMorning: e.startTimeMorning,
|
||||
// endTimeMorning: e.endTimeMorning,
|
||||
// startTimeAfternoon: e.startTimeAfternoon,
|
||||
// endTimeAfternoon: e.endTimeAfternoon,
|
||||
// checkIn: e.checkOut,
|
||||
// checkOut: e.checkOut,
|
||||
// status: e.status,
|
||||
// checkInStatus: convertStatus(e.checkInStatus),
|
||||
// checkOutStatus: convertStatus(e.checkOutStatus),
|
||||
// }));
|
||||
// rows.value = datalist;
|
||||
// DataMainOrig.value = datalist;
|
||||
// }
|
||||
const DataMainUpdate = ref<DataRows[]>([]); // ข้อมูลเปลี่ยนแปลง
|
||||
const DataMain = (val: DataRows[]) => (DataMainOrig.value = val);
|
||||
const DataUpdate = (filterYear: string) => {
|
||||
|
|
@ -68,15 +41,16 @@ export const useSpecialTimeStore = defineStore("LeaveSpecialTime", () => {
|
|||
const year = ref<number>(2023);
|
||||
const month = ref<number>(11);
|
||||
const page = ref<number>(1);
|
||||
const total = ref<number>(0);
|
||||
const pageSize = ref<number>(10);
|
||||
const filter = ref<string>(""); //search data table
|
||||
|
||||
const maxPage = ref<number>(0);
|
||||
// Pagination - update rowsPerPage
|
||||
async function updatePagination(newPagination: any) {
|
||||
initialPagination.value = newPagination;
|
||||
// currentPage.value = 1;
|
||||
console.log("updatePagination");
|
||||
}
|
||||
// async function updatePagination(newPagination: any) {
|
||||
// initialPagination.value = newPagination;
|
||||
// // currentPage.value = 1;
|
||||
// console.log("updatePagination");
|
||||
// }
|
||||
|
||||
// Pagination - initial pagination
|
||||
const initialPagination = ref<any>({
|
||||
|
|
@ -86,21 +60,6 @@ export const useSpecialTimeStore = defineStore("LeaveSpecialTime", () => {
|
|||
// rowsPerPage: pageSize,
|
||||
});
|
||||
|
||||
// Pagination - page & change page & get new data
|
||||
// const currentPage = ref<number>(1);
|
||||
// watch(
|
||||
// [() => currentPage.value, () => initialPagination.value.rowsPerPage],
|
||||
// () => {
|
||||
// emit(
|
||||
// "update:change-page",
|
||||
// currentPage.value,
|
||||
// initialPagination.value.rowsPerPage,
|
||||
// true
|
||||
// );
|
||||
// }
|
||||
// );
|
||||
|
||||
// const emit = defineEmits(["update:change-page"]);
|
||||
/**
|
||||
* ฟังก์ชั่น api เปลี่ยนหน้า
|
||||
* @param pageVal page
|
||||
|
|
@ -123,12 +82,16 @@ export const useSpecialTimeStore = defineStore("LeaveSpecialTime", () => {
|
|||
config.API.specialTime() +
|
||||
`?year=${year.value}&month=${month.value}&page=${page.value}&pageSize=${pageSize.value}&keyword=${filter.value}`
|
||||
)
|
||||
.then((res) => {
|
||||
let data = res.data.result;
|
||||
.then(async (res) => {
|
||||
let data = res.data.result.data;
|
||||
total.value = res.data.result.total;
|
||||
maxPage.value = await Math.ceil(total.value / pageSize.value);
|
||||
maxPage.value = maxPage.value < 1 ? 1 : maxPage.value;
|
||||
rows.value = [];
|
||||
data.map((e: any) => {
|
||||
rows.value.push({
|
||||
id: e.id,
|
||||
fullname: e.fullname,
|
||||
fullname: e.fullName,
|
||||
date: date2Thai(new Date(e.checkDate), false, true),
|
||||
dateFix: date2Thai(new Date(e.createdAt)),
|
||||
timeMorning:
|
||||
|
|
@ -299,7 +262,11 @@ export const useSpecialTimeStore = defineStore("LeaveSpecialTime", () => {
|
|||
optionStatus,
|
||||
fetchData,
|
||||
changePage,
|
||||
initialPagination,
|
||||
updatePagination,
|
||||
total,
|
||||
maxPage,
|
||||
year,
|
||||
page,
|
||||
pageSize,
|
||||
month,
|
||||
};
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue