refactor:handle sub branch
This commit is contained in:
parent
e95078e75e
commit
ca7713c88e
3 changed files with 30 additions and 134 deletions
|
|
@ -1,9 +1,10 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import useUserStore from 'stores/user';
|
import useUserStore from 'stores/user';
|
||||||
import { selectFilterOptionRefMod } from 'stores/utils';
|
import { selectFilterOptionRefMod } from 'stores/utils';
|
||||||
import { onMounted, ref, watch } from 'vue';
|
import { ref } from 'vue';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
import { isRoleInclude } from 'src/stores/utils';
|
import { isRoleInclude } from 'src/stores/utils';
|
||||||
|
import SelectBranch from '../shared/select/SelectBranch.vue';
|
||||||
|
|
||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
|
|
@ -15,7 +16,7 @@ const userRole = defineModel<string>('userRole');
|
||||||
const username = defineModel<string | null | undefined>('username');
|
const username = defineModel<string | null | undefined>('username');
|
||||||
const userCode = defineModel<string>('userCode');
|
const userCode = defineModel<string>('userCode');
|
||||||
|
|
||||||
const props = defineProps<{
|
defineProps<{
|
||||||
title?: string;
|
title?: string;
|
||||||
dense?: boolean;
|
dense?: boolean;
|
||||||
outlined?: boolean;
|
outlined?: boolean;
|
||||||
|
|
@ -24,35 +25,6 @@ const props = defineProps<{
|
||||||
usernameReadonly?: boolean;
|
usernameReadonly?: boolean;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
async function selectHq(id: string) {
|
|
||||||
if (!id) return;
|
|
||||||
brId.value = '';
|
|
||||||
userStore.userOption.brOpts = [];
|
|
||||||
await userStore.fetchBrOption(id);
|
|
||||||
if (userStore.userOption.brOpts.length === 1) {
|
|
||||||
brId.value = userStore.userOption.brOpts[0].value;
|
|
||||||
}
|
|
||||||
brFilter = selectFilterOptionRefMod(
|
|
||||||
ref(userStore.userOption.brOpts),
|
|
||||||
brOptions,
|
|
||||||
'label',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const hqOptions = ref<Record<string, unknown>[]>([]);
|
|
||||||
const hqFilter = selectFilterOptionRefMod(
|
|
||||||
ref(userStore.userOption.hqOpts),
|
|
||||||
hqOptions,
|
|
||||||
'label',
|
|
||||||
);
|
|
||||||
|
|
||||||
const brOptions = ref<Record<string, unknown>[]>([]);
|
|
||||||
let brFilter = selectFilterOptionRefMod(
|
|
||||||
ref(userStore.userOption.brOpts),
|
|
||||||
brOptions,
|
|
||||||
'label',
|
|
||||||
);
|
|
||||||
|
|
||||||
const userTypeOptions = ref<Record<string, unknown>[]>([]);
|
const userTypeOptions = ref<Record<string, unknown>[]>([]);
|
||||||
const userTypeFilter = selectFilterOptionRefMod(
|
const userTypeFilter = selectFilterOptionRefMod(
|
||||||
ref(
|
ref(
|
||||||
|
|
@ -71,35 +43,6 @@ const roleFilter = selectFilterOptionRefMod(
|
||||||
roleOptions,
|
roleOptions,
|
||||||
'label',
|
'label',
|
||||||
);
|
);
|
||||||
|
|
||||||
onMounted(async () => {
|
|
||||||
if (userStore.userOption.hqOpts[0].value && !props.readonly) {
|
|
||||||
await userStore.fetchBrOption(userStore.userOption.hqOpts[0].value);
|
|
||||||
if (userStore.userOption.brOpts.length === 1) {
|
|
||||||
brId.value = userStore.userOption.brOpts[0].value;
|
|
||||||
}
|
|
||||||
brFilter = selectFilterOptionRefMod(
|
|
||||||
ref(userStore.userOption.brOpts),
|
|
||||||
brOptions,
|
|
||||||
'label',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
watch(
|
|
||||||
() => hqId.value,
|
|
||||||
async (v) => {
|
|
||||||
if (v) {
|
|
||||||
userStore.userOption.brOpts = [];
|
|
||||||
await userStore.fetchBrOption(v);
|
|
||||||
brFilter = selectFilterOptionRefMod(
|
|
||||||
ref(userStore.userOption.brOpts),
|
|
||||||
brOptions,
|
|
||||||
'label',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<div class="row col-12">
|
<div class="row col-12">
|
||||||
|
|
@ -116,83 +59,35 @@ watch(
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-12 row q-col-gutter-sm">
|
<div class="col-12 row q-col-gutter-sm">
|
||||||
<q-select
|
<SelectBranch
|
||||||
outlined
|
id="select-hq-id"
|
||||||
clearable
|
|
||||||
use-input
|
|
||||||
fill-input
|
|
||||||
emit-value
|
|
||||||
map-options
|
|
||||||
hide-selected
|
|
||||||
hide-bottom-space
|
|
||||||
:disable="isRoleInclude(['branch_manager']) && !readonly"
|
|
||||||
v-model="hqId"
|
|
||||||
for="select-hq-id"
|
|
||||||
autocomplete="off"
|
|
||||||
input-debounce="0"
|
|
||||||
option-label="label"
|
|
||||||
option-value="value"
|
|
||||||
class="col-md-2 col-12"
|
class="col-md-2 col-12"
|
||||||
:dense="dense"
|
:readonly
|
||||||
:readonly="readonly"
|
:disabled="isRoleInclude(['branch_manager']) && !readonly"
|
||||||
:hide-dropdown-icon="readonly"
|
:params="{
|
||||||
|
filter: 'head',
|
||||||
|
}"
|
||||||
:label="$t('branch.form.code')"
|
:label="$t('branch.form.code')"
|
||||||
:options="hqOptions"
|
code-only
|
||||||
:rules="[
|
|
||||||
(val: string) =>
|
|
||||||
!!val ||
|
|
||||||
$t('form.error.selectField', { field: $t('branch.form.code') }),
|
|
||||||
]"
|
|
||||||
@update:model-value="(val: string) => selectHq(val)"
|
|
||||||
@filter="hqFilter"
|
|
||||||
@clear="
|
|
||||||
() => {
|
|
||||||
(hqId = ''), (brId = '');
|
|
||||||
}
|
|
||||||
"
|
|
||||||
>
|
|
||||||
<template v-slot:no-option>
|
|
||||||
<q-item>
|
|
||||||
<q-item-section class="text-grey">
|
|
||||||
{{ $t('general.noData') }}
|
|
||||||
</q-item-section>
|
|
||||||
</q-item>
|
|
||||||
</template>
|
|
||||||
</q-select>
|
|
||||||
<q-select
|
|
||||||
outlined
|
|
||||||
clearable
|
clearable
|
||||||
use-input
|
v-model:value="hqId"
|
||||||
fill-input
|
@update:value="() => (brId = '')"
|
||||||
emit-value
|
required
|
||||||
map-options
|
/>
|
||||||
hide-selected
|
<SelectBranch
|
||||||
hide-bottom-space
|
id="select-br-id"
|
||||||
for="select-br-id"
|
|
||||||
autocomplete="off"
|
|
||||||
input-debounce="0"
|
|
||||||
option-label="label"
|
|
||||||
option-value="value"
|
|
||||||
class="col-md-2 col-12"
|
class="col-md-2 col-12"
|
||||||
:disable="isRoleInclude(['branch_manager']) && !readonly"
|
:key="hqId ?? undefined"
|
||||||
:dense="dense"
|
:readonly
|
||||||
:readonly="readonly"
|
:disabled="(isRoleInclude(['branch_manager']) && !readonly) || !hqId"
|
||||||
:hide-dropdown-icon="readonly"
|
:params="{
|
||||||
|
headOfficeId: hqId ?? undefined,
|
||||||
|
}"
|
||||||
:label="$t('branch.form.codeBranch')"
|
:label="$t('branch.form.codeBranch')"
|
||||||
:options="brOptions"
|
code-only
|
||||||
@filter="brFilter"
|
clearable
|
||||||
:model-value="readonly ? brId || '-' : brId"
|
v-model:value="brId"
|
||||||
@update:model-value="(v) => (typeof v === 'string' ? (brId = v) : '')"
|
/>
|
||||||
@clear="brId = ''"
|
|
||||||
>
|
|
||||||
<template v-slot:no-option>
|
|
||||||
<q-item>
|
|
||||||
<q-item-section class="text-grey">
|
|
||||||
{{ $t('general.noData') }}
|
|
||||||
</q-item-section>
|
|
||||||
</q-item>
|
|
||||||
</template>
|
|
||||||
</q-select>
|
|
||||||
<q-input
|
<q-input
|
||||||
for="input-username"
|
for="input-username"
|
||||||
:dense="dense"
|
:dense="dense"
|
||||||
|
|
|
||||||
|
|
@ -98,8 +98,8 @@ function setDefaultValue() {
|
||||||
return ret;
|
return ret;
|
||||||
})
|
})
|
||||||
"
|
"
|
||||||
:hide-selected="false"
|
hide-selected
|
||||||
:fill-input="false"
|
fill-input
|
||||||
:rules="[
|
:rules="[
|
||||||
(v: string) =>
|
(v: string) =>
|
||||||
checkRole?.some((v) => getRole()?.includes(v)) ||
|
checkRole?.some((v) => getRole()?.includes(v)) ||
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,7 @@ const useBranchStore = defineStore('api-branch', () => {
|
||||||
filter?: 'head' | 'sub';
|
filter?: 'head' | 'sub';
|
||||||
withHead?: boolean;
|
withHead?: boolean;
|
||||||
activeOnly?: boolean;
|
activeOnly?: boolean;
|
||||||
|
headOfficeId?: string;
|
||||||
},
|
},
|
||||||
Data extends Pagination<Branch[]>,
|
Data extends Pagination<Branch[]>,
|
||||||
>(opts?: Options): Promise<Data | false> {
|
>(opts?: Options): Promise<Data | false> {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue