diff --git a/src/modules/07_insignia/components/2_Manage/Tab1.vue b/src/modules/07_insignia/components/2_Manage/Tab1.vue index 5641ad146..884864418 100644 --- a/src/modules/07_insignia/components/2_Manage/Tab1.vue +++ b/src/modules/07_insignia/components/2_Manage/Tab1.vue @@ -1245,17 +1245,15 @@ onMounted(async () => { - + {{ props.rowIndex + 1 }} diff --git a/src/modules/07_insignia/components/2_Manage/downloadFile.vue b/src/modules/07_insignia/components/2_Manage/downloadFile.vue index e879bd3e6..caca2bc65 100644 --- a/src/modules/07_insignia/components/2_Manage/downloadFile.vue +++ b/src/modules/07_insignia/components/2_Manage/downloadFile.vue @@ -6,7 +6,8 @@ import { useCounterMixin } from "@/stores/mixin"; import http from "@/plugins/http"; import config from "@/app.config"; -import type { Optionround } from "@/modules/07_insignia/interface/index/Main"; +import genReport from "@/plugins/genreport"; +import genReportXLSX from "@/plugins/genreportxlsx"; /** use*/ const $q = useQuasar(); @@ -15,68 +16,37 @@ const { messageError, showLoader, hideLoader } = mixin; /** props*/ const props = defineProps({ - profileId: { + rowId: { type: String, }, - round: { - type: String, - }, - optionRound: { - type: Object, - }, }); -const titleReport = ref(""); //ชื่อรายงาน - /** * function ดาวน์โหลดไฟล์ * @param type ประเภท file */ async function downloadDocument(type: string) { - let round = []; - if (props.optionRound) { - round = props.optionRound.find((e: Optionround) => e.id === props.round); - } - titleReport.value = round.name; - const download: boolean = true; - if (props.profileId) { - showLoader(); - await http - .get(config.API.reportInsignia("46", type, props.profileId), { - responseType: "blob", - }) - .then(async (res) => { - if (download) { - downloadFile( - res, - `ประวัติสำหรับการเสนอขอพระราชทานเหรียญจักรพรรดิมาลา.${type}` - ); - } - }) - .catch(async (e) => { - messageError($q, JSON.parse(await e.response.data.text())); - }) - .finally(() => { - hideLoader(); - }); - } -} + showLoader(); + try { + const res = await http.post( + config.API.reportInsigniaNew + `/report8/${props.rowId}` + ); -/** - * function โหลดเอกสาร - * @param response ข้อมู - * @param filename ชื่อไฟล์ - */ -function 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 reportTitle = "ประวัติสำหรับการเสนอขอพระราชทานเหรียญจักรพรรดิมาลา"; + + if (type === "xlsx") { + await genReportXLSX(res.data.result, reportTitle, type); + } else { + await genReport(res.data.result, reportTitle, type); + } + } catch (error) { + messageError($q, error); + } finally { + hideLoader(); + } } +