From af7ac9e78ba1871959371c58f5fc073a73fbf82a Mon Sep 17 00:00:00 2001 From: "DESKTOP-1R2VSQH\\Lenovo ThinkPad E490" Date: Wed, 8 Oct 2025 13:42:10 +0700 Subject: [PATCH] fix(leave-history):sort --- src/components/TablePagination.vue | 1 - .../components/07_LeaveHistory/DialogForm.vue | 82 +++--- .../09_leave/views/07_LeaveHistoryMain.vue | 250 ++++++++---------- 3 files changed, 142 insertions(+), 191 deletions(-) diff --git a/src/components/TablePagination.vue b/src/components/TablePagination.vue index 02ed5960a..5c8b2d1ca 100644 --- a/src/components/TablePagination.vue +++ b/src/components/TablePagination.vue @@ -11,7 +11,6 @@ :pagination-label="paginationLabel" v-model:pagination="pagination" @request="onRequest" - :grid="!$q.screen.gt.xs" :rows-per-page-options="[10, 25, 50, 100]" :loading="loading" > diff --git a/src/modules/09_leave/components/07_LeaveHistory/DialogForm.vue b/src/modules/09_leave/components/07_LeaveHistory/DialogForm.vue index 70621f169..baef31d8a 100644 --- a/src/modules/09_leave/components/07_LeaveHistory/DialogForm.vue +++ b/src/modules/09_leave/components/07_LeaveHistory/DialogForm.vue @@ -8,6 +8,7 @@ import config from "@/app.config"; import { useCounterMixin } from "@/stores/mixin"; import { useLeaveHistoryDataStore } from "@/modules/09_leave/stores/LeaveHistoryStore"; import { calculateFiscalYear } from "@/utils/function"; +import { usePagination } from "@/composables/usePagination"; import type { QTableColumn } from "quasar"; import type { @@ -20,7 +21,7 @@ import type { } from "@/modules/09_leave/interface/response/leaveHistory"; import DialogHeader from "@/components/DialogHeader.vue"; -import { max } from "moment"; +import { co } from "@fullcalendar/core/internal-common"; /** useStore*/ const $q = useQuasar(); @@ -28,6 +29,11 @@ const { leaveTypeData } = storeToRefs(useLeaveHistoryDataStore()); const { findYear } = useLeaveHistoryDataStore(); const { dialogConfirm, showLoader, success, messageError, hideLoader } = useCounterMixin(); + +const { pagination, params, onRequest } = usePagination("", () => + onSearchData(false) +); + const modal = defineModel("modal", { required: true }); const isStatusEdit = defineModel("isStatusEdit", { required: true }); const rowData = defineModel("rowData", { @@ -42,8 +48,6 @@ const formFilter = reactive({ citizenId: "", type: "citizenId", keyword: "", - page: 1, - pageSize: 10, }); const searchTypeOption = ref([ { id: "citizenId", name: "เลขประจำตัวประชาชน" }, @@ -130,14 +134,12 @@ async function fetchDataPerson() { firstname: formFilter.type === "firstName" ? formFilter.keyword.trim() : "", //ชื่อจริง lastname: formFilter.type === "lastName" ? formFilter.keyword.trim() : "", //นามสกุล - page: formFilter.page, //หน้า - pageSize: formFilter.pageSize || 10, //จำนวนแถวต่อหน้า + ...params.value, }) .then((res) => { - const data = res.data.result; - rows.value = data.data; - total.value = data.total; - maxPage.value = Math.ceil(data.total / formFilter.pageSize); + const result = res.data.result; + pagination.value.rowsNumber = result.total; + rows.value = result.data; }) .catch((e) => { messageError($q, e); @@ -168,7 +170,7 @@ async function onSearchData(newSearch: boolean) { try { showLoader(); if (newSearch) { - formFilter.page = 1; + pagination.value.page = 1; } await fetchDataPerson(); } finally { @@ -176,28 +178,25 @@ async function onSearchData(newSearch: boolean) { } } -/** - * ฟังก์ชันอัปเดทรายการแถวต่อหน้า - * @param newPagination ข้อมูล Pagination ใหม่ - */ -function updatePagination(newPagination: DataPagination) { - formFilter.pageSize = newPagination.rowsPerPage; -} - /** ฟังก์ชันปิด Dialog*/ function onClose() { modal.value = false; formFilter.citizenId = ""; formFilter.type = "citizenId"; formFilter.keyword = ""; - formFilter.page = 1; - formFilter.pageSize = 10; formData.leaveTypeId = ""; formData.leaveYear = calculateFiscalYear(new Date()); formData.leaveDays = ""; formData.leaveDaysUsed = ""; rows.value = []; selected.value = []; + pagination.value = { + page: 1, + rowsPerPage: 10, + rowsNumber: 0, + sortBy: "", + descending: false, + }; } /** @@ -243,14 +242,6 @@ function classInput(val: boolean) { }; } -/** Hook*/ -watch( - () => formFilter.pageSize, - () => { - modal.value && onSearchData(true); - } -); - watch(modal, async (val) => { if (val) { try { @@ -278,10 +269,17 @@ watch(modal, async (val) => { /> - -
+ +
-
+
{
- { :rows-per-page-options="[10, 25, 50, 100]" selection="single" v-model:selected="selected" - @update:pagination="updatePagination" + v-model:pagination="pagination" + @request="onRequest" > - - - +
diff --git a/src/modules/09_leave/views/07_LeaveHistoryMain.vue b/src/modules/09_leave/views/07_LeaveHistoryMain.vue index 4c511a799..ffd20cb79 100644 --- a/src/modules/09_leave/views/07_LeaveHistoryMain.vue +++ b/src/modules/09_leave/views/07_LeaveHistoryMain.vue @@ -1,18 +1,17 @@