From 1de3d3575254732e4c72bf792a95a744c0cd4149 Mon Sep 17 00:00:00 2001 From: "DESKTOP-1R2VSQH\\Lenovo ThinkPad E490" Date: Tue, 21 Apr 2026 14:14:38 +0700 Subject: [PATCH] refactor(retirement): download retirementReport --- .../01_retirement/RetirementDetail.vue | 38 +++++++++++++------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/src/modules/06_retirement/components/01_retirement/RetirementDetail.vue b/src/modules/06_retirement/components/01_retirement/RetirementDetail.vue index 2f773e5e1..08d05ff47 100644 --- a/src/modules/06_retirement/components/01_retirement/RetirementDetail.vue +++ b/src/modules/06_retirement/components/01_retirement/RetirementDetail.vue @@ -370,18 +370,32 @@ async function uploadFile(event: any, date: any) { */ async function downloadAttachment(type: string, id: string) { showLoader(); - await http - .get(config.API.reportRetireList(type, id)) - .then(async (res) => { - const data = res.data.result; - await genReport(data, `รายชื่อผู้เกษียณอายุราชการ`, type); - }) - .catch(async (e) => { - messageError($q, JSON.parse(await e.response.data.text())); - }) - .finally(() => { - hideLoader(); - }); + try { + const response = await http.get( + config.API.retirementReport + `/${type}/${id}`, + { + headers: { + accept: + type === "pdf" + ? "application/pdf" + : "application/vnd.openxmlformats-officedocument.wordprocessingml.document", + "content-Type": "application/json", + }, + responseType: "blob", + } + ); + const blob = response.data; + const url = URL.createObjectURL(blob); + const link = document.createElement("a"); + link.href = url; + link.download = `รายชื่อผู้เกษียณอายุราชการ.${type}`; + link.click(); + URL.revokeObjectURL(url); + } catch (e) { + messageError($q, e); + } finally { + hideLoader(); + } } // ยืนยันการแก้ไขข้อมูล