From 5d72fbde3fd8cabafd2e49922cfa09589126ffa8 Mon Sep 17 00:00:00 2001 From: AnandaTon Date: Wed, 30 Aug 2023 10:32:31 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=E0=B9=84=E0=B8=82?= =?UTF-8?q?=20=20api=20Download=20=E0=B8=A3=E0=B8=B2=E0=B8=A2=E0=B8=8A?= =?UTF-8?q?=E0=B8=B7=E0=B9=88=E0=B8=AD=E0=B8=9C=E0=B8=B9=E0=B9=89=E0=B9=80?= =?UTF-8?q?=E0=B8=81=E0=B8=A9=E0=B8=B5=E0=B8=A2=E0=B8=93=E0=B8=AD=E0=B8=B2?= =?UTF-8?q?=E0=B8=A2=E0=B8=B8=E0=B8=A3=E0=B8=B2=E0=B8=8A=E0=B8=81=E0=B8=B2?= =?UTF-8?q?=E0=B8=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/ListRetirement/TableList.vue | 56 ++++++++++++++----- 1 file changed, 42 insertions(+), 14 deletions(-) diff --git a/src/modules/06_retirement/components/ListRetirement/TableList.vue b/src/modules/06_retirement/components/ListRetirement/TableList.vue index 7b5023014..28b907829 100644 --- a/src/modules/06_retirement/components/ListRetirement/TableList.vue +++ b/src/modules/06_retirement/components/ListRetirement/TableList.vue @@ -150,14 +150,12 @@ const visibleColumns = ref([ const action = ref(""); const fileUpload = ref(null); -const clickOpenDownloadPDF =() =>{window.open(orderCoverPdf.value);} -const clickOpenDownloadDoc =() =>{window.open(orderCoverDocs.value);} onMounted(() => { retireld.value = retireld_params.toString(); fecthlistprofile(retireld.value); - fetchReportCover("pdf", retireld.value); - fetchReportCover("docx", retireld.value); + // fetchReportCover("pdf", retireld.value); + // fetchReportCover("docx", retireld.value); }); const round = ref(); const typeReport = ref(""); @@ -325,24 +323,54 @@ const uploadFile = async (event: any) => { }); }; -const fetchReportCover = async (type: string, orderId: string) => { +const downloadAttachment = async (type: string, id: string) => { showLoader(); await http - .get(config.API.reportRetireList(type, orderId)) + .get(config.API.reportRetireList(type, id), { + responseType: "blob", + }) .then(async (res) => { - if (type == "pdf") { - orderCoverPdf.value = res.data.result; - } else { - orderCoverDocs.value = res.data.result; - } + const data = res.data.result; + console.log(data); + let list: any[] = []; + downloadFile(res, `${id}.${type}`); }) .catch((e) => { - // messageError($q, e); + messageError($q, e); }) .finally(() => { hideLoader(); }); }; +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 fetchReportCover = async (type: string, orderId: string) => { +// showLoader(); +// await http +// .get(config.API.reportRetireList(type, orderId)) +// .then(async (res) => { +// if (type == "pdf") { +// orderCoverPdf.value = res.data.result; +// } else { +// orderCoverDocs.value = res.data.result; +// } +// }) +// .catch((e) => { +// // messageError($q, e); +// }) +// .finally(() => { +// hideLoader(); +// }); +// }; // const classrow = (prop: any) => { // if (profileId.value !== "" && prop.profileId === profileId.value) { @@ -402,7 +430,7 @@ const paginationLabel = (start: number, end: number, total: number) => { clickable v-close-popup type="a" - @click="clickOpenDownloadPDF" + @click="downloadAttachment('pdf', retireld)" target="_blank" > { clickable v-close-popup type="a" - @click="clickOpenDownloadDoc" + @click="downloadAttachment('docx', retireld)" target="_blank" >