From 6db8040e909b8878773844180827b39c6f189e26 Mon Sep 17 00:00:00 2001 From: "DESKTOP-1R2VSQH\\Lenovo ThinkPad E490" Date: Tue, 15 Jul 2025 11:38:32 +0700 Subject: [PATCH] =?UTF-8?q?fix=20CurrentPage=20=3D=3D>=20=E0=B8=A3?= =?UTF-8?q?=E0=B8=B2=E0=B8=A2=E0=B8=81=E0=B8=B2=E0=B8=A3=E0=B8=95=E0=B8=B1?= =?UTF-8?q?=E0=B8=A7=E0=B8=8A=E0=B8=B5=E0=B9=89=E0=B8=A7=E0=B8=B1=E0=B8=94?= =?UTF-8?q?=E0=B8=95=E0=B8=B2=E0=B8=A1=E0=B9=81=E0=B8=9C=E0=B8=99=E0=B8=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../indicatorByPlan/IndicatorByPlan.vue | 2 +- .../01_masterdata/interface/index/Main.ts | 20 +++-- .../01_masterdata/views/indicatorByPlan.vue | 76 +++++++++++-------- 3 files changed, 60 insertions(+), 38 deletions(-) diff --git a/src/modules/01_masterdata/components/Indicators/indicatorByPlan/IndicatorByPlan.vue b/src/modules/01_masterdata/components/Indicators/indicatorByPlan/IndicatorByPlan.vue index 939b48704..a4e0000d0 100644 --- a/src/modules/01_masterdata/components/Indicators/indicatorByPlan/IndicatorByPlan.vue +++ b/src/modules/01_masterdata/components/Indicators/indicatorByPlan/IndicatorByPlan.vue @@ -216,7 +216,7 @@ function onSubmit() { const res = await http[method](url, body); success($q, "บันทึกข้อมูลสำเร็จ"); editStatus.value - ? fetchDataById(id.value) + ? await fetchDataById(id.value) : router.push(`/masterdata/indicator-plan/${res.data.result}`); } catch (e) { messageError($q, e); diff --git a/src/modules/01_masterdata/interface/index/Main.ts b/src/modules/01_masterdata/interface/index/Main.ts index 46f16b7f7..301ece0ac 100644 --- a/src/modules/01_masterdata/interface/index/Main.ts +++ b/src/modules/01_masterdata/interface/index/Main.ts @@ -37,6 +37,7 @@ interface IndicatorType { } interface OrgTreeNode { + orgTreeDnaId: string; orgTreeId: string; orgRootId: string; orgLevel: number; @@ -107,7 +108,7 @@ interface CompetencySumary { value: string; label: string; color: string; - total?:string + total?: string; } interface Position { @@ -130,10 +131,18 @@ interface ListLinkGroup { capacitys: Capacity[]; } -interface SizeType{ - width:number - height:number +interface SizeType { + width: number; + height: number; } + +interface FormDataNodeData { + round: string; + nodeId: string | null; + node: number | null; + keyword: string; +} + export type { Pagination, DataOption, @@ -149,5 +158,6 @@ export type { ListLinkGroup, Position, CompetencySumary, - SizeType + SizeType, + FormDataNodeData }; diff --git a/src/modules/01_masterdata/views/indicatorByPlan.vue b/src/modules/01_masterdata/views/indicatorByPlan.vue index d994a930c..1c6264f48 100644 --- a/src/modules/01_masterdata/views/indicatorByPlan.vue +++ b/src/modules/01_masterdata/views/indicatorByPlan.vue @@ -8,12 +8,15 @@ import config from "@/app.config"; import { useCounterMixin } from "@/stores/mixin"; import { checkPermission } from "@/utils/permissions"; import { useStructureTree } from "@/stores/structureTree"; +import { updateCurrentPage } from "@/utils/function"; import type { DataOption, IndicatorType, OrgTreeNode, DataHistory, + FormDataNodeData, + NewPagination, } from "@/modules/01_masterdata/interface/index/Main"; import DialogHistory from "@/modules/01_masterdata/components/Indicators/DialogHistory.vue"; @@ -32,12 +35,6 @@ const isAll = ref(false); const total = ref(0); const totalList = ref(1); -const pagination = ref({ - sortBy: "createdAt", - descending: true, - page: 1, - rowsPerPage: 10, -}); /** หัวตาราง */ const rows = ref([]); @@ -61,10 +58,17 @@ const columns = ref([ style: "font-size: 14px", }, ]); -const node = ref([]); -const expanded = ref([]); -const filterMain = ref(""); const visibleColumns = ref(["including", "includingName"]); +const pagination = ref({ + sortBy: "createdAt", + descending: true, + page: 1, + rowsPerPage: 10, +}); + +const node = ref([]); +const expanded = ref([]); +const filterMain = ref(""); const roundOp = ref([ { id: "", name: "ทั้งหมด" }, @@ -73,18 +77,18 @@ const roundOp = ref([ ]); const year = ref(new Date().getFullYear()); -const nodeData = reactive({ +const nodeData = reactive({ round: "", nodeId: null, node: null, keyword: "", }); -/** ดึงข้อมูล */ -function fetchList() { +/** ฟังชั่นดึงข้อมูลรายการตัวชี้วัดตามแผน */ +async function fetchList() { if (nodeData.nodeId) { showLoader(); - http + await http .post(config.API.kpiPlan + `/search-edit`, { isAll: isAll.value, keyword: nodeData.keyword.trim(), @@ -123,6 +127,10 @@ function onClickAddOrView(status: boolean = false, id: string = "") { : router.push("/masterdata/indicator-plan/add"); } +/** + * ฟังชั่นดูรายละเอียดรายการตัวชี้วัด + * @param id id รายการตัวชี้วัดที่ต้องการดู + */ function onClickView(id: string = "") { router.push(`/masterdata/indicator-plan/view/${id}`); } @@ -133,24 +141,33 @@ async function fetchTree() { } /** เรียกข้อมูลตาม row โครงสร้าง*/ -function updateSelectedTreeMain(data: any) { +function updateSelectedTreeMain(data: OrgTreeNode) { if (nodeData.node === data.orgLevel && nodeData.nodeId === data.orgTreeId) { nodeData.node = null; nodeData.nodeId = null; } else { - nodeData.node = data.orgLevel; - nodeData.nodeId = data.orgTreeDnaId; + nodeData.node = data.orgLevel ?? null; + nodeData.nodeId = data.orgTreeDnaId ?? null; } getSearch(); } -/** delete */ +/** + * ฟังชั่นลบข้อมูล + * @param idData id ของข้อมูลที่ต้องการลบ + */ async function deleteData(idData: string) { - dialogRemove($q, () => - http + dialogRemove($q, async () => { + showLoader(); + await http .delete(config.API.kpiPlanById(idData)) - .then(() => { - fetchList(); + .then(async () => { + pagination.value.page = await updateCurrentPage( + pagination.value.page, + totalList.value, + rows.value.length + ); + await fetchList(); success($q, "ลบข้อมูลสำเร็จ"); }) .catch((err) => { @@ -158,19 +175,13 @@ async function deleteData(idData: string) { }) .finally(() => { hideLoader(); - }) - ); -} - -/** clear input filter */ -function clearFilter() { - nodeData.keyword = ""; - getSearch(); + }); + }); } /** - * เปิด dialog history - * @param id + * ฟังชั่นเปิด dialog history + * @param id id รายการตัวชี้วัดที่ต้องการดูประวัติ */ function onClickHistory(id: string) { showLoader(); @@ -189,7 +200,7 @@ function onClickHistory(id: string) { }); } -function updatePagination(newPagination: any) { +function updatePagination(newPagination: NewPagination) { pagination.value.page = 1; pagination.value.rowsPerPage = newPagination.rowsPerPage; } @@ -230,6 +241,7 @@ onMounted(() => { +