diff --git a/src/modules/18_command/components/DialogPreviewCommand.vue b/src/modules/18_command/components/DialogPreviewCommand.vue index 66c2567aa..68aa9a5d9 100644 --- a/src/modules/18_command/components/DialogPreviewCommand.vue +++ b/src/modules/18_command/components/DialogPreviewCommand.vue @@ -13,10 +13,7 @@ import genReportXLSX from "@/plugins/genreportxlsx"; import DialogHeader from "@/components/DialogHeader.vue"; import type { PDFDocumentLoadingTask } from "pdfjs-dist/types/src/display/api"; -import type { - DataFileOrder, - FormDataDetail, -} from "@/modules/18_command/interface/index/Main"; +import type { DataFile } from "@/modules/18_command/interface/index/Main"; const $q = useQuasar(); const { showLoader, hideLoader, messageError } = useCounterMixin(); @@ -34,9 +31,9 @@ const pdfSrc = ref(); // ตัวแปร const dialog = ref(false); // เปิด dialog const isLoadView = ref(false); -const isAttachment = ref(false); -const dataCover = ref(); //ข้อมูลไฟล์คำสั่ง -const dataAttachment = ref(); //ข้อมูลไฟล์แบนท้าย +const isUploadAttachment = ref(false); +const dataCover = ref(); //ข้อมูลไฟล์คำสั่ง +const dataAttachment = ref(); //ข้อมูลไฟล์แบนท้าย /** ปิด popup */ function closeDialog() { @@ -69,8 +66,8 @@ async function checkAttachment() { .get(config.API.commandRegister(commandId.value)) .then(async (res) => { const data = res.data.result; - isAttachment.value = data.isAttachment; - if (isAttachment.value) { + isUploadAttachment.value = data.isUploadAttachment; + if (isUploadAttachment.value) { promises.value.push(fetchDataCommand("attachment")); } }); @@ -82,19 +79,22 @@ async function checkAttachment() { */ async function downloadCover(type: string) { if (tab.value === "main") { - genReport( - dataCover.value, - `คำสั่ง ${issue.value}`, - type, - "?folder=command" - ); + window.open(dataCover.value?.downloadUrl, "_blank"); + + // genReport( + // dataCover.value, + // `คำสั่ง ${issue.value}`, + // type, + // "?folder=command" + // ); } else { - genReportXLSX( - dataAttachment.value, - `เอกสารแนบท้าย ${issue.value}`, - type, - "?folder=command" - ); + window.open(dataAttachment.value?.downloadUrl, "_blank"); + // genReportXLSX( + // dataAttachment.value, + // `เอกสารแนบท้าย ${issue.value}`, + // type, + // "?folder=command" + // ); } } @@ -103,30 +103,53 @@ async function downloadCover(type: string) { * @param type ประเภท cover เป็นคำสั่ง attachment เป็น แบนท้าย */ async function fetchDataCommand(type: string) { + let newType = type === "cover" ? "คำสั่ง" : "แนบท้าย"; await http - .get(config.API.commandRegisterByType(commandId.value, type)) + .get( + config.API.fileByFile("ระบบออกคำสั่ง", newType, commandId.value, newType) + ) .then(async (res) => { - const dataMain = await res.data.result; + const data = res.data; + console.log(res); + if (type === "cover") { - dataCover.value = dataMain; - issue.value = await res.data.result.data.commandTitle; + dataCover.value = data; await fetchPDF(dataCover.value); } else { - dataAttachment.value = dataMain; + dataAttachment.value = data; } + }) + .catch((e) => { + messageError($q, e); + }) + .finally(() => { + hideLoader(); }); + // await http + // .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; + // } + // }); } /** ฟังชั่นกำหนดค่าของ PDF*/ async function fetchPDF(data: any, type: string = "docx?folder=command") { isLoadView.value = false; - await axios - .post(config.API.reportTemplate + `/${type}`, data, { - headers: { - accept: "application/pdf", - "content-Type": "application/json", - }, + axios + .get(data.downloadUrl, { + method: "GET", responseType: "blob", + headers: { + "Content-Type": "application/json", + Accept: type, // ถ้ามีการระบุเมื่ออัปโหลด + }, }) .then(async (res) => { const blob = new Blob([res.data]); @@ -138,10 +161,33 @@ async function fetchPDF(data: any, type: string = "docx?folder=command") { isLoadView.value = true; }, 1500); }) - .catch(async (e) => { - messageError($q, e); + .catch((err) => { + messageError($q, err); isLoadView.value = true; }); + + // await axios + // .post(config.API.reportTemplate + `/${type}`, data, { + // headers: { + // accept: "application/pdf", + // "content-Type": "application/json", + // }, + // responseType: "blob", + // }) + // .then(async (res) => { + // const blob = new Blob([res.data]); + // const objectUrl = URL.createObjectURL(blob); + // const pdfData = usePDF(`${objectUrl}`); + // setTimeout(() => { + // pdfSrc.value = pdfData.pdf.value; + // numOfPages.value = pdfData.pages.value; + // isLoadView.value = true; + // }, 1500); + // }) + // .catch(async (e) => { + // messageError($q, e); + // isLoadView.value = true; + // }); } watch( @@ -191,7 +237,7 @@ watch(
diff --git a/src/modules/18_command/components/Step/0_Main.vue b/src/modules/18_command/components/Step/0_Main.vue index 0129ef8c7..c54c34785 100644 --- a/src/modules/18_command/components/Step/0_Main.vue +++ b/src/modules/18_command/components/Step/0_Main.vue @@ -27,6 +27,7 @@ const isSignature = ref(null); const isDraft = ref(false); //ทำแบบร่าง const isSign = ref(false); //การลงนาม const isAttachment = ref(false); //เอกสารแนบท้าย +const isUploadAttachment = ref(false); /** ฟังก์ชันเรียกข้อมูลสถานะคำสั่ง*/ async function fetchData() { @@ -47,7 +48,8 @@ async function fetchData() { isDraft.value = data.isDraft; isSign.value = data.isSign; isAttachment.value = data.isAttachment; - store.isSalary = data.isSalary + isUploadAttachment.value = data.isUploadAttachment; + store.isSalary = data.isSalary; }) .catch((err) => { messageError($q, err); @@ -211,7 +213,7 @@ onMounted(async () => { v-model:step="step" v-model:is-draft="isDraft" v-model:is-authority="isSign" - v-model:is-attachment="isAttachment" + v-model:is-attachment="isUploadAttachment" :fetch-data="fetchData" />
@@ -224,7 +226,7 @@ onMounted(async () => { diff --git a/src/modules/18_command/components/Step/View0_Live.vue b/src/modules/18_command/components/Step/View0_Live.vue index 93bf0933b..a34ad1419 100644 --- a/src/modules/18_command/components/Step/View0_Live.vue +++ b/src/modules/18_command/components/Step/View0_Live.vue @@ -392,14 +392,7 @@ onMounted(async () => { -
+