feat: auto select current branch

This commit is contained in:
Methapon2001 2024-07-10 13:21:32 +07:00
parent dcefa3de02
commit 2dac800fad
5 changed files with 81 additions and 66 deletions

View file

@ -2,6 +2,7 @@
import { ref, watch, reactive } from 'vue';
import { useI18n } from 'vue-i18n';
import { onMounted } from 'vue';
import { getUserId, getRole } from 'src/services/keycloak';
import { storeToRefs } from 'pinia';
import type { QTableProps } from 'quasar';
import ItemCard from 'components/ItemCard.vue';
@ -33,9 +34,9 @@ import useMyBranchStore from 'src/stores/my-branch';
import { dateFormat } from 'src/utils/datetime';
import { formatNumberDecimal } from 'src/stores/utils';
const useMyBranch = useMyBranchStore();
const userBranchStore = useMyBranchStore();
const { fetchListOptionBranch } = useMyBranch;
const { currentMyBranch } = storeToRefs(userBranchStore);
import { Status } from 'src/stores/types';
@ -403,9 +404,22 @@ async function featchStatsService() {
}
async function fetchListOfOptionBranch() {
const res = await fetchListOptionBranch({ pageSize: 999 });
const uid = getUserId();
const role = getRole();
if (res) branchOption.value = res.result;
if (!uid) return;
if (role?.includes('system')) {
const result = await userBranchStore.fetchListOptionBranch();
if (result && result.total > 0) branchOption.value = result.result;
} else {
const result = await userBranchStore.fetchListMyBranch(uid);
if (result && result.total > 0) branchOption.value = result.result;
}
formDataProduct.value.registeredBranchId = currentMyBranch.value?.id || '';
formDataProductService.value.registeredBranchId =
currentMyBranch.value?.id || '';
}
async function featchStatsProduct() {
@ -3093,8 +3107,6 @@ watch(inputSearchProductAndService, async () => {
class="col-md-10 col-sm-12"
>
<div class="surface-1 rounded bordered q-pa-lg full-width row">
<BasicInformation
dense
service