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

@ -39,27 +39,13 @@ const props = defineProps<{
defineEmits<{
(e: 'filterOwnerBranch', val: string, update: void): void;
}>();
onMounted(async () => {
if(!!props.optionsBranch) {
registeredBranchId.value = props.optionsBranch[0].id ;
}
});
</script>
<template>
<div class="col-3 app-text-muted">
{{ $t(`formDialogTitleInformation`) }}
</div>
<div v-if="!employee" class="col-9 row q-col-gutter-md">
<q-select
id="input-source-nationality"
:dense="dense"
@ -76,15 +62,16 @@ onMounted(async () => {
option-value="id"
v-model="registeredBranchId"
:options="optionsBranch"
:rules="[
(val) => {
const roles = getRole() || [];
const isSpecialRole = ['admin', 'system', 'head_of_admin'].some(role => roles.includes(role));
return isSpecialRole || !!val || 'กรุณากรอกข้อมูล';
}
]"
clearable
:rules="[
(val) => {
const roles = getRole() || [];
const isSpecialRole = ['admin', 'system', 'head_of_admin'].some(
(role) => roles.includes(role),
);
return isSpecialRole || !!val || 'กรุณากรอกข้อมูล';
},
]"
clearable
/>
<q-input
@ -110,7 +97,7 @@ clearable
class="col-6"
:label="$t('taxNo')"
v-model="taxNo"
:rules="[
:rules="[
(val) =>
(val && val.length === 13 && /[0-9]+/.test(val)) ||
$t('formDialogInputTaxNoValidate'),

View file

@ -24,23 +24,6 @@ const props = defineProps<{
service?: boolean;
optionsBranch?: { id: string; name: string }[];
}>();
onMounted( async() => {
setTimeout(() => {
if(!!props.optionsBranch ){
registeredBranchId.value = props.optionsBranch[0].id ;
}
}, 100);
});
</script>
<template>

View file

@ -1,13 +1,32 @@
<script setup lang="ts">
import { computed, ref } from 'vue';
import { computed, ref, onMounted } from 'vue';
import { useRouter } from 'vue-router';
import { storeToRefs } from 'pinia';
import { Icon } from '@iconify/vue';
import useMyBranch from 'stores/my-branch';
import { getUserId, getRole } from 'src/services/keycloak';
defineProps<{
mini?: boolean;
}>();
onMounted(async () => {
const uid = getUserId();
const role = getRole();
if (!uid) return;
if (role?.includes('system')) {
const result = await userBranch.fetchListOptionBranch();
if (result && result.total > 0) currentMyBranch.value = result.result[0];
}
const result = await userBranch.fetchListMyBranch(uid);
if (result && result.total > 0) currentMyBranch.value = result.result[0];
});
const router = useRouter();
const userBranch = useMyBranch();
const { currentMyBranch } = storeToRefs(userBranch);
const currentRoute = ref<string>('');
const currentPath = computed(() => {
@ -175,10 +194,14 @@ function branchSetting() {}
style="white-space: nowrap"
>
<span class="text-weight-bold">
{{ 'ชื่อสาขาที่ 1' }}
{{
($i18n.locale === 'en-US'
? currentMyBranch?.nameEN
: currentMyBranch?.name) ?? '-'
}}
</span>
<span>
{{ 'BR1001' }}
{{ currentMyBranch?.code ?? '-' }}
</span>
</div>