feat: select user type that at least have one

This commit is contained in:
Methapon2001 2024-04-17 17:19:58 +07:00
parent eb56b59f95
commit a1167dd6a5

View file

@ -1,6 +1,5 @@
<script setup lang="ts">
import { ref, onMounted, watch } from 'vue';
import { api } from 'src/boot/axios';
import { useRouter } from 'vue-router';
import { storeToRefs } from 'pinia';
import useUserStore from 'stores/user';
@ -288,6 +287,13 @@ onMounted(async () => {
? await userStore.fetchRoleOption()
: '';
typeStats.value = await userStore.typeStats();
const firstTypeIncludeUser = Object.entries(typeStats.value || {}).find(
(v) => v[1] > 0,
);
firstTypeIncludeUser && (selectorLabel.value = firstTypeIncludeUser[0]);
const res = await branchStore.userStats(formData.value.userType);
if (res) {
userStats.value = res;
@ -298,6 +304,10 @@ watch(
() => selectorLabel.value,
async (label) => {
mapUserType(label);
await userStore.fetchList({
includeBranch: true,
userType: selectorLabel.value ?? undefined,
});
const res = await branchStore.userStats(label);
if (res) {
userStats.value = res;