diff --git a/src/api/18_command/api.command.ts b/src/api/18_command/api.command.ts index 8c3491460..58c7b946f 100644 --- a/src/api/18_command/api.command.ts +++ b/src/api/18_command/api.command.ts @@ -18,4 +18,7 @@ export default { `${command}/${tab}/recive/${commandReciveId}`, checkIdofficer: `${env.API_URI}/org/profile/keycloak/idofficer`, + + commandRegister:(id:string)=>`${command}/register-tab0/${id}`, + commandRegisterByType:(id:string,type:string)=>`${command}/register-tab4/${type}/${id}` }; diff --git a/src/modules/18_command/components/DialogPreviewCommand.vue b/src/modules/18_command/components/DialogPreviewCommand.vue index 55291eca3..1db0e392c 100644 --- a/src/modules/18_command/components/DialogPreviewCommand.vue +++ b/src/modules/18_command/components/DialogPreviewCommand.vue @@ -24,22 +24,8 @@ const { showLoader, hideLoader, messageError } = useCounterMixin(); const modal = defineModel("modal", { required: true }); const command = defineModel("command", { required: true }); const commandId = defineModel("commandId", { required: true }); - -let formCommandList = reactive({ - id: "", - status: "", - commandTypeName: "", - commandNo: "", - commandYear: null, - detailHeader: "", - detailBody: "", - detailFooter: "", - issue: null, - commandAffectDate: null, //วันที่ลงนาม - commandExcecuteDate: null, //วันที่คำสั่งมีผล - commandSysId: "", // ประเภท คำสั่ง - isAttachment: true, -}); +const issue = ref(null); +const promises = ref([]); const tab = ref("main"); //tab const page = ref(1); @@ -79,18 +65,14 @@ function getClass(val: boolean) { } async function checkAttachment() { - showLoader(); await http - .get(config.API.commandAction(commandId.value, "tab0")) + .get(config.API.commandRegister(commandId.value)) .then(async (res) => { const data = res.data.result; isAttachment.value = data.isAttachment; - }) - .catch((err) => { - messageError($q, err); - }) - .finally(() => { - hideLoader(); + if (isAttachment.value) { + promises.value.push(fetchDataCommand("attachment")); + } }); } @@ -102,14 +84,14 @@ async function downloadCover(type: string) { if (tab.value === "main") { genReport( dataCover.value, - `คำสั่ง ${formCommandList.issue}`, + `คำสั่ง ${issue.value}`, type, "?folder=command" ); } else { genReportXLSX( dataAttachment.value, - `เอกสารแนบท้าย ${formCommandList.issue}`, + `เอกสารแนบท้าย ${issue.value}`, type, "?folder=command" ); @@ -122,18 +104,16 @@ async function downloadCover(type: string) { */ async function fetchDataCommand(type: string) { await http - .get(config.API.commandAction(commandId.value, `tab4/${type}`)) + .get(config.API.commandRegisterByType(commandId.value, type)) .then(async (res) => { const dataMain = await res.data.result; if (type === "cover") { dataCover.value = dataMain; + issue.value = await res.data.result.data.commandTitle; await fetchPDF(dataCover.value); } else { dataAttachment.value = dataMain; } - }) - .catch((err) => { - messageError($q, err); }); } @@ -164,41 +144,21 @@ async function fetchPDF(data: any, type: string = "docx?folder=command") { }); } -/** - * ฟังก์ชันดึงข้อมูลรายละเอียดคำสั่ง - * - * กำหนดข้อมูลที่ได้รับมาให้กับตัวแปร `formData` - */ -async function fetchDataCommandList() { - showLoader(); - await http - .get(config.API.commandAction(commandId.value, "tab1")) - .then(async (res) => { - const data = await res.data.result; - formCommandList = data; - }) - .catch((err) => { - messageError($q, err); - }) - .finally(() => { - hideLoader(); - }); -} - watch( () => modal.value, async () => { if (modal.value) { - await checkAttachment(); - await fetchDataCommandList(); showLoader(); - const promises = [fetchDataCommand("cover")]; - if (isAttachment.value) { - promises.push(fetchDataCommand("attachment")); - } - await Promise.all(promises).finally(() => { - hideLoader(); - }); + promises.value = [checkAttachment(), fetchDataCommand("cover")]; + + await Promise.all(promises.value) + .catch((e) => { + messageError($q, e); + hideLoader(); + }) + .finally(() => { + hideLoader(); + }); } } ); @@ -221,7 +181,7 @@ watch(