diff --git a/src/pages/02_personnel-management/MainPage.vue b/src/pages/02_personnel-management/MainPage.vue index 677c75b6..d069f544 100644 --- a/src/pages/02_personnel-management/MainPage.vue +++ b/src/pages/02_personnel-management/MainPage.vue @@ -298,11 +298,7 @@ async function onSubmit() { } } - userStore.fetchList({ - includeBranch: true, - query: !!inputSearch.value ? inputSearch.value : undefined, - userType: selectorLabel.value ?? undefined, - }); + await fetchUserList(); typeStats.value = await userStore.typeStats(); const res = await branchStore.userStats(formData.value.userType); if (res) { @@ -337,11 +333,9 @@ async function onSubmit() { } selectorLabel.value = formData.value.userType; - userStore.fetchList({ - includeBranch: true, - query: !!inputSearch.value ? inputSearch.value : undefined, - userType: selectorLabel.value ?? undefined, - }); + + await fetchUserList(); + typeStats.value = await userStore.typeStats(); const res = await branchStore.userStats(formData.value.userType); if (res) { @@ -362,11 +356,8 @@ async function onDelete(id: string) { message: 'คุณต้องการลบข้อมูล ใช่หรือไม่', action: async () => { await userStore.deleteById(id); - await userStore.fetchList({ - includeBranch: true, - query: !!inputSearch.value ? inputSearch.value : undefined, - userType: selectorLabel.value ?? undefined, - }); + + await fetchUserList(); typeStats.value = await userStore.typeStats(); flowStore.rotate(); }, @@ -474,11 +465,8 @@ async function assignFormData(idEdit: string) { } onMounted(async () => { - await userStore.fetchList({ - includeBranch: true, - query: !!inputSearch.value ? inputSearch.value : undefined, - userType: selectorLabel.value ?? undefined, - }); + await fetchUserList(); + userStore.userOption.roleOpts.length === 0 ? await userStore.fetchRoleOption() : ''; @@ -501,11 +489,7 @@ watch( () => selectorLabel.value, async (label) => { mapUserType(label); - await userStore.fetchList({ - includeBranch: true, - query: !!inputSearch.value ? inputSearch.value : undefined, - userType: selectorLabel.value ?? undefined, - }); + await fetchUserList(); const res = await branchStore.userStats(label); if (res) { userStats.value = res; @@ -513,13 +497,6 @@ watch( }, ); -watch(inputSearch, async () => { - await userStore.fetchList({ - pageSize: 9999, - query: !!inputSearch.value ? inputSearch.value : undefined, - }); -}); - watch( () => formData.value.userType, async () => { @@ -536,6 +513,24 @@ watch( agencyFile.value = []; }, ); + +const currentPage = ref(1); +const currentMaxPage = computed(() => + userData.value + ? Math.ceil(userData.value?.total / userData.value?.pageSize) + : 1, +); + +async function fetchUserList() { + await userStore.fetchList({ + includeBranch: true, + page: currentPage.value, + query: !!inputSearch.value ? inputSearch.value : undefined, + userType: selectorLabel.value ?? undefined, + }); +} + +watch(inputSearch, async () => await fetchUserList());