diff --git a/src/modules/02_organization/components/DialogAddPosition.vue b/src/modules/02_organization/components/DialogAddPosition.vue index 9fa0e35da..162f71512 100644 --- a/src/modules/02_organization/components/DialogAddPosition.vue +++ b/src/modules/02_organization/components/DialogAddPosition.vue @@ -133,10 +133,9 @@ function saveSelectEdit() { }; await http .put(url, body) - .then(() => { - success($q, "เพิ่มข้อมูลสำเร็จ"); - - props.getData?.(); + .then(async () => { + await props.getData?.(); + await success($q, "เพิ่มข้อมูลสำเร็จ"); close(); }) .catch((err) => { @@ -192,10 +191,12 @@ function onSubmitSelectEdit() { await http .post(url, body) - .then(() => { - success($q, "เพิ่มข้อมูลสำเร็จ"); - - props.emitSearch?.(formPositionSelect.positionName, "positionName"); + .then(async () => { + await props.emitSearch?.( + formPositionSelect.positionName, + "positionName" + ); + await success($q, "เพิ่มข้อมูลสำเร็จ"); close(); }) .catch((err) => { @@ -241,7 +242,12 @@ function inputEdit(val: boolean) { }; } +/** + * function เลือกประเภทตำแหน่ง + * @param val id ประเภทตำแหน่ง + */ function updateSelectType(val: string) { + // หาระดับตำแหน่ง const listLevel = dataLevel.value.find((e: any) => e.id === val); levelOpsMain.value = listLevel.posLevels.map((e: OptionLevel) => ({ id: e.id, @@ -257,8 +263,7 @@ function close() { } async function fetchType() { - showLoader(); - await http + http .get(config.API.orgPosType) .then((res) => { dataLevel.value = res.data.result; @@ -270,16 +275,12 @@ async function fetchType() { }) .catch((err) => { messageError($q, err); - }) - .finally(() => { - hideLoader(); }); } /** function เรียกรายการตำแหน่งทางการบริหาร */ -async function fetchExecutive() { - showLoader(); - await http +function fetchExecutive() { + http .get(config.API.orgPosExecutive) .then((res) => { executiveOpsMain.value = res.data.result.map((e: OptionExecutive) => ({ @@ -290,9 +291,6 @@ async function fetchExecutive() { }) .catch((err) => { messageError($q, err); - }) - .finally(() => { - hideLoader(); }); } @@ -300,8 +298,9 @@ watch( () => modal.value, async () => { if (modal.value === true) { - await fetchType(); - await fetchExecutive(); + showLoader(); + await Promise.all([fetchType(), fetchExecutive()]); + hideLoader(); if (props.data) { const dataList = props.data; diff --git a/src/modules/02_organization/components/DialogFormAgency.vue b/src/modules/02_organization/components/DialogFormAgency.vue index e6142d868..611bd8b37 100644 --- a/src/modules/02_organization/components/DialogFormAgency.vue +++ b/src/modules/02_organization/components/DialogFormAgency.vue @@ -149,13 +149,14 @@ function onSubmit() { formData.responsibility != null ? formData.responsibility : "", }; + //เพิ่มข้อมูล if (actionType.value === "ADD") { await http .post(config.API.createOrgLevel(type.toLocaleLowerCase()), body) - .then(() => { - props.fetchDataTree(store.draftId); - success($q, "บันทึกข้อมูลสำเร็จ"); - closeClear(); + .then(async () => { + await props.fetchDataTree(store.draftId); + await success($q, "บันทึกข้อมูลสำเร็จ"); + await closeClear(); }) .catch((err) => { messageError($q, err); @@ -164,6 +165,7 @@ function onSubmit() { hideLoader(); }); } else { + // แก่้ไขข้อมูล props.dataNode && (await http .put( @@ -173,32 +175,35 @@ function onSubmit() { ), body ) - .then(() => { - props.fetchDataTree(store.draftId); - props.edit?.( + .then(async () => { + await props.fetchDataTree(store.draftId); + await props.edit?.( props.dataNode?.orgTreeId, type, body, props.dataNode?.orgRootCode ); - closeClear(); - props.fetchDataTable( + await props.fetchDataTable( props?.dataNode?.orgTreeId, props?.dataNode?.orgLevel, false ); - success($q, "บันทึกข้อมูลสำเร็จ"); + await success($q, "บันทึกข้อมูลสำเร็จ"); + await closeClear(); }) .catch((err) => { messageError($q, err); }) - .finally(async () => { + .finally(() => { hideLoader(); })); } }); } +/** + * function เช็ต formdata กลับไปค่าว่าง และปิด popup + */ function closeClear() { formData.orgName = ""; formData.orgShortName = ""; @@ -211,14 +216,14 @@ function closeClear() { props.close?.(); } +/** + * callback function ทำงานเมื่อมีการเปิด popup + */ watch( () => props.modal, () => { if (props.modal === true) { if (actionType.value === "ADD") { - // console.log(props.dataNode); - // console.log(level.value); - if (props.dataNode) { formData.orgCode = props?.dataNode?.orgLevel !== 0 @@ -261,6 +266,9 @@ watch( } ); +/** + * title ของ popup + */ const tittleName = computed(() => { let name = ""; if (actionType.value === "ADD") { @@ -272,6 +280,11 @@ const tittleName = computed(() => { return name; }); +/** + * function เลือกระดับของส่วนราชการ + * @param val + * @param status + */ function selectOrgLevele(val: string, status: boolean = true) { formData.orgLevelSub = status ? "" : formData.orgLevelSub; switch (val) { diff --git a/src/modules/02_organization/components/DialogFormPosition.vue b/src/modules/02_organization/components/DialogFormPosition.vue index c51991cd6..f0197b7fe 100644 --- a/src/modules/02_organization/components/DialogFormPosition.vue +++ b/src/modules/02_organization/components/DialogFormPosition.vue @@ -1,7 +1,6 @@