From 32d8a11956e23333398a1f6c8f8619f6c23b34d2 Mon Sep 17 00:00:00 2001 From: waruneeauy Date: Fri, 13 Sep 2024 15:11:15 +0700 Subject: [PATCH] updated structure check isOfficer --- src/api/02_organizational/api.organization.ts | 2 + .../components/DialogFormAgency.vue | 39 ++++++++++++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/api/02_organizational/api.organization.ts b/src/api/02_organizational/api.organization.ts index 76c8352d6..6b3848fcf 100644 --- a/src/api/02_organizational/api.organization.ts +++ b/src/api/02_organizational/api.organization.ts @@ -125,4 +125,6 @@ export default { */ orgPermissions: `${organization}/permission/menu`, orgPermissionsSys: `${organization}/permission`, + + checkIsOfficer: (id: string) => `${organization}/check/child1/${id}`, }; diff --git a/src/modules/02_organization/components/DialogFormAgency.vue b/src/modules/02_organization/components/DialogFormAgency.vue index ab84029df..8c58f2c49 100644 --- a/src/modules/02_organization/components/DialogFormAgency.vue +++ b/src/modules/02_organization/components/DialogFormAgency.vue @@ -268,6 +268,22 @@ const tittleName = computed(() => { return name; }); +const checkIsOfficer = ref(false); // เช็คว่าในโครงสร้างแบบร่างมีการเลือก สกจ. ไหม true = มี false = ไม่มี +/** ฟังก์ชั่นเช็คว่าในโครงสร้างแบบร่างมีการเลือก สกจ. หรือยัง */ +async function checkOfficer() { + await http + .get(config.API.checkIsOfficer(store.draftId ?? "")) + .then((res) => { + checkIsOfficer.value = res.data.result; + }) + .catch((err) => { + messageError($q, err); + }) + .finally(() => { + hideLoader(); + }); +} + /** * callback function ทำงานเมื่อ props.modal เป็น true */ @@ -275,7 +291,9 @@ watch( () => props.modal, () => { if (props.modal === true) { + // ถ้าเป็นการเพิ่มข้อมูล if (actionType.value === "ADD") { + props.dataNode?.orgLevel === 0 && checkOfficer(); if (props.dataNode) { formData.orgCode = props?.dataNode?.orgLevel !== 0 @@ -296,7 +314,10 @@ watch( } formData.orgLevel == "DEPARTMENT" ? selectOrgLevele("DEPARTMENT") : ""; - } else { + } + // ถ้าเป็นการแก้ไขข้อมูล + else { + props.dataNode?.orgLevel === 1 && checkOfficer(); if (props.dataNode) { formData.orgName = props.dataNode.orgTreeName; formData.orgShortName = props.dataNode.orgTreeShortName; @@ -318,6 +339,22 @@ watch( } } ); + +/** ถ้ามีการเลือก สกจ. และเคยมีเลือกไปแล้วระบบจะถามและให้ยืนยันการเลือกสกจ. */ +watch( + () => formData.isOfficer, + (newData, oldData) => { + if (newData === true && checkIsOfficer.value === true) { + dialogConfirm( + $q, + () => (formData.isOfficer = true), + "ยืนยันการแก้ไข", + "คุณต้องการแก้ไข สกจ. เป็นส่วนราชการนี้ใช่หรือไม่?", + () => (formData.isOfficer = false) + ); + } + } +);