feat: i18n, edit branch

This commit is contained in:
puriphatt 2024-04-22 10:54:32 +07:00
parent 82d3c893f2
commit 4bd2a08cb5

View file

@ -198,6 +198,7 @@ async function openDialog(action?: 'FORM' | 'INFO', idEdit?: string) {
} }
if (idEdit && userData.value) { if (idEdit && userData.value) {
isEdit.value = true;
assignFormData(idEdit); assignFormData(idEdit);
if (formData.value.userType === 'AGENCY') { if (formData.value.userType === 'AGENCY') {
@ -239,7 +240,7 @@ async function onSubmit() {
formData.value.profileImage = null; formData.value.profileImage = null;
} }
if (isEdit.value === true && userId.value) { if (isEdit.value && userId.value) {
dialog({ dialog({
color: 'primary', color: 'primary',
icon: 'mdi-pencil-outline', icon: 'mdi-pencil-outline',
@ -262,7 +263,10 @@ async function onSubmit() {
hqId.value !== currentUser.value.branch[0].id && hqId.value !== currentUser.value.branch[0].id &&
brId.value !== currentUser.value.branch[0].id brId.value !== currentUser.value.branch[0].id
) { ) {
userStore.removeBranch(userId.value, currentUser.value.branch[0].id); await branchStore.removeUser(
currentUser.value.branch[0].id,
userId.value,
);
await branchStore.addUser( await branchStore.addUser(
!!brId.value ? brId.value : hqId.value, !!brId.value ? brId.value : hqId.value,
@ -270,6 +274,15 @@ async function onSubmit() {
); );
} }
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 = {
@ -433,17 +446,21 @@ async function assignFormData(idEdit: string) {
? (statusToggle.value = true) ? (statusToggle.value = true)
: (statusToggle.value = false); : (statusToggle.value = false);
userId.value = foundUser.id; userId.value = foundUser.id;
if (foundUser.branch[0].isHeadOffice) {
hqId.value = foundUser.branch[0].id as string; if (foundUser.branch[0]) {
} else { if (foundUser.branch[0].isHeadOffice) {
hqId.value = foundUser.branch[0].headOfficeId as string; hqId.value = foundUser.branch[0].id as string;
brId.value = foundUser.branch[0].id; } else {
hqId.value = foundUser.branch[0].headOfficeId as string;
brId.value = foundUser.branch[0].id;
}
} }
code.value = foundUser.code; code.value = foundUser.code;
urlProfile.value = foundUser.profileImageUrl; urlProfile.value = foundUser.profileImageUrl;
isEdit.value = true; isEdit.value = true;
profileSubmit.value = true; profileSubmit.value = true;
await userStore.fetchBrOption(hqId.value); hqId.value && (await userStore.fetchBrOption(hqId.value));
if (formData.value.districtId) { if (formData.value.districtId) {
await adrressStore.fetchSubDistrictByProvinceId( await adrressStore.fetchSubDistrictByProvinceId(
formData.value.districtId, formData.value.districtId,
@ -538,9 +555,10 @@ watch(
{{ selectorLabel === '' ? '' : $t(selectorLabel) }} {{ selectorLabel === '' ? '' : $t(selectorLabel) }}
</div> </div>
<q-btn <q-btn
id="btn-add-personnel"
dense dense
unelevated unelevated
label="+ เพิ่มบุคลากร" :label="'+ ' + $t('personnelAdd')"
padding="4px 16px" padding="4px 16px"
@click="openDialog('FORM')" @click="openDialog('FORM')"
style="background-color: var(--cyan-6); color: white" style="background-color: var(--cyan-6); color: white"
@ -566,6 +584,7 @@ watch(
<AppBox bordered class="column" style="width: 100%; min-height: 70vh"> <AppBox bordered class="column" style="width: 100%; min-height: 70vh">
<div class="row q-mb-md justify-between"> <div class="row q-mb-md justify-between">
<q-btn <q-btn
id="btn-filter"
icon="mdi-tune-vertical-variant" icon="mdi-tune-vertical-variant"
size="sm" size="sm"
class="bordered rounded" class="bordered rounded"
@ -609,7 +628,7 @@ watch(
style="width: 250px" style="width: 250px"
outlined outlined
dense dense
label="ค้นหา" :label="$t('search')"
debounce="500" debounce="500"
v-model="inputSearch" v-model="inputSearch"
></q-input> ></q-input>
@ -639,10 +658,10 @@ watch(
male: v.gender === 'male', male: v.gender === 'male',
female: v.gender === 'female', female: v.gender === 'female',
detail: [ detail: [
{ label: 'ประเภท', value: $t(v.userType) }, { label: $t('personnelCardUserType'), value: $t(v.userType) },
{ label: 'โทรศัพท์', value: v.telephoneNo }, { label: $t('personnelCardTelephone'), value: v.telephoneNo },
{ {
label: 'อายุ', label: $t('personnelCardAge'),
value: userStore.calculateAge(v.birthDate as Date), value: userStore.calculateAge(v.birthDate as Date),
}, },
], ],
@ -697,6 +716,8 @@ watch(
> >
<template #info> <template #info>
<InfoForm <InfoForm
:addressTitle="$t('formDialogTitleAddressPure')"
:addressTitleEN="$t('formDialogTitleAddressPure') + ' ENG'"
:readonly="!infoPersonCardEdit" :readonly="!infoPersonCardEdit"
v-model:address="formData.address" v-model:address="formData.address"
v-model:addressEN="formData.addressEN" v-model:addressEN="formData.addressEN"
@ -780,9 +801,9 @@ watch(
<FormDialog <FormDialog
removeDialog removeDialog
ref="formDialogRef" ref="formDialogRef"
title="เพิ่มบุคลากร" :title="$t('personnelAdd')"
addressTitle="ที่อยู่พนักงาน" :addressTitle="$t('formDialogTitleAddressPure')"
addressENTitle="ที่อยู่พนักงาน ENG" :addressTitleEN="$t('formDialogTitleAddressPure') + ' ENG'"
v-model:modal="modal" v-model:modal="modal"
v-model:address="formData.address" v-model:address="formData.address"
v-model:addressEN="formData.addressEN" v-model:addressEN="formData.addressEN"
@ -815,28 +836,31 @@ watch(
> >
<div class="col-6"> <div class="col-6">
<q-btn <q-btn
id="btn-profile-cancel"
dense dense
unelevated unelevated
outlined outlined
padding="8px" padding="8px"
class="cancel-img-btn full-width" class="cancel-img-btn full-width"
label="ยกเลิก" :label="$t('cancel')"
@click="urlProfile = ''" @click="urlProfile = ''"
/> />
</div> </div>
<div class="col-6"> <div class="col-6">
<q-btn <q-btn
id="btn-profile-save"
dense dense
unelevated unelevated
outlined outlined
padding="8px" padding="8px"
class="submit-img-btn full-width" class="submit-img-btn full-width"
label="บันทึก" :label="$t('save')"
@click="profileSubmit = true" @click="profileSubmit = true"
/> />
</div> </div>
</div> </div>
<q-btn <q-btn
id="btn-profile-edit"
v-else-if="urlProfile && profileSubmit" v-else-if="urlProfile && profileSubmit"
dense dense
unelevated unelevated
@ -844,18 +868,19 @@ watch(
padding="8px" padding="8px"
icon="mdi-pencil-outline" icon="mdi-pencil-outline"
class="edit-img-btn q-mt-md full-width" class="edit-img-btn q-mt-md full-width"
label="แก้ไขโปรไฟล์" :label="$t('formDialogBtnEditProfile')"
@click.prevent="inputFile.click(), (profileSubmit = false)" @click.prevent="inputFile.click(), (profileSubmit = false)"
/> />
<q-btn <q-btn
id="btn-profile-upload"
v-else v-else
dense dense
unelevated unelevated
outlined outlined
padding="8px" padding="8px"
class="upload-img-btn q-mt-md full-width" class="upload-img-btn q-mt-md full-width"
label="อัปโหลดรูปภาพ" :label="$t('formDialogBtnUploadProfile')"
:class="{ dark: $q.dark.isActive }" :class="{ dark: $q.dark.isActive }"
@click="inputFile.click()" @click="inputFile.click()"
/> />
@ -868,7 +893,7 @@ watch(
padding="none" padding="none"
class="q-pr-md" class="q-pr-md"
/> />
<span>สถานะผใชงาน</span> <span>{{ $t('formDialogTitleUserStatus') }}</span>
</div> </div>
</div> </div>
</template> </template>