diff --git a/src/modules/09_leave/components/3_Report/DetailReport.vue b/src/modules/09_leave/components/3_Report/DetailReport.vue index f1b04a802..0683e748b 100644 --- a/src/modules/09_leave/components/3_Report/DetailReport.vue +++ b/src/modules/09_leave/components/3_Report/DetailReport.vue @@ -111,6 +111,7 @@ const numOfPages = ref(0); const page = ref(1); const pdfSrc = ref(); const modalFull = ref(false); +const fileBlob = ref(); /** ไปหน้าต่อไปของรายงาน */ function nextPage() { if (page.value < numOfPages.value) { @@ -137,6 +138,7 @@ async function fetchReportTimeRecords(body: any) { .then((res) => { const data = res.data.result; data && genReport(data); + dataDetail.value = data; }) .catch((err) => { messageError($q, err); @@ -152,14 +154,13 @@ async function fetchLeaveday(type: string, year: string) { await http .post(config.API.leaveReportLeaveday(type), body) .then((res) => { - console.log(res); const data = res.data.result; data && genReport(data); + dataDetail.value = data; }) .catch((err) => { messageError($q, err); - }) - .finally(() => {}); + }); } async function updateFilterType() { @@ -221,8 +222,7 @@ async function genReport(data: any) { .then(async (res) => { const blob = new Blob([res.data]); const objectUrl = URL.createObjectURL(blob); - console.log(blob); - + fileBlob.value = blob; const pdfData = await usePDF(`${objectUrl}`); showLoader(); setTimeout(() => { @@ -239,12 +239,44 @@ async function genReport(data: any) { }); } +const dataDetail = ref([]); +async function genReportXLSX(data: any) { + await axios + .post(apiGenReport, data, { + headers: { + accept: + "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", + "content-Type": "application/json", + }, + responseType: "blob", + }) + .then(async (res) => { + const blob = new Blob([res.data]); + downloadReport(blob, "xlsx"); + }) + .catch((err) => { + messageError($q, err); + }) + .finally(() => { + hideLoader(); + }); +} + async function updateLeaveday() { fetchLeaveday(employeeClass.value, yearType.value); } +async function downloadReport(data: any, type: string) { + const link = document.createElement("a"); + var fileName = titleReport.value; + link.href = window.URL.createObjectURL(new Blob([data])); + link.setAttribute("download", `${fileName}.${type}`); + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); +} + onMounted(() => { - console.log(typeReport); const body = { startDate: dateToISO(date.value), endDate: dateToISO(date.value), @@ -343,10 +375,36 @@ onMounted(() => {
- + + + + + + ไฟล์ .PDF + + + + ไฟล์ .xlsx + + + + +
([ ]); const getDataNotification = async () => { - showLoader(); + // showLoader(); await http .get(config.API.msgNotificate) .then((res: any) => { @@ -107,7 +107,7 @@ const getDataNotification = async () => { // messageError($q, e); }) .finally(() => { - hideLoader(); + // hideLoader(); }); };