From e69db49a3fe29bbeadb0c274d185ddb52a37a1b4 Mon Sep 17 00:00:00 2001 From: "DESKTOP-1R2VSQH\\Lenovo ThinkPad E490" Date: Thu, 1 Feb 2024 16:01:35 +0700 Subject: [PATCH] =?UTF-8?q?API=20=E0=B9=81=E0=B8=81=E0=B9=89=E0=B9=84?= =?UTF-8?q?=E0=B8=82=E0=B8=AD=E0=B8=B1=E0=B8=95=E0=B8=A3=E0=B8=B2=E0=B8=81?= =?UTF-8?q?=E0=B8=B3=E0=B8=A5=E0=B8=B1=E0=B8=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/02_organizational/api.organization.ts | 1 + .../components/DialogFormPosition.vue | 63 ++++++++++++----- .../components/listView.vue | 1 + .../components/tableTree.vue | 67 ++++++++++++++++--- .../components/Detail/step/step5.vue | 22 +++--- 5 files changed, 118 insertions(+), 36 deletions(-) diff --git a/src/api/02_organizational/api.organization.ts b/src/api/02_organizational/api.organization.ts index db44353f9..ce61ef8fc 100644 --- a/src/api/02_organizational/api.organization.ts +++ b/src/api/02_organizational/api.organization.ts @@ -22,6 +22,7 @@ export default { orgPosType: `${orgPos}/type`, orgPosLevel: `${orgPos}/level`, orgPosMaster: `${orgPos}/master`, + orgPosMasterById: (id: string) => `${orgPos}/master/${id}`, orgPosMasterList: `${orgPos}/master/list`, orgPosSort: `${orgPos}/sort`, organizationShortName: `${organization}/sort`, diff --git a/src/modules/02_organizationalNew/components/DialogFormPosition.vue b/src/modules/02_organizationalNew/components/DialogFormPosition.vue index 23e390591..08e0091fc 100644 --- a/src/modules/02_organizationalNew/components/DialogFormPosition.vue +++ b/src/modules/02_organizationalNew/components/DialogFormPosition.vue @@ -19,6 +19,7 @@ import type { OptionExecutive, DataPosition, } from "@/modules/02_organizationalNew/interface/response/organizational"; +import type { FilterMaster } from "@/modules/02_organizationalNew/interface/request/organizational"; import http from "@/plugins/http"; import config from "@/app.config"; @@ -28,8 +29,11 @@ const props = defineProps({ orgLevel: Number, treeId: String, actionType: String, + rowId: String, + fetchDataTable: Function, }); +const reqMaster = defineModel("reqMaster", { required: true }); const isReadonly = ref(false); // อ่านได้อย่างเดียว const isDisValidate = ref(false); @@ -216,7 +220,11 @@ async function fetchPosition(id: string) { await http .get(config.API.orgPosPositionById(id)) .then((res) => { - console.log(res); + const data = res.data.result; + formData.prefixNo = data.posMasterNoPrefix; + formData.positionNo = data.posMasterNo; + formData.suffixNo = data.posMasterNoSuffix; + rows.value = data.positions; }) .catch((err) => { messageError($q, err); @@ -346,18 +354,42 @@ function onSubmit() { positions: positionsData, }; showLoader(); - await http - .post(config.API.orgPosMaster, body) - .then((res) => { - success($q, "เพิ่มข้อมูลสำเร็จ"); - }) - .catch((err) => { - messageError($q, err); - }) - .finally(() => { - props.close?.(); - hideLoader(); - }); + props.actionType === "ADD" + ? await http + .post(config.API.orgPosMaster, body) + .then(() => { + success($q, "เพิ่มข้อมูลสำเร็จ"); + props.fetchDataTable?.( + reqMaster.value.id, + reqMaster.value.type, + false + ); + }) + .catch((err) => { + messageError($q, err); + }) + .finally(() => { + props.close?.(); + hideLoader(); + }) + : props.rowId && + (await http + .put(config.API.orgPosMasterById(props.rowId), body) + .then(() => { + success($q, "แก้ไขข้อมูลสำเร็จ"); + props.fetchDataTable?.( + reqMaster.value.id, + reqMaster.value.type, + false + ); + }) + .catch((err) => { + messageError($q, err); + }) + .finally(() => { + props.close?.(); + hideLoader(); + })); }); } /** ฟังชั่น บันทึก */ @@ -411,7 +443,6 @@ async function searchInput() { `?keyword=${search.value}&type=${type.value}` ) .then((res) => { - console.log(res); rowsPositionSelect.value = res.data.result; }) .catch((err) => { @@ -462,7 +493,7 @@ watch( rows.value = []; clearFormPositionSelect(); } else { - // props.treeId && fetchPosition(props.treeId); + props.rowId && fetchPosition(props.rowId); } } } @@ -487,7 +518,7 @@ function deletePos(id: string) { showLoader(); http .delete(config.API.orgPosPositionById(id)) - .then((res) => { + .then(() => { success($q, "ลบข้อมูลสำเร็จ"); }) .catch((err) => { diff --git a/src/modules/02_organizationalNew/components/listView.vue b/src/modules/02_organizationalNew/components/listView.vue index 0b6cedcde..5ebb791e0 100644 --- a/src/modules/02_organizationalNew/components/listView.vue +++ b/src/modules/02_organizationalNew/components/listView.vue @@ -203,6 +203,7 @@ watch( v-model:reqMaster="reqMaster" v-model:totalPage="totalPage" v-model:posMaster="posMaster" + :fetchDataTable="fetchDataTable" :filterKeyword="filterKeyword" /> diff --git a/src/modules/02_organizationalNew/components/tableTree.vue b/src/modules/02_organizationalNew/components/tableTree.vue index 4302ddaa1..a59dc0125 100644 --- a/src/modules/02_organizationalNew/components/tableTree.vue +++ b/src/modules/02_organizationalNew/components/tableTree.vue @@ -1,5 +1,8 @@