diff --git a/src/modules/18_command/components/DialogCreateCommand.vue b/src/modules/18_command/components/DialogCreateCommand.vue index 393a5e2b2..0c8d17e03 100644 --- a/src/modules/18_command/components/DialogCreateCommand.vue +++ b/src/modules/18_command/components/DialogCreateCommand.vue @@ -7,6 +7,7 @@ import config from "@/app.config"; import { useRouter } from "vue-router"; import { useCounterMixin } from "@/stores/mixin"; import { useCommandMainStore } from "@/modules/18_command/store/Main"; +import { usePagination } from "@/composables/usePagination"; import type { QTableProps } from "quasar"; import type { @@ -25,6 +26,7 @@ const $q = useQuasar(); const mixin = useCounterMixin(); const { showLoader, messageError, dialogConfirm, hideLoader, date2Thai } = mixin; +const { pagination, params, onRequest } = usePagination("", getListCommandDraf); /** props*/ const modal = defineModel("modal", { required: true }); @@ -52,8 +54,6 @@ const commandChapter = ref(""); //ตอนที่ const rows = ref([]); // รายการคำสั่ง const selected = ref([]); // id คำสั่งที่เลือก const filter = ref(""); // คำค้นหา -const total = ref(0); //จำนวนรายการ -const totalList = ref(1); //จำนวนหน้า const visibleColumns = ref([ "commandNo", "issue", @@ -67,7 +67,7 @@ const columns = ref([ name: "commandNo", align: "left", label: "เลขที่คำสั่ง", - sortable: false, + sortable: true, field: "commandNo", format(val, row) { return val ? `${val}/${row.commandYear + 543}` : "-"; @@ -88,7 +88,7 @@ const columns = ref([ name: "commandAffectDate", align: "left", label: "วันที่ลงนาม", - sortable: false, + sortable: true, field: "commandAffectDate", format(val) { return val ? date2Thai(val) : "-"; @@ -100,7 +100,7 @@ const columns = ref([ name: "commandExcecuteDate", align: "left", label: "วันที่คำสั่งมีผล", - sortable: false, + sortable: true, field: "commandExcecuteDate", format(val) { return val ? date2Thai(val) : "-"; @@ -112,7 +112,7 @@ const columns = ref([ name: "createdFullName", align: "left", label: "ผู้สร้าง", - sortable: false, + sortable: true, field: "createdFullName", headerStyle: "font-size: 14px", style: "font-size: 14px", @@ -127,12 +127,6 @@ const columns = ref([ style: "font-size: 14px", }, ]); -const pagination = ref({ - sortBy: "createdAt", - descending: true, - page: 1, - rowsPerPage: 10, -}); const selectCreate = ref("NEW"); //ประเภทการออกคำสั่ง สร้างใหม่/คำสั่งแบบร่าง @@ -140,16 +134,19 @@ const selectCreate = ref("NEW"); //ประเภทการอ async function getListCommandDraf() { showLoader(); await http - .get( - config.API.commandList + - `?page=${pagination.value.page}&pageSize=${pagination.value.rowsPerPage}&year=${commandYear.value}&keyword=${filter.value}&status=DRAFT&commandTypeId=${commandType.value}` - ) + .get(config.API.commandList, { + params: { + ...params.value, + year: commandYear.value, + keyword: filter.value.trim(), + status: "DRAFT", + commandTypeId: commandType.value, + }, + }) .then(async (res) => { - totalList.value = Math.ceil( - res.data.result.total / pagination.value.rowsPerPage - ); - total.value = res.data.result.total; - rows.value = res.data.result.data; + const result = res.data.result; + pagination.value.rowsNumber = result.total; + rows.value = result.data; }) .catch((err) => { messageError($q, err); @@ -179,19 +176,6 @@ function createCommand(isRedirect: boolean) { posLevel: e.posLevel, ...(e.remarkVertical ? { remarkVertical: e.remarkVertical } : {}), ...(e.remarkHorizontal ? { remarkHorizontal: e.remarkHorizontal } : {}), - - // ...(props.commandTypeCode == "C-PM-01" || - // props.commandTypeCode == "C-PM-02" - // ? { position: e.position ? e.position : null } - // : {}), - // ...(props.commandTypeCode == "C-PM-01" || - // props.commandTypeCode == "C-PM-02" - // ? { posType: e.posType ? e.posType : null } - // : {}), - // ...(props.commandTypeCode == "C-PM-01" || - // props.commandTypeCode == "C-PM-02" - // ? { posLevel: e.posLevel ? e.posLevel : null } - // : {}), })); const body = { @@ -310,15 +294,6 @@ async function fetchCommandType() { commandCode.value = commandOp.value[0].code; } -/** - * ฟังก์ชันอัปเดทจำนวนแถวต่อหน้า - * @param newPagination จำนวนแถวที่ต้องการ - */ -function updatePagination(newPagination: Pagination) { - pagination.value.page = 1; - pagination.value.rowsPerPage = newPagination.rowsPerPage; -} - const isHold = ref(true); // true คือแสดงปุ่มบันทึกและเลือกรายชื่อต่อ / false คือซ่อนปุ่มบันทึกและเลือกรายชื่อต่อ // tab สร้างคำสั่งใหม่ และเลือกคำสั่งที่เป็นแบบร่าง const tabOptions = ref([ @@ -340,14 +315,6 @@ async function displayTab() { : [{ label: "สร้างคำสั่งใหม่", value: "NEW" }]; } -/** ดูการเปลี่ยนแปลงของจำนวนแถวต่อหน้า*/ -watch( - () => pagination.value.rowsPerPage, - async () => { - await getListCommandDraf(); - } -); - /** ดูการเปลี่ยนแปลงของ modal*/ watch(modal, () => { if (modal.value && props.persons?.length !== 0) { @@ -561,7 +528,7 @@ watch( />
- - - - +
diff --git a/src/modules/18_command/components/DialogCreateCommandORG.vue b/src/modules/18_command/components/DialogCreateCommandORG.vue index 8ef7b34bc..54f99f11e 100644 --- a/src/modules/18_command/components/DialogCreateCommandORG.vue +++ b/src/modules/18_command/components/DialogCreateCommandORG.vue @@ -633,18 +633,6 @@ watch(modal, async () => { - diff --git a/src/modules/18_command/components/Main/TableMain.vue b/src/modules/18_command/components/Main/TableMain.vue index 53124e0eb..db61c7a70 100644 --- a/src/modules/18_command/components/Main/TableMain.vue +++ b/src/modules/18_command/components/Main/TableMain.vue @@ -6,7 +6,6 @@ import { useRouter } from "vue-router"; import { checkPermission } from "@/utils/permissions"; import { useCounterMixin } from "@/stores/mixin"; import { useCommandListStore } from "@/modules/18_command/store/ListStore"; -import { updateCurrentPage } from "@/utils/function"; import http from "@/plugins/http"; import config from "@/app.config"; @@ -27,11 +26,11 @@ const { dialogConfirm, } = useCounterMixin(); -const page = defineModel("page", { required: true }); -const pageSize = defineModel("pageSize", { required: true }); - +const pagination = defineModel("pagination", { required: true }); const props = defineProps({ fetchList: { type: Function, required: true }, + onRequest: { type: Function, required: true }, + checkAndUpdatePage: { type: Function, required: true }, }); const modalCopy = ref(false); @@ -82,11 +81,7 @@ function onReCommand(id: string) { await http .put(config.API.commandAction(id, "resume")) .then(async () => { - page.value = await updateCurrentPage( - page.value, - store.maxPage, - store.rows.length - ); + await props.checkAndUpdatePage(store.rows.length); await fetchListCommand(); success($q, "ดึงไปทำคำสั่งใหม่สำเร็จ"); }) @@ -109,11 +104,7 @@ function onDeleteCommand(id: string) { await http .delete(config.API.command + `/${id}`) .then(async () => { - page.value = await updateCurrentPage( - page.value, - store.maxPage, - store.rows.length - ); + await props.checkAndUpdatePage(store.rows.length); await fetchListCommand(); success($q, "ลบรายการสำเร็จ"); }) @@ -129,27 +120,13 @@ function onDeleteCommand(id: string) { ); } -/** - * function updatePagination - * @param newPagination ข้อมูล Pagination ใหม่ - */ -function updatePagination(newPagination: Pagination) { - page.value = 1; - pageSize.value = newPagination.rowsPerPage; -} - -watch(pageSize, () => { - isCheckPageSize.value = true; - fetchListCommand(); -}); - onMounted(() => { !isCheckPageSize.value && fetchListCommand(); });