diff --git a/src/modules/04_registryNew/views/detailView.vue b/src/modules/04_registryNew/views/detailView.vue index d7b3e6f7c..c259d03d0 100644 --- a/src/modules/04_registryNew/views/detailView.vue +++ b/src/modules/04_registryNew/views/detailView.vue @@ -259,11 +259,33 @@ async function fetchDataPersonal() { } function onClickDownloadKp7(type: string) { - if (type === "FULL") { - window.open(config.API.profileReportId(profileId.value)); - } else if (type === "SHORT") { - window.open(config.API.profileKp7ShortId(profileId.value)); - } + showLoader(); + const url = + type === "FULL" + ? config.API.profileReportId(profileId.value) + : config.API.profileKp7ShortId(profileId.value); + const fileName = type === "FULL" ? "ก.พ.7/ก.ก.1" : "ประวัติแบบย่อ"; + http + .get(url, { + responseType: "arraybuffer", // + }) + .then((res) => { + const data = res.data; + console.log(data); + const blob = new Blob([data], { type: "application/pdf" }); + const url = URL.createObjectURL(blob); + const link = document.createElement("a"); + link.href = url; + link.download = `${fileName}.pdf`; + document.body.appendChild(link); + link.click(); + }) + .catch((err) => { + messageError($q, err); + }) + .finally(() => { + hideLoader(); + }); } /** ช่วยราชการ */