From defe861b552c64fe9a52daf9d48c6aa6c0eb45e0 Mon Sep 17 00:00:00 2001 From: waruneeta Date: Mon, 8 Jan 2024 12:19:14 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=E0=B8=A3=E0=B8=B2?= =?UTF-8?q?=E0=B8=A2=E0=B8=87=E0=B8=B2=E0=B8=99=E0=B8=AD=E0=B8=AD=E0=B8=81?= =?UTF-8?q?=E0=B8=84=E0=B8=B3=E0=B8=AA=E0=B8=B1=E0=B9=88=E0=B8=87=E0=B8=A7?= =?UTF-8?q?=E0=B8=B4=E0=B8=99=E0=B8=B1=E0=B8=A2=20=E0=B9=81=E0=B8=A5?= =?UTF-8?q?=E0=B8=B0=E0=B9=81=E0=B8=81=E0=B9=89=20path=20url=20report-temp?= =?UTF-8?q?late?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/index.ts | 12 +- src/api/reports/api.report.ts | 41 +++---- .../10_order/components/step/step04.vue | 107 ++++++++++++++---- src/plugins/genreport.ts | 7 +- 4 files changed, 119 insertions(+), 48 deletions(-) diff --git a/src/api/index.ts b/src/api/index.ts index 3315adba4..7359b3d8c 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -32,6 +32,8 @@ const config = ref({ // API_PROBATION_URI: "http://192.168.1.151:7776/v1", API_REPORT2_URI: "https://bma-ehr.frappet.synology.me/api/v2", LINK_EVALUATE_PUBLISH: "https://bma-ehr-publish.frappet.synology.me", + API_REPORT_TEMPLATE_URI: + "https://report-server.frappet.synology.me/api/v1/report-template", }, test: { API_URI: "http://localhost:5010/api/v1", @@ -55,6 +57,8 @@ const config = ref({ API_PROBATION_URI: `${window.location.protocol}//${window.location.host}/api/v1/probation`, API_REPORT2_URI: `${window.location.protocol}//${window.location.host}/api/v2`, LINK_EVALUATE_PUBLISH: "https://bma-ehr-publish.frappet.synology.me", + API_REPORT_TEMPLATE_URI: + "https://report-server.frappet.synology.me/api/v1/report-template", }, }); @@ -84,7 +88,12 @@ const API_PROBATION_URI = ref( config.value[env.value].API_PROBATION_URI ); const API_REPORT2_URI = ref(config.value[env.value].API_REPORT2_URI); -const LINK_EVALUATE_PUBLISH = ref(config.value[env.value].LINK_EVALUATE_PUBLISH); +const LINK_EVALUATE_PUBLISH = ref( + config.value[env.value].LINK_EVALUATE_PUBLISH +); +const API_REPORT_TEMPLATE_URI = ref( + config.value[env.value].API_REPORT_TEMPLATE_URI +); export default { env: env.value, @@ -102,4 +111,5 @@ export default { API_PROBATION_URI: API_PROBATION_URI.value, API_REPORT2_URI: API_REPORT2_URI.value, LINK_EVALUATE_PUBLISH: LINK_EVALUATE_PUBLISH.value, + API_REPORT_TEMPLATE_URI: API_REPORT_TEMPLATE_URI.value, }; diff --git a/src/api/reports/api.report.ts b/src/api/reports/api.report.ts index 9021a1739..5508f22b4 100644 --- a/src/api/reports/api.report.ts +++ b/src/api/reports/api.report.ts @@ -8,6 +8,7 @@ const reportProbation = `${env.API_REPORT2_URI}/report/probation`; const reportResign = `${env.API_REPORT2_URI}/report/resign/33`; const reportTransfer = `${env.API_REPORT2_URI}/report/transfer`; const reportDeceased = `${env.API_REPORT2_URI}/report/deceased`; +const reportTemplate = `${env.API_REPORT_TEMPLATE_URI}`; export default { reportOrderCover: (fileType: string, id: string, commandCode: string) => @@ -16,7 +17,7 @@ export default { `${reportOrder}/${commandCode}/attachment/${fileType}/${id}`, reportRetireList: (fileType: string, id: string) => `${reportRetire}/${fileType}/${id}`, - reportResignList: (fileType: string, id: string) => + reportResignList: (fileType: string, id: string) => `${reportResign}/${fileType}/${id}`, fileCover: (format: string, fileType: string, id: string) => @@ -24,23 +25,25 @@ export default { fileAttachment: (format: string, fileType: string, id: string) => `${reportOrder}/${format}/attachment/${fileType}/${id}`, + //ระบบทดลองงาน + reportAssign: (type: string, id: string) => + `${reportProbation}/13/${type}/${id}`, + reportEvaluateRecord1: (type: string, id: string) => + `${reportProbation}/14/${type}/${id}`, + // reportEvaluateRecord2:(type:string, id:string) => `${reportProbation}/15/${type}/${id}`, + reportEvaluate: (type: string, id: string) => + `${reportProbation}/16/${type}/${id}`, + reportEvaluateChairman: (type: string, id: string) => + `${reportProbation}/17/${type}/${id}`, + reportEvaluateResult: (type: string, id: string) => + `${reportProbation}/19/${type}/${id}`, + // reportSurvey:(type:string, id:string) => `${reportProbation}/19/${type}/${id}`, - //ระบบทดลองงาน - reportAssign:(type:string, id:string) => `${reportProbation}/13/${type}/${id}`, - reportEvaluateRecord1:(type:string, id:string) => `${reportProbation}/14/${type}/${id}`, - // reportEvaluateRecord2:(type:string, id:string) => `${reportProbation}/15/${type}/${id}`, - reportEvaluate:(type:string, id:string) => `${reportProbation}/16/${type}/${id}`, - reportEvaluateChairman:(type:string, id:string) => `${reportProbation}/17/${type}/${id}`, - reportEvaluateResult:(type:string, id:string) => `${reportProbation}/19/${type}/${id}`, - // reportSurvey:(type:string, id:string) => `${reportProbation}/19/${type}/${id}`, + //filetransfer + reportTransferFile: (no: number, type: string, id: string) => + `${reportTransfer}/${no}/${type}/${id}`, - //filetransfer - reportTransferFile:(no:number,type:string,id:string) => `${reportTransfer}/${no}/${type}/${id}`, - - DeceasedReport:(type:string,id:string) => `${reportDeceased}/36/${type}/${id}` - - - - - - }; + DeceasedReport: (type: string, id: string) => + `${reportDeceased}/36/${type}/${id}`, + reportTemplate, +}; diff --git a/src/modules/10_order/components/step/step04.vue b/src/modules/10_order/components/step/step04.vue index 7c99646f2..485428fd2 100644 --- a/src/modules/10_order/components/step/step04.vue +++ b/src/modules/10_order/components/step/step04.vue @@ -8,7 +8,8 @@ import { useQuasar } from "quasar"; import { useRoute } from "vue-router"; import http from "@/plugins/http"; import config from "@/app.config"; -// import { aW } from "@fullcalendar/core/internal-common"; +import axios from "axios"; +import genReport from "@/plugins/genreport"; const mixin = useCounterMixin(); const { @@ -38,7 +39,7 @@ const fileTailer = ref(null); const OrderPDFUpload = ref(""); const TailerPDFUpload = ref(""); -const orderCoverPdf = ref(""); +const orderCoverPdf = ref(); const orderAttachmentPdf = ref(""); const statusOrder = ref(); @@ -79,6 +80,20 @@ const attachmentStatus = computed(() => { : false; }); +// เช็คว่าต้องไป gen report ที่ server เพิ่มไหม code ที่เพิ่มคือคำสั่งใหม่ที่ต้องไป gen report อีกรอบ +const genReportStatus = computed(() => { + return code.value == "c-pm-25" || + code.value == "c-pm-26" || + code.value == "c-pm-27" || + code.value == "c-pm-28" || + code.value == "c-pm-29" || + code.value == "c-pm-30" || + code.value == "c-pm-31" || + code.value == "c-pm-32" + ? true + : false; +}); + // เรียกข้อมูลคำสั่ง const getCommandDetail = async () => { await http @@ -103,19 +118,33 @@ const getCommandDetail = async () => { // โหลดคำสั่ง const downloadCover = async (type: string) => { showLoader(); - await http - .get(config.API.fileCover(code.value, type, orderId.value), { - responseType: "blob", - }) - .then(async (res) => { - downloadFile(res, `คำสั่ง ${orderName.value}.${type}`); - }) - .catch((e) => { - messageError($q, e); - }) - .finally(() => { - hideLoader(); - }); + + if (!genReportStatus) { + await http + .get(config.API.fileCover(code.value, type, orderId.value), { + responseType: "blob", + }) + .then(async (res) => { + downloadFile(res, `คำสั่ง ${orderName.value}.${type}`); + }) + .catch((e) => { + messageError($q, e); + }) + .finally(() => { + hideLoader(); + }); + } else { + const link = document.createElement("a"); + var fileName = `คำสั่ง ${orderName.value}.${ + type === "docx" ? "docx" : "pdf" + }`; + link.href = orderCoverPdf.value; + link.setAttribute("download", fileName); + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); + hideLoader(); + } }; // โหลด เอกสารแนบท้าย const downloadAttachment = async (type: string) => { @@ -137,15 +166,45 @@ const downloadAttachment = async (type: string) => { // เรียกไฟล์ คำสั่ง const fetchReportCover = async (type: string, orderId: string) => { await http - .get(config.API.reportOrderCover(type, orderId, code.value), { - responseType: "blob", - }) - .then((res) => { - const blob = new Blob([res.data]); - const objectUrl = URL.createObjectURL(blob); - orderCoverPdf.value = objectUrl; - if (tab.value == "main") { - viewPDF(orderCoverPdf.value); + .get( + config.API.reportOrderCover(type, orderId, code.value), + !genReportStatus.value + ? { + responseType: "blob", + } + : {} + ) + .then(async (res: any) => { + if (!genReportStatus.value) { + const blob = new Blob([res.data]); + const objectUrl = URL.createObjectURL(blob); + orderCoverPdf.value = objectUrl; + if (tab.value == "main") { + viewPDF(orderCoverPdf.value); + } + } else { + // report template + await axios + .post(`${config.API.reportTemplate}/docx`, res.data.result, { + headers: { + accept: "application/pdf", + "content-Type": "application/json", + }, + responseType: "blob", + }) + .then((resReport) => { + const data = resReport.data; + if (data) { + const blob = new Blob([data]); + const objectUrl = URL.createObjectURL(blob); + orderCoverPdf.value = objectUrl; + viewPDF(orderCoverPdf.value); + } + }) + .catch((err) => { + messageError($q, err); + }) + .finally(() => {}); } }) .catch((e) => { diff --git a/src/plugins/genreport.ts b/src/plugins/genreport.ts index 7b39dcc63..0673a76a8 100644 --- a/src/plugins/genreport.ts +++ b/src/plugins/genreport.ts @@ -1,4 +1,6 @@ import axios from "axios"; +import config from "@/app.config"; + import { useQuasar } from "quasar"; import { useCounterMixin } from "@/stores/mixin"; @@ -7,13 +9,10 @@ const $q = useQuasar(); const mixin = useCounterMixin(); const { showLoader, hideLoader, messageError } = mixin; -const apiGenReport = - "https://report-server.frappet.synology.me/api/v1/report-template/docx"; - async function genReport(data: any, fileName: string, type: string = "docx") { showLoader(); await axios - .post(apiGenReport, data, { + .post(`${config.API.reportTemplate}/docx`, data, { headers: type == "docx" ? {