diff --git a/src/modules/10_registry/views/main.vue b/src/modules/10_registry/views/main.vue index 76694af..99db19a 100644 --- a/src/modules/10_registry/views/main.vue +++ b/src/modules/10_registry/views/main.vue @@ -21,7 +21,7 @@ import { useQuasar } from "quasar"; const store = useRegistryInFormationStore(); const $q = useQuasar(); const mixin = useCounterMixin(); -const { messageError, dialogConfirm } = mixin; +const { messageError, dialogConfirm ,showLoader,hideLoader } = mixin; const profileImg = ref(""); const router = useRouter(); const tab = ref("information"); @@ -89,11 +89,32 @@ function getType() { } function onClickDownloadKp7(type: string) { - if (type === "FULL") { - window.open(config.API.profileReportId(store.profileId)); - } else if (type === "SHORT") { - window.open(config.API.profileKp7ShortId(store.profileId)); - } + showLoader(); + const url = + type === "FULL" + ? config.API.profileReportId(store.profileId) + : config.API.profileKp7ShortId(store.profileId); + const fileName = type === "FULL" ? "ก.พ.7/ก.ก.1" : "ประวัติแบบย่อ"; + http + .get(url, { + responseType: "arraybuffer", // + }) + .then((res) => { + const data = res.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(); + }); } /**