From 32239c891a3bccc8ffe46481b4602ae15feda095 Mon Sep 17 00:00:00 2001 From: "DESKTOP-1R2VSQH\\Lenovo ThinkPad E490" Date: Fri, 14 Jun 2024 16:13:45 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B8=88=E0=B8=B1=E0=B8=94=E0=B8=97=E0=B8=B3?= =?UTF-8?q?=E0=B8=9B=E0=B8=A3=E0=B8=B0=E0=B8=81=E0=B8=B2=E0=B8=A8=E0=B8=9C?= =?UTF-8?q?=E0=B8=B9=E0=B9=89=E0=B8=A1=E0=B8=B5=E0=B8=9C=E0=B8=A5=E0=B8=81?= =?UTF-8?q?=E0=B8=B2=E0=B8=A3=E0=B8=9B=E0=B8=8F=E0=B8=B4=E0=B8=9A=E0=B8=B1?= =?UTF-8?q?=E0=B8=95=E0=B8=B4=E0=B8=A3=E0=B8=B2=E0=B8=8A=E0=B8=81=E0=B8=B2?= =?UTF-8?q?=E0=B8=A3=E0=B8=A3=E0=B8=B0=E0=B8=94=E0=B8=B1=E0=B8=9A=E0=B8=94?= =?UTF-8?q?=E0=B8=B5=E0=B9=80=E0=B8=94=E0=B9=88=E0=B8=99=E0=B9=81=E0=B8=A5?= =?UTF-8?q?=E0=B8=B0=E0=B8=94=E0=B8=B5=E0=B8=A1=E0=B8=B2=E0=B8=81=20=3D>?= =?UTF-8?q?=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/14_KPI/views/report.vue | 72 ++++++++++++++++++++++------- 1 file changed, 56 insertions(+), 16 deletions(-) diff --git a/src/modules/14_KPI/views/report.vue b/src/modules/14_KPI/views/report.vue index fce0da73e..4cbb751f5 100644 --- a/src/modules/14_KPI/views/report.vue +++ b/src/modules/14_KPI/views/report.vue @@ -5,6 +5,7 @@ import { VuePDF, usePDF } from "@tato30/vue-pdf"; import config from "@/app.config"; import http from "@/plugins/http"; import axios from "axios"; +import genReport from "@/plugins/genreport"; import { useCounterMixin } from "@/stores/mixin"; @@ -44,6 +45,8 @@ function fetchRoundOption() { roundOp.value = []; round.value = ""; organization.value = ""; + dataDownload.value = null; + pdfSrc.value = null; } }) .catch((err) => { @@ -93,14 +96,50 @@ function fetchReport() { }; http .post(config.API.kpiReport(), body) - .then((res) => {}) - .catch((err) => {}) - .finally(() => { + .then((res) => { + dataDownload.value = res.data.result; + page.value = 1; + genPDf(res.data.result); + }) + .catch((err) => { + messageError($q, err); hideLoader(); }); } } +/** + * function เรียกไฟล์ PDF + * @param data ข้อมูลบัญชีวันลา + */ +async function genPDf(data: any) { + showLoader(); + await axios + .post(config.API.reportTemplate + `/docx`, 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 = await usePDF(`${objectUrl}`); + showLoader(); + setTimeout(() => { + pdfSrc.value = pdfData.pdf.value; + numOfPages.value = pdfData.pages.value; + hideLoader(); + }, 1500); + }) + .catch(async (e) => { + messageError($q, JSON.parse(await e.response.data.text())); + hideLoader(); + }); +} + function changOption() { fetchReport(); } @@ -117,16 +156,11 @@ const splitterModel = ref(14); const numOfPages = ref(0); const page = ref(1); const pdfSrc = ref(); -const fileBlob = ref(); +const dataDownload = ref(); async function downloadReport(data: any, type: string) { - const link = document.createElement("a"); var fileName = "ประกาศผู้มีผลการปฏิบัติราชการระดับดีเด่นและดีมาก"; - link.href = window.URL.createObjectURL(new Blob([data])); - link.setAttribute("download", `${fileName}.${type}`); - document.body.appendChild(link); - link.click(); - document.body.removeChild(link); + genReport(data, fileName, type); } /** ไปหน้าต่อไปของรายงาน */ @@ -227,13 +261,19 @@ onMounted(() => { - + { { before-class="overflow-hidden disable" separator-class="bg-white disabled" > -