From 2ef5a7b8459c079fdd782fd1beda67391977efbe Mon Sep 17 00:00:00 2001 From: Thanit Konmek Date: Sat, 26 Aug 2023 13:17:07 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B8=AA=E0=B9=80=E0=B8=95=E0=B8=9B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/reports/api.report.ts | 5 + .../10_order/components/step/step04.vue | 538 ++++++++++++++---- 2 files changed, 443 insertions(+), 100 deletions(-) diff --git a/src/api/reports/api.report.ts b/src/api/reports/api.report.ts index b7d868f5b..41314672f 100644 --- a/src/api/reports/api.report.ts +++ b/src/api/reports/api.report.ts @@ -12,4 +12,9 @@ export default { `${reportOrder}/attachment/${fileType}/${id}`, reportRetireList: (fileType: string, id: string) => `${reportRetire}/${fileType}/${id}`, + + fileCover: (format: string, fileType: string, id: string) => + `${reportOrder}/${format}/cover/${fileType}/${id}`, + fileAttachment: (format: string, fileType: string, id: string) => + `${reportOrder}/${format}/attachment/${fileType}/${id}`, }; diff --git a/src/modules/10_order/components/step/step04.vue b/src/modules/10_order/components/step/step04.vue index 6284cf6dd..47be1245d 100644 --- a/src/modules/10_order/components/step/step04.vue +++ b/src/modules/10_order/components/step/step04.vue @@ -10,7 +10,14 @@ import http from "@/plugins/http"; import config from "@/app.config"; const mixin = useCounterMixin(); -const { date2Thai, messageError, showLoader, hideLoader, dialogConfirm, success } = mixin; +const { + date2Thai, + messageError, + showLoader, + hideLoader, + dialogConfirm, + success, +} = mixin; const route = useRoute(); const $q = useQuasar(); @@ -21,6 +28,7 @@ const splitterModel = ref(70); const tab = ref("main"); const order = ref(""); +const code = ref(""); const years = ref(new Date().getDate()); const date = ref(new Date()); const fileOrder = ref(null); @@ -39,21 +47,69 @@ const statusOrder = ref(); const orderId = ref(orderId_params.toString()); onMounted(async () => { if (orderId.value) { - fetchReportCover('pdf', orderId.value); - fetchReportCover('docx', orderId.value); - fetchReportAttachment('pdf', orderId.value); - fetchReportAttachment('xlsx', orderId.value); + fetchReportCover("pdf", orderId.value); + fetchReportCover("docx", orderId.value); + fetchReportAttachment("pdf", orderId.value); + fetchReportAttachment("xlsx", orderId.value); fetchAttachment(orderId.value); fecthstatusOrder(orderId.value); + getType(); } }); +const getType = async () => { + showLoader(); + await http + .get(config.API.detailOrder(orderId.value)) + .then(async (res) => { + const data = res.data.result; + const orderTypeCode = data.orderTypeCode; + code.value = orderTypeCode ?? ""; + }) + .catch((e) => { + messageError($q, e); + }) + .finally(() => { + hideLoader(); + }); +}; + +const downloadCover = async (type: string) => { + showLoader(); + await http + .get(config.API.fileCover(code.value, type, orderId.value)) + .then(async (res) => { + downloadFile(res.data.result, "คำสั่ง"); + }) + .catch((e) => { + messageError($q, e); + }) + .finally(() => { + hideLoader(); + }); +}; + +const downloadAttachment = async (type: string) => { + showLoader(); + await http + .get(config.API.fileCover(code.value, type, orderId.value)) + .then(async (res) => { + downloadFile(res.data.result, "เอกสารแนบท้าย"); + }) + .catch((e) => { + messageError($q, e); + }) + .finally(() => { + hideLoader(); + }); +}; + const fetchReportCover = async (type: string, orderId: string) => { showLoader(); await http .get(config.API.reportOrderCover(type, orderId)) .then(async (res) => { - if (type == 'pdf') { + if (type == "pdf") { orderCoverPdf.value = res.data.result; viewPDF(orderCoverPdf.value); } else { @@ -73,7 +129,7 @@ const fetchReportAttachment = async (type: string, orderId: string) => { await http .get(config.API.reportOrderAttachment(type, orderId)) .then(async (res) => { - if (type == 'pdf') { + if (type == "pdf") { orderAttachmentPdf.value = res.data.result; } else { orderAttachmentXlsx.value = res.data.result; @@ -183,21 +239,27 @@ const onchangePage = (val: any) => { } }; +const downloadFile = (response: any, filename: string) => { + const link = document.createElement("a"); + var fileName = filename; + link.href = window.URL.createObjectURL(new Blob([response.data])); + link.setAttribute("download", fileName); + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); +}; + const save = () => { if (myForm.value !== null) { myForm.value!.validate().then((success: Boolean) => { if (success) { - dialogConfirm( - $q, - async () => { - await putOrderData(); - await postfileOrder(); - await postfileTailer(); - await fetchAttachment(orderId.value); - await fecthstatusOrder(orderId.value); - }, - ); - + dialogConfirm($q, async () => { + await putOrderData(); + await postfileOrder(); + await postfileTailer(); + await fetchAttachment(orderId.value); + await fecthstatusOrder(orderId.value); + }); } }); } @@ -222,15 +284,20 @@ const putOrderData = async () => { const postfileOrder = async () => { const formData = new FormData(); formData.append("File", fileOrder.value); - await http.post(config.API.attachmentOrderId(orderId.value), formData).then(() => { - // fileOrder.value = null - }); + await http + .post(config.API.attachmentOrderId(orderId.value), formData) + .then(() => { + // fileOrder.value = null + }); }; const postfileTailer = async () => { const formData = new FormData(); formData.append("File", fileTailer.value); - await http.post(config.API.attachmentFileId(orderId.value), formData).then(() => { //fileTailer.value = null - }); + await http + .post(config.API.attachmentFileId(orderId.value), formData) + .then(() => { + //fileTailer.value = null + }); }; const clickExecute = async (id: string) => { @@ -247,7 +314,7 @@ const clickExecute = async (id: string) => { }); }, "ยืนยันการออกคำสั่ง", - "ต้องการยืนยันการออกคำสั่งนี้ใช่หรือไม่?", + "ต้องการยืนยันการออกคำสั่งนี้ใช่หรือไม่?" ); }; @@ -270,32 +337,60 @@ const setTab = (val: string) => { }; const viewFileUpload = async (url: string) => { - pdfFileUploadSrc.value = undefined + pdfFileUploadSrc.value = undefined; await viewPDFUpload(url); - dialogFileUpload.value = true -} + dialogFileUpload.value = true; +};