From 3f627856a1d7841cc0f402895c49db3afc8c31de Mon Sep 17 00:00:00 2001 From: setthawutttty Date: Tue, 26 Aug 2025 10:48:38 +0700 Subject: [PATCH] =?UTF-8?q?fix::=20=E0=B9=81=E0=B8=81=E0=B9=89=E0=B9=80?= =?UTF-8?q?=E0=B8=AA=E0=B9=89=E0=B8=99=20API=20=E0=B8=A3=E0=B8=B2=E0=B8=A2?= =?UTF-8?q?=E0=B8=87=E0=B8=B2=E0=B8=99=E0=B8=AA=E0=B8=96=E0=B8=B4=E0=B8=95?= =?UTF-8?q?=E0=B8=B4=E0=B8=81=E0=B8=B2=E0=B8=A3=E0=B8=A5=E0=B8=87=E0=B9=80?= =?UTF-8?q?=E0=B8=A7=E0=B8=A5=E0=B8=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/09_leave/api.leave.ts | 3 +- src/modules/09_leave/views/06_ReportMain.vue | 91 +++++++++++++++++++- 2 files changed, 91 insertions(+), 3 deletions(-) diff --git a/src/api/09_leave/api.leave.ts b/src/api/09_leave/api.leave.ts index 3d345b7de..338f59175 100644 --- a/src/api/09_leave/api.leave.ts +++ b/src/api/09_leave/api.leave.ts @@ -55,6 +55,7 @@ export default { leaveReportLeave2: (type: string) => `${leaveReport}/leave2/${type}`, addApproverByType:(type:string,profileType:string,id:string)=>`${leave}/${profileType}/add-approver/${type}/${id}`, - sendApprove:(id:string)=>`${leave}/admin/approve/officer/${id}` + sendApprove:(id:string)=>`${leave}/admin/approve/officer/${id}`, + leaveReportAPI:(type:string)=>`${leave}/report/download/time-records/${type}` }; diff --git a/src/modules/09_leave/views/06_ReportMain.vue b/src/modules/09_leave/views/06_ReportMain.vue index 9e7eacc3c..5de0fb5ec 100644 --- a/src/modules/09_leave/views/06_ReportMain.vue +++ b/src/modules/09_leave/views/06_ReportMain.vue @@ -30,7 +30,7 @@ const $q = useQuasar(); const route = useRoute(); const { fetchStructureTree } = useStructureTree(); -const { date2Thai, dateToISO, messageError, monthYear2Thai } = +const { date2Thai, dateToISO, messageError, monthYear2Thai,showLoader,hideLoader } = useCounterMixin(); const year = ref(new Date().getFullYear()); @@ -395,6 +395,68 @@ function formatWeekDisplay(week: Date[]) { } } +const isLoad = ref(false); + +/** + * + * @param isName ชื่อไฟล์ + * @param fileType pdf/xlsx + */ +function getReport(isName: string) { + showLoader() + const body = { + type: + leaveType.value === "FULL" + ? "FULL" + : leaveType.value === "MONTH" + ? "MONTH" + : leaveType.value == "HAFT" + ? "HAFT" + : leaveType.value == "DAY" + ? "DAY" + : "WEEKLY", + startDate: dateToISO(dateStart.value), + endDate: dateToISO(dateEnd.value), + nodeId: nodeId.value, + node: nodeLevel.value, + }; + http + .post(config.API.leaveReportAPI(employeeClass.value), body, { + headers: { + accept: + "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", + "content-Type": "application/json", + }, + + responseType: "blob", + }) + .then((res) => { + const data = res.data; + if (data) { + // สร้าง Blob จาก array buffer + const blob = new Blob([data]); + + // สร้าง URL สำหรับไฟล์ Blob + const url = URL.createObjectURL(blob); + + // สร้างลิงก์เพื่อดาวน์โหลดไฟล์ + const link = document.createElement("a"); + link.href = url; + link.download = `${isName}.xlsx`; // กำหนดชื่อไฟล์ที่จะดาวน์โหลด + document.body.appendChild(link); + link.click(); + + // ลบ URL ที่สร้างขึ้นหลังจากใช้งาน + URL.revokeObjectURL(url); + } + }) + .catch((e) => { + messageError($q, e); + }) + .finally(() => { + hideLoader() + }); +} onMounted(() => { fetchDataTree(); }); @@ -440,7 +502,7 @@ onMounted(() => { round color="primary" icon="download" - v-if="checkPermission($route)?.attrIsGet" + v-if="checkPermission($route)?.attrIsGet && typeReport !== '3'" > @@ -502,6 +564,24 @@ onMounted(() => { + + @@ -921,6 +1001,7 @@ onMounted(() => { {
{
+ + + +

รายงานการเข้างานไม่มี พรีวิว

+