diff --git a/src/api/02_organizational/api.organization.ts b/src/api/02_organizational/api.organization.ts index 0123c0604..520ca9db7 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 @@