From 3eb1a41bdb91dbaa1db7b62afba330aeaaf217d9 Mon Sep 17 00:00:00 2001 From: setthawutttty Date: Wed, 31 Jan 2024 16:10:07 +0700 Subject: [PATCH] =?UTF-8?q?pop=20up=20=E0=B8=88=E0=B8=B1=E0=B8=94=E0=B8=A5?= =?UTF-8?q?=E0=B8=B3=E0=B8=94=E0=B8=B1=E0=B8=9A=E0=B8=81=E0=B8=B2=E0=B8=A3?= =?UTF-8?q?=E0=B9=81=E0=B8=AA=E0=B8=94=E0=B8=87=E0=B8=9C=E0=B8=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/02_organizational/api.organization.ts | 1 + .../components/DialogSortAgency.vue | 52 ++++++++------- .../components/mainTree.vue | 63 ++++++++----------- 3 files changed, 51 insertions(+), 65 deletions(-) diff --git a/src/api/02_organizational/api.organization.ts b/src/api/02_organizational/api.organization.ts index 25ee73b01..f9a7faf4b 100644 --- a/src/api/02_organizational/api.organization.ts +++ b/src/api/02_organizational/api.organization.ts @@ -12,4 +12,5 @@ export default { orgSetDateTime:(id:string) => `${organization}/set/publish/${id}`, organizationHistoryNew: `${organization}/history`, + organizationShortName: `${organization}/sort`, }; diff --git a/src/modules/02_organizationalNew/components/DialogSortAgency.vue b/src/modules/02_organizationalNew/components/DialogSortAgency.vue index 3abe050da..4d21409e8 100644 --- a/src/modules/02_organizationalNew/components/DialogSortAgency.vue +++ b/src/modules/02_organizationalNew/components/DialogSortAgency.vue @@ -24,7 +24,6 @@ const { dialogConfirm, showLoader, success, hideLoader, messageError } = const modal = defineModel("sortAgency", { required: true }); const modalSort = defineModel>("data", { required: true }); -const modalType = defineModel("type", { required: true }); const rows = ref([]); const columns = ref([ { @@ -49,39 +48,38 @@ function save() { dialogConfirm($q, () => { const data = rows.value; const dataId = data.map((item: any) => item.orgTreeId); - console.log(dataId); + http + .put(config.API.organizationShortName, { + id: data[0].orgLevel === 0 ? data[0].orgRevisionId : data[0].orgRootId, + type: data[0].orgLevel, + sortId: dataId, + }) + .then((res) => { + modal.value = false; + success($q, "บันทึกข้อมูลสำเร็จ"); + }) + .catch((e) => { + messageError($q, e); + }) + .finally(() => {}); }); } watch( () => modal.value, () => { if (modal.value == true) { + rows.value = []; const dataStandant = modalSort.value; - if (modalType.value === 0) { - const mappedData = dataStandant.map((item: any) => ({ - orgLevel: item.orgLevel, - name: `${item.orgTreeName} (${item.orgTreeShortName})`, - orgRevisionId: item.orgRevisionId, - orgTreeId: item.orgTreeId, - orgTreeName: item.orgTreeName, - orgTreeShortName: item.orgTreeShortName, - })); - rows.value = mappedData; - console.log("row", rows.value); - } else if (modalType.value === 1) { - const mappedData = dataStandant.map((item: any) => ({ - name: `${item.orgTreeName} (${item.orgTreeShortName})`, - orgRootId: item.orgRootId, - orgTreeId: item.orgTreeId, - orgLevel: item.orgLevel, - orgTreeName: item.orgTreeName, - orgTreeShortName: item.orgTreeShortName, - orgRevisionId: item.orgRevisionId, - })); - rows.value = mappedData; - - console.log("row", dataStandant); - } + const mappedData = dataStandant.map((item: any) => ({ + name: `${item.orgTreeName} (${item.orgTreeShortName})`, + orgRootId: item.orgRootId, + orgTreeId: item.orgTreeId, + orgLevel: item.orgLevel, + orgTreeName: item.orgTreeName, + orgTreeShortName: item.orgTreeShortName, + orgRevisionId: item.orgRevisionId, + })); + rows.value = mappedData; } } ); diff --git a/src/modules/02_organizationalNew/components/mainTree.vue b/src/modules/02_organizationalNew/components/mainTree.vue index cb0dab00f..6f3f388ae 100644 --- a/src/modules/02_organizationalNew/components/mainTree.vue +++ b/src/modules/02_organizationalNew/components/mainTree.vue @@ -212,16 +212,25 @@ async function onClickDel(type: number, id: string) { messageError($q, err); }) .finally(async () => { - props.fetchDataTree?.(); - hideLoader(); + props.fetchDataTree?.(); + hideLoader(); }); }); } -function onClickSort(type: number, id: string) { +async function onClickSort(id: string) { modalSortAgency.value = true; - level.value = type; - if (type === 0) { + if (id) { + breakLoop.value = false; + + const orgId = id; + + for (let index = 0; index < nodes.value.length; index++) { + const data = nodes.value[index]; + searchAndReplace(data, orgId); + if (breakLoop.value) break; + } + } else { const dataList = nodes.value; const dataMap = dataList.map((item: any) => ({ orgTreeId: item.orgTreeId, @@ -232,38 +241,17 @@ function onClickSort(type: number, id: string) { })); dataSort.value = dataMap; - } else if (type === 1) { - const dataList = nodes.value; - const dataMap = dataList.map((item: any) => ({ - orgTreeId: item.orgTreeId, - orgRevisionId: item.orgRevisionId, - children: item.children, - })); - const dataChild = dataMap - .filter((item: any) => item.orgTreeId === id) - .reduce((acc: any, item: any) => { - return acc.concat( - item.children.map((child: any) => ({ - orgRootId: child.orgRootId, - orgTreeId: child.orgTreeId, - orgLevel: child.orgLevel, - orgTreeName: child.orgTreeName, - orgTreeShortName: child.orgTreeShortName, - orgRevisionId: child.orgRevisionId, - })) - ); - }, []); - dataSort.value = dataChild; - } else if (type === 2) { - - const dataList = nodes.value; - const dataMap = dataList.map((item: any) => ({ - orgTreeId: item.orgTreeId, - children: item.children, - })) - - console.log(dataMap) + } + function searchAndReplace(data: any, id: string) { + if (data.orgTreeId === id) { + dataSort.value = data.children; + breakLoop.value = true; + } else if (data.children) { + for (const child of data.children) { + searchAndReplace(child, id); + } + } } } watch( @@ -381,7 +369,7 @@ onMounted(async () => {}); : item.type === 'DEL' ? onClickDel(prop.node.orgLevel, prop.node.orgTreeId) : item.type === 'SORT' - ? onClickSort(prop.node.orgLevel, prop.node.orgRootId) + ? onClickSort(prop.node.orgRootId) : null " > @@ -509,7 +497,6 @@ onMounted(async () => {});