diff --git a/src/modules/09_leave/views/06_ReportMain.vue b/src/modules/09_leave/views/06_ReportMain.vue index 9d48079d6..5a8df9215 100644 --- a/src/modules/09_leave/views/06_ReportMain.vue +++ b/src/modules/09_leave/views/06_ReportMain.vue @@ -24,14 +24,8 @@ import LoadView from "@/components/LoadView.vue"; const $q = useQuasar(); const route = useRoute(); const { fetchStructureTree } = useStructureTree(); -const { - showLoader, - hideLoader, - date2Thai, - dateToISO, - messageError, - monthYear2Thai, -} = useCounterMixin(); +const { date2Thai, dateToISO, messageError, monthYear2Thai } = + useCounterMixin(); const year = ref(new Date().getFullYear()); const dateStart = ref(new Date(year.value - 1, 9, 1)); @@ -77,17 +71,26 @@ const nodeLevel = ref(0); const node = ref([]); const expanded = ref([]); +/** ฟังก์ชันเรียกข้อมูลโครงสร้างหน่วยงาน*/ async function fetchDataTree() { node.value = await fetchStructureTree(route.meta.Key as string, true); } +/** + * ฟังก์ชันเลือกหน่วยงานที่ต้องการดูข้อมูล + * @param id id หน่วยงาน + * @param level node ของหน่วงงานที่เลือก + */ function onSelectedNode(id: string, level: number) { nodeId.value = id; nodeLevel.value = level; updateLeaveday(); } -/** function อัปเดทบัญชีแสดงวันลา */ +/** + * ฟังก์ชันอัปเดทบัญชีแสดงวันลา + * และเรียกข้อมูลรายงาน + */ async function updateLeaveday() { switch (yearType.value) { case "FULL": @@ -125,23 +128,17 @@ async function updateLeaveday() { isLoadPDF.value = true; pdfSrc.value = undefined; - typeReport.value === "1" - ? fetchLeaveday( - employeeClass.value, - yearType.value, - dateStart.value, - dateEnd.value - ) - : fetchLeaveday2( - employeeClass.value, - yearType.value, - dateStart.value, - dateEnd.value - ); + //เรียกฟังก์ชัน fetchLeaveday + fetchLeaveday( + employeeClass.value, + yearType.value, + dateStart.value, + dateEnd.value + ); } /** - * function เรียกข้อมูลบัญชีแสดงวันลา + * ฟังก์ชันเรียกข้อมูลรายงาน * @param type สถานภาพ * @param year ปั * @param startDate วันเริ่มต้น @@ -161,38 +158,13 @@ async function fetchLeaveday( node: nodeLevel.value, }; - await http - .post(config.API.leaveReportLeaveday(type), body) - .then(async (res) => { - const data = res.data.result; - data && (await fetchDocumentTemplate(data)); - isReport.value = data ? true : false; - detailReport.value = data; - }) - .catch((err) => { - messageError($q, err); - }) - .finally(() => { - isLoadPDF.value = false; - }); -} - -async function fetchLeaveday2( - type: string, - year: string, - startDate: Date, - endDate: Date -) { - const body = { - type: year === "FULL" ? "FULL" : year === "MONTH" ? "MONTH" : "HAFT", - startDate: dateToISO(startDate), - endDate: dateToISO(endDate), - nodeId: nodeId.value, - node: nodeLevel.value, - }; + const pathAPI = + typeReport.value === "1" + ? config.API.leaveReportLeaveday(type) + : config.API.leaveReportLeave2(type); await http - .post(config.API.leaveReportLeave2(type), body) + .post(pathAPI, body) .then(async (res) => { const data = res.data.result; data && (await fetchDocumentTemplate(data)); @@ -233,12 +205,10 @@ async function fetchDocumentTemplate(data: any) { .catch(async (e) => { messageError($q, JSON.parse(await e.response.data.text())); }) - .finally(() => { - setTimeout(() => { - hideLoader(); - }, 2000); - }); + .finally(() => {}); } + +//ตัวแปร PDF const numOfPages = ref(0); const page = ref(1); const pdfSrc = ref(); @@ -366,7 +336,7 @@ onMounted(() => {