diff --git a/src/modules/09_leave/components/4_specialTime/DialogApprove.vue b/src/modules/09_leave/components/4_specialTime/DialogApprove.vue index 5d0615ac3..f0b422790 100644 --- a/src/modules/09_leave/components/4_specialTime/DialogApprove.vue +++ b/src/modules/09_leave/components/4_specialTime/DialogApprove.vue @@ -104,6 +104,7 @@ const approveData = async () => { hideLoader(); }) .finally(async () => { + SpecialTimeStore.fetchData(); hideLoader(); }); }; diff --git a/src/modules/09_leave/interface/request/specialTime.ts b/src/modules/09_leave/interface/request/specialTime.ts index fa44490f8..f11b3a282 100644 --- a/src/modules/09_leave/interface/request/specialTime.ts +++ b/src/modules/09_leave/interface/request/specialTime.ts @@ -13,4 +13,9 @@ interface ListData { checkOut: string; checkIn: string; } -export type { ListData }; + +interface DataDateMonthObject { + month: number; + year: number; +} +export type { ListData, DataDateMonthObject }; diff --git a/src/modules/09_leave/stores/SpecialTimeStore.ts b/src/modules/09_leave/stores/SpecialTimeStore.ts index 0735dcdaa..ecdd6ffd8 100644 --- a/src/modules/09_leave/stores/SpecialTimeStore.ts +++ b/src/modules/09_leave/stores/SpecialTimeStore.ts @@ -2,12 +2,14 @@ import { defineStore } from "pinia"; import { ref, watch, defineEmits } from "vue"; import type { QTableProps } from "quasar"; import type { DataRows } from "@/modules/09_leave/interface/response/specialTime"; -import type { ListData } from "@/modules/09_leave/interface/request/specialTime"; +import type { DataDateMonthObject } from "@/modules/09_leave/interface/request/specialTime"; + import { useCounterMixin } from "@/stores/mixin"; import type { DataOption } from "@/modules/09_leave/interface/index/Main"; import http from "@/plugins/http"; import config from "@/app.config"; import { useQuasar } from "quasar"; +import { mount } from "@vue/test-utils"; const $q = useQuasar(); const mixin = useCounterMixin(); @@ -45,32 +47,6 @@ export const useSpecialTimeStore = defineStore("LeaveSpecialTime", () => { const pageSize = ref(10); const filter = ref(""); //search data table const maxPage = ref(0); - // Pagination - update rowsPerPage - // async function updatePagination(newPagination: any) { - // initialPagination.value = newPagination; - // // currentPage.value = 1; - // console.log("updatePagination"); - // } - - // Pagination - initial pagination - const initialPagination = ref({ - sortBy: null, - descending: false, - page: 1, - // rowsPerPage: pageSize, - }); - - /** - * ฟังก์ชั่น api เปลี่ยนหน้า - * @param pageVal page - * @param pageSizeVal pagesize - */ - async function changePage(pageVal: number, pageSizeVal: number) { - page.value = await pageVal; - pageSize.value = await pageSizeVal; - console.log("changePage"); - fetchData(); - } /** * ฟังชั้นเรียกดูข้อมูล @@ -126,6 +102,19 @@ export const useSpecialTimeStore = defineStore("LeaveSpecialTime", () => { }); }; + /** + * ฟังก์ชั่น api เปลี่ยนหน้า + * @param pageVal page + * @param pageSizeVal pagesize + */ + async function changePage(pageVal: number, pageSizeVal: number) { + page.value = await pageVal; + pageSize.value = await pageSizeVal; + console.log(pageSize.value); + + fetchData(); + } + //--------------|ฟิลเตอร์|--------------------------------------// const searchFilterTable = async (searchDate: any) => { rows.value = []; @@ -268,5 +257,7 @@ export const useSpecialTimeStore = defineStore("LeaveSpecialTime", () => { page, pageSize, month, + filter, + // changeMonth, }; }); diff --git a/src/modules/09_leave/views/SpecialTimeMain.vue b/src/modules/09_leave/views/SpecialTimeMain.vue index 42021a04e..3868106c5 100644 --- a/src/modules/09_leave/views/SpecialTimeMain.vue +++ b/src/modules/09_leave/views/SpecialTimeMain.vue @@ -8,7 +8,7 @@ import DialogReason from "@/components/Dialogs/PopupReason.vue"; import DialogApprove from "@/modules/09_leave/components/4_specialTime/DialogApprove.vue"; import http from "@/plugins/http"; import config from "@/app.config"; - +import type { DataDateMonthObject } from "@/modules/09_leave/interface/request/specialTime"; import { useRouter } from "vue-router"; import { identity } from "@fullcalendar/core/internal"; @@ -28,6 +28,7 @@ const name = ref(""); const id = ref(""); const dateDialog = ref(""); const dateFixDialog = ref(""); +const dateYear = ref(new Date().getFullYear()); /**ฟังก์ชั่นไม่อนุมัติ */ const unapprove = async (fullname: string, personId: string) => { @@ -35,6 +36,7 @@ const unapprove = async (fullname: string, personId: string) => { dialogTitle.value = " ไม่อนุมัติการลงเวลาพิเศษของ" + fullname; name.value = fullname; modalUnapprove.value = true; + // rejectData(); }; @@ -79,35 +81,20 @@ const clickSave = async (reason: string) => { .catch((e) => { messageError($q, e); }) - .finally(async () => {}); + .finally(async () => { + dataSpecialTime.fetchData(); + }); + console.log(reason); }; -// ค้นหาในตาราง -const filterKeyword = ref(""); -const filterRef = ref(null); -const resetFilter = () => { - filterKeyword.value = ""; - if (filterRef.value) { - filterRef.value.focus(); - } -}; - // paging -const page = ref(1); const pageSize = ref(10); -const filter = ref(""); //search data table /** * ฟังก์ชั่น api เปลี่ยนหน้า * @param pageVal page * @param pageSizeVal pagesize */ -async function changePage(pageVal: number, pageSizeVal: number) { - // page.value = await pageVal; - // pageSize.value = await pageSizeVal; - // dataSpecialTime.fetchData(); - console.log("test"); -} // Pagination - initial pagination const initialPagination = ref({ sortBy: null, @@ -123,21 +110,36 @@ watch( async () => { dataSpecialTime.page = currentPage.value; await dataSpecialTime.fetchData(); - // emit( - // "update:change-page", - // currentPage.value, - // initialPagination.value.rowsPerPage, - // true - // ); } ); + // Pagination - update rowsPerPage -async function updatePagination(newPagination: any) { +async function updatePagination(initialPagination: any) { currentPage.value = 1; - dataSpecialTime.pageSize = initialPagination.value.rowsPerPage; + dataSpecialTime.pageSize = initialPagination.rowsPerPage; dataSpecialTime.page = 1; // set current page เป็น 1 เสมอเมื่อเปลี่ยน per row } +// ค้นหาในตาราง +const filterKeyword = ref(""); +const filterRef = ref(null); +const resetFilter = () => { + filterKeyword.value = ""; + dataSpecialTime.filter = filterKeyword.value; + dataSpecialTime.fetchData(); + if (filterRef.value) { + filterRef.value.focus(); + } +}; +/** function ค้นหาข้อมูลแล้วอัปเดท*/ +function filterFn() { + updatePagination(filterKeyword.value); + console.log(filterKeyword.value); + dataSpecialTime.filter = filterKeyword.value; + dataSpecialTime.pageSize = pageSize.value; + dataSpecialTime.fetchData(); +} + /**Hook */ onMounted(async () => { console.log("test"); @@ -145,11 +147,23 @@ onMounted(async () => { }); /** Function Date */ -const selectedDate = ref(""); const dateMonth = ref({ month: new Date().getMonth(), year: new Date().getFullYear(), }); +const updateMonth = async (e: DataDateMonthObject) => { + // console.log(dateMonth.value); + if (e != null) { + dateYear.value = e.year; + dateYear.value = dataSpecialTime.year; + dataSpecialTime.month = dateMonth.value.month + 1; + dataSpecialTime.year = dateMonth.value.year; + // filterKeyword.value = ""; + } + await dataSpecialTime.fetchData(); +}; + +//แปลงเดือนเป็นไทย const monthYearThai = (val: any) => { if (val == null) return ""; else return monthYear2Thai(val.month, val.year); @@ -164,11 +178,12 @@ const monthYearThai = (val: any) => {