diff --git a/src/modules/13_salary/components/04_salaryLists/TabMain.vue b/src/modules/13_salary/components/04_salaryLists/TabMain.vue index 07b06f477..9db593cd9 100644 --- a/src/modules/13_salary/components/04_salaryLists/TabMain.vue +++ b/src/modules/13_salary/components/04_salaryLists/TabMain.vue @@ -23,7 +23,7 @@ import DialogInfoCriteria from "@/modules/13_salary/components/04_salaryLists/Di import { useCounterMixin } from "@/stores/mixin"; import { useSalaryListSDataStore } from "@/modules/13_salary/store/SalaryListsStore"; -/** use*/ +/** use composables*/ const $q = useQuasar(); const store = useSalaryListSDataStore(); const { messageError, showLoader, hideLoader } = useCounterMixin(); @@ -41,6 +41,8 @@ const props = defineProps({ const total = ref(0); const splitterModel = ref(13); const rows = ref([]); +const modalDialogInfoCriteria = ref(false); // ตัวแปรสำหรับแสดง Dialog แสดงหลักเกณฑ์การพิจารณาเลื่อนขั้นเงินข้าราชการ +const isRetire = ref(false); // ตัวแปรสำหรับแสดงเฉพาะผู้เกษียณอายุราชการ /** itemsTab กลุ่ม*/ const itemsTabGroup = ref([ @@ -208,21 +210,21 @@ const itemsCard = ref([ }, ]); -/** ข้อมูลค้นหารายชื่อคยขึ้นเงินเดือน*/ +/** ข้อมูลค้นหารายชื่อคนขึ้นเงินเดือน*/ const formFilter = reactive({ page: 1, pageSize: 10, keyword: "", type: store.tabType, }); -const maxPage = ref(1); +const maxPage = ref(1); // จำนวนหน้าสูงสุด /** - * function เรียกข้อมูลจำนวนโควต้า + * ฟังก์ชันเรียกข้อมูลโควต้า * @param id กลุ่ม */ -function fetchDataQuota(id: string) { - http +async function fetchDataQuota(id: string) { + await http .get(config.API.salaryListPeriodQuota(id)) .then((res) => { const data = res.data.result; @@ -250,12 +252,10 @@ function fetchDataQuota(id: string) { } /** - * function เรียกข้อมูลรายชื่อ + * ฟังก์ชันเรียกข้อมูลรายชื่อเลื่อนเงินเดือนข้าราชการฯ * @param id กลุ่ม */ async function fetchDataPeriod(id: string) { - showLoader(); - let formData = { page: formFilter.page.toString(), pageSize: formFilter.pageSize.toString(), @@ -279,37 +279,62 @@ async function fetchDataPeriod(id: string) { }) .catch((err) => { messageError($q, err); - }) - .finally(() => { - hideLoader(); }); } -/**function เปลี่ยนกลุ่ม*/ -function changeTabGroup() { - formFilter.page = 1; - formFilter.pageSize = 10; - formFilter.keyword = ""; - store.tabType = "PENDING"; - props.periodLatest && - store.fetchPeriodLatest(props?.periodLatest, store.tabGroup); - store.groupId && fetchDataQuota(store.groupId); - store.groupId && fetchDataPeriod(store.groupId); - splitterModel.value = store.roundMainCode === "APR" ? 13 : 16; +/**ฟังก์ชันเปลี่ยนกลุ่ม*/ +async function changeTabGroup() { + showLoader(); + try { + await Promise.all([ + (formFilter.page = 1), + (formFilter.pageSize = 10), + (formFilter.keyword = ""), + (store.tabType = "PENDING"), + props.periodLatest && + store.fetchPeriodLatest(props?.periodLatest, store.tabGroup), + store.groupId && fetchDataQuota(store.groupId), + store.groupId && fetchDataPeriod(store.groupId), + (splitterModel.value = store.roundMainCode === "APR" ? 13 : 16), + ]); + } catch (error) { + messageError($q, error); + } finally { + hideLoader(); + } } -/**function เปลี่ยนขั้น*/ -function changeTabType() { - formFilter.page = 1; - formFilter.pageSize = 10; - formFilter.keyword = ""; - store.groupId && fetchDataPeriod(store.groupId); +/**ฟังก์ชันเปลี่ยนขั้น*/ +async function changeTabType() { + if (!store.groupId) return; + showLoader(); + try { + formFilter.page = 1; + formFilter.pageSize = 10; + formFilter.keyword = ""; + store.groupId && (await fetchDataPeriod(store.groupId)); + } catch (error) { + messageError($q, error); + } finally { + hideLoader(); + } } -/** function เรียกข้อมูลรายชื่ออีกครั้ง*/ -function fetchDataPeriodNew() { - store.groupId && fetchDataPeriod(store.groupId); - store.groupId && fetchDataQuota(store.groupId); +/** ฟังก์ชันเรียกข้อมูลรายชื่ออีกครั้งและโควต้า */ +async function fetchDataPeriodNew() { + if (!store.groupId) return; + + showLoader(); + try { + await Promise.all([ + fetchDataPeriod(store.groupId), + fetchDataQuota(store.groupId), + ]); + } catch (error) { + messageError($q, error); + } finally { + hideLoader(); + } } function onClickDownload(data: DataOption, type: string = "xlsx") { @@ -386,20 +411,29 @@ function onClickDownload(data: DataOption, type: string = "xlsx") { } } -const modalDialogInfoCriteria = ref(false); -onMounted(() => { +/** ฟังก์ชันแสดงเฉพาะผู้เกษียณอายุราชการ*/ +async function updateIsShowRetire() { + isRetire.value = !isRetire.value; + await fetchDataPeriodNew(); +} + +/** ฟังก์ชันเรียกข้อมูลเมื่อ component ถูกเรียก */ +onMounted(async () => { if (props.rootId) { - fetchDataQuota(store.groupId); - fetchDataPeriod(store.groupId); - splitterModel.value = store.roundMainCode === "APR" ? 13 : 16; + showLoader(); + try { + await Promise.all([ + fetchDataQuota(store.groupId), + fetchDataPeriod(store.groupId), + (splitterModel.value = store.roundMainCode === "APR" ? 13 : 16), + ]); + } catch (error) { + messageError($q, error); + } finally { + hideLoader(); + } } }); - -const isRetire = ref(false); -const updateIsShowRetire = async () => { - isRetire.value = !isRetire.value; - fetchDataPeriodNew(); -};