fix: personnel branchId (add & edit)
This commit is contained in:
parent
05d7c70f97
commit
0c2926bb60
3 changed files with 32 additions and 54 deletions
|
|
@ -10,6 +10,7 @@ const props = withDefaults(
|
||||||
}[];
|
}[];
|
||||||
dark?: boolean;
|
dark?: boolean;
|
||||||
labelI18n?: boolean;
|
labelI18n?: boolean;
|
||||||
|
nowrap?: boolean;
|
||||||
}>(),
|
}>(),
|
||||||
{
|
{
|
||||||
labelI18n: false,
|
labelI18n: false,
|
||||||
|
|
@ -19,14 +20,14 @@ const props = withDefaults(
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div
|
<div
|
||||||
class="stat-card"
|
class="row full-width"
|
||||||
style="gap: var(--size-4)"
|
style="gap: var(--size-4)"
|
||||||
:class="{ 'justify-between': $q.screen.lt.md, dark }"
|
:class="{ 'justify-between': $q.screen.lt.md, dark, 'no-wrap': nowrap }"
|
||||||
>
|
>
|
||||||
<AppBox
|
<AppBox
|
||||||
v-for="v in props.branch"
|
v-for="v in props.branch"
|
||||||
:key="v.label"
|
:key="v.label"
|
||||||
class="bordered stat-card__wave col-12"
|
class="bordered stat-card__wave"
|
||||||
:class="{ [`stat-card__${v.color}`]: true }"
|
:class="{ [`stat-card__${v.color}`]: true }"
|
||||||
style="
|
style="
|
||||||
padding: 12px 16px;
|
padding: 12px 16px;
|
||||||
|
|
|
||||||
|
|
@ -102,6 +102,7 @@ const typeStats = ref<UserTypeStats>();
|
||||||
const agencyFile = ref<File[]>([]);
|
const agencyFile = ref<File[]>([]);
|
||||||
const agencyFileList = ref<{ name: string; url: string }[]>([]);
|
const agencyFileList = ref<{ name: string; url: string }[]>([]);
|
||||||
const formData = ref<UserCreate>({
|
const formData = ref<UserCreate>({
|
||||||
|
branchId: '',
|
||||||
provinceId: null,
|
provinceId: null,
|
||||||
districtId: null,
|
districtId: null,
|
||||||
subDistrictId: null,
|
subDistrictId: null,
|
||||||
|
|
@ -256,38 +257,18 @@ async function onSubmit() {
|
||||||
if (isEdit.value && userId.value) {
|
if (isEdit.value && userId.value) {
|
||||||
if (!userId.value) return;
|
if (!userId.value) return;
|
||||||
|
|
||||||
|
formData.value.branchId = brId.value
|
||||||
|
? brId.value
|
||||||
|
: hqId.value
|
||||||
|
? hqId.value
|
||||||
|
: '';
|
||||||
const formDataEdit = {
|
const formDataEdit = {
|
||||||
...formData.value,
|
...formData.value,
|
||||||
status: !statusToggle.value ? 'INACTIVE' : 'ACTIVE',
|
status: !statusToggle.value ? 'INACTIVE' : 'ACTIVE',
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
await userStore.editById(userId.value, formDataEdit);
|
await userStore.editById(userId.value, formDataEdit);
|
||||||
|
|
||||||
if (
|
|
||||||
hqId.value &&
|
|
||||||
currentUser.value?.branch[0] &&
|
|
||||||
hqId.value !== currentUser.value.branch[0].id &&
|
|
||||||
brId.value !== currentUser.value.branch[0].id
|
|
||||||
) {
|
|
||||||
await branchStore.removeUser(
|
|
||||||
currentUser.value.branch[0].id,
|
|
||||||
userId.value,
|
|
||||||
);
|
|
||||||
|
|
||||||
await branchStore.addUser(
|
|
||||||
!!brId.value ? brId.value : hqId.value,
|
|
||||||
userId.value,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!currentUser.value?.branch[0]) {
|
|
||||||
if (brId.value || hqId.value) {
|
|
||||||
await branchStore.addUser(
|
|
||||||
(!!brId.value ? brId.value : hqId.value)!,
|
|
||||||
userId.value,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (userId.value && formDataEdit.userType === 'AGENCY') {
|
if (userId.value && formDataEdit.userType === 'AGENCY') {
|
||||||
if (!agencyFile.value) return;
|
if (!agencyFile.value) return;
|
||||||
const payload: UserAttachmentCreate = {
|
const payload: UserAttachmentCreate = {
|
||||||
|
|
@ -313,13 +294,13 @@ async function onSubmit() {
|
||||||
? (formData.value.status = 'CREATED')
|
? (formData.value.status = 'CREATED')
|
||||||
: (formData.value.status = 'INACTIVE');
|
: (formData.value.status = 'INACTIVE');
|
||||||
|
|
||||||
|
formData.value.branchId = brId.value
|
||||||
|
? brId.value
|
||||||
|
: hqId.value
|
||||||
|
? hqId.value
|
||||||
|
: '';
|
||||||
|
|
||||||
const result = await userStore.create(formData.value);
|
const result = await userStore.create(formData.value);
|
||||||
if (result) {
|
|
||||||
await branchStore.addUser(
|
|
||||||
!!brId.value ? brId.value : hqId.value,
|
|
||||||
result.id,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result && formData.value.userType === 'AGENCY') {
|
if (result && formData.value.userType === 'AGENCY') {
|
||||||
if (!agencyFile.value) return;
|
if (!agencyFile.value) return;
|
||||||
|
|
@ -395,6 +376,7 @@ async function assignFormData(idEdit: string) {
|
||||||
infoPersonId.value = currentUser.value.id;
|
infoPersonId.value = currentUser.value.id;
|
||||||
|
|
||||||
formData.value = {
|
formData.value = {
|
||||||
|
branchId: foundUser.branch[0].id,
|
||||||
provinceId: foundUser.provinceId,
|
provinceId: foundUser.provinceId,
|
||||||
districtId: foundUser.districtId,
|
districtId: foundUser.districtId,
|
||||||
subDistrictId: foundUser.subDistrictId,
|
subDistrictId: foundUser.subDistrictId,
|
||||||
|
|
@ -552,27 +534,20 @@ watch(inputSearch, async () => await fetchUserList());
|
||||||
</ButtonAddComponent>
|
</ButtonAddComponent>
|
||||||
|
|
||||||
<div class="column full-height">
|
<div class="column full-height">
|
||||||
<!-- <div class="text-h6 text-weight-bold q-mb-md">
|
<div class="row full-width q-pb-md q-gutter-y-md">
|
||||||
{{ $t('personnelManagement') }}
|
|
||||||
</div> -->
|
|
||||||
|
|
||||||
<div class="row full-width no-wrap q-pb-md">
|
|
||||||
<!-- selector -->
|
<!-- selector -->
|
||||||
<SelectorList
|
<div class="col-sm-5 col-md-3 col-12 q-mr-md">
|
||||||
:list="selectorList"
|
<SelectorList :list="selectorList" v-model:selector="selectorLabel" />
|
||||||
v-model:selector="selectorLabel"
|
</div>
|
||||||
class="q-mr-md col-3"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<!-- stat -->
|
<!-- stat -->
|
||||||
<AppBox bordered class="column full-width">
|
<div class="col-12 col-sm bordered surface-1 rounded">
|
||||||
<div class="row q-pb-sm justify-between items-center">
|
<div class="text-weight-bold text-subtitle1 q-pa-md">
|
||||||
<div class="text-weight-bold text-subtitle1">
|
{{ $t('personnelStatTitle') }}
|
||||||
{{ $t('personnelStatTitle') }}
|
{{ selectorLabel === '' ? '' : $t(selectorLabel) }}
|
||||||
{{ selectorLabel === '' ? '' : $t(selectorLabel) }}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="row full-width" style="overflow-x: auto">
|
|
||||||
|
<div class="q-px-md scroll">
|
||||||
<StatCardComponent
|
<StatCardComponent
|
||||||
v-if="sortedUserStats"
|
v-if="sortedUserStats"
|
||||||
:branch="
|
:branch="
|
||||||
|
|
@ -583,10 +558,11 @@ watch(inputSearch, async () => await fetchUserList());
|
||||||
}))
|
}))
|
||||||
"
|
"
|
||||||
:dark="$q.dark.isActive"
|
:dark="$q.dark.isActive"
|
||||||
class="no-wrap"
|
nowrap
|
||||||
|
class="q-mb-md"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</AppBox>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- main -->
|
<!-- main -->
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,7 @@ export type User = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export type UserCreate = {
|
export type UserCreate = {
|
||||||
|
branchId: string;
|
||||||
provinceId?: string | null;
|
provinceId?: string | null;
|
||||||
districtId?: string | null;
|
districtId?: string | null;
|
||||||
subDistrictId?: string | null;
|
subDistrictId?: string | null;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue