refactor: personnel main
This commit is contained in:
parent
f269e4ac5d
commit
89110f54c7
1 changed files with 82 additions and 43 deletions
|
|
@ -42,7 +42,7 @@ const defaultFormData = {
|
||||||
licenseExpireDate: null,
|
licenseExpireDate: null,
|
||||||
licenseIssueDate: null,
|
licenseIssueDate: null,
|
||||||
licenseNo: null,
|
licenseNo: null,
|
||||||
discountCondition: '',
|
discountCondition: null,
|
||||||
retireDate: null,
|
retireDate: null,
|
||||||
startDate: null,
|
startDate: null,
|
||||||
registrationNo: null,
|
registrationNo: null,
|
||||||
|
|
@ -54,9 +54,11 @@ const defaultFormData = {
|
||||||
userType: '',
|
userType: '',
|
||||||
profileImage: null,
|
profileImage: null,
|
||||||
birthDate: null,
|
birthDate: null,
|
||||||
responsibleArea: '',
|
responsibleArea: null,
|
||||||
|
username: '',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const profileSubmit = ref(false);
|
||||||
const urlProfile = ref<string>();
|
const urlProfile = ref<string>();
|
||||||
const isEdit = ref(false);
|
const isEdit = ref(false);
|
||||||
const modal = ref(false);
|
const modal = ref(false);
|
||||||
|
|
@ -65,7 +67,6 @@ const userId = ref('');
|
||||||
const selectorLabel = ref('');
|
const selectorLabel = ref('');
|
||||||
const hqId = ref('');
|
const hqId = ref('');
|
||||||
const brId = ref('');
|
const brId = ref('');
|
||||||
const username = ref('');
|
|
||||||
const code = ref('');
|
const code = ref('');
|
||||||
const formDialogRef = ref();
|
const formDialogRef = ref();
|
||||||
const userStats = ref<BranchUserStats[]>();
|
const userStats = ref<BranchUserStats[]>();
|
||||||
|
|
@ -98,7 +99,10 @@ const formData = ref<UserCreate>({
|
||||||
userType: '',
|
userType: '',
|
||||||
profileImage: null,
|
profileImage: null,
|
||||||
birthDate: null,
|
birthDate: null,
|
||||||
responsibleArea: '',
|
responsibleArea: null,
|
||||||
|
checkpoint: null,
|
||||||
|
checkpointEN: null,
|
||||||
|
username: '',
|
||||||
});
|
});
|
||||||
|
|
||||||
const profileFile = ref<File | undefined>(undefined);
|
const profileFile = ref<File | undefined>(undefined);
|
||||||
|
|
@ -131,6 +135,7 @@ const selectorList = computed(() => [
|
||||||
|
|
||||||
async function openDialog(idEdit?: string) {
|
async function openDialog(idEdit?: string) {
|
||||||
modal.value = true;
|
modal.value = true;
|
||||||
|
profileSubmit.value = false;
|
||||||
userStore.userOption.brOpts = [];
|
userStore.userOption.brOpts = [];
|
||||||
|
|
||||||
userStore.userOption.hqOpts.length === 0
|
userStore.userOption.hqOpts.length === 0
|
||||||
|
|
@ -166,6 +171,7 @@ async function openDialog(idEdit?: string) {
|
||||||
firstName: foundUser.firstName,
|
firstName: foundUser.firstName,
|
||||||
userRole: foundUser.userRole,
|
userRole: foundUser.userRole,
|
||||||
userType: foundUser.userType,
|
userType: foundUser.userType,
|
||||||
|
username: foundUser.username,
|
||||||
responsibleArea: foundUser.responsibleArea,
|
responsibleArea: foundUser.responsibleArea,
|
||||||
licenseExpireDate:
|
licenseExpireDate:
|
||||||
(foundUser.licenseExpireDate &&
|
(foundUser.licenseExpireDate &&
|
||||||
|
|
@ -192,9 +198,10 @@ async function openDialog(idEdit?: string) {
|
||||||
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;
|
||||||
await userStore.fetchBrOption(hqId.value);
|
await userStore.fetchBrOption(hqId.value);
|
||||||
await formDialogRef.value.fetchSubDistrict(formData.value.districtId);
|
// await formDialogRef.value.fetchSubDistrict(formData.value.districtId);
|
||||||
await formDialogRef.value.fetchDistrict(formData.value.provinceId);
|
// await formDialogRef.value.fetchDistrict(formData.value.provinceId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -204,13 +211,13 @@ function onClose() {
|
||||||
hqId.value = '';
|
hqId.value = '';
|
||||||
brId.value = '';
|
brId.value = '';
|
||||||
userId.value = '';
|
userId.value = '';
|
||||||
username.value = '';
|
|
||||||
urlProfile.value = '';
|
urlProfile.value = '';
|
||||||
|
profileSubmit.value = false;
|
||||||
modal.value = false;
|
modal.value = false;
|
||||||
status.value = false;
|
status.value = false;
|
||||||
isEdit.value = false;
|
isEdit.value = false;
|
||||||
mapUserType(selectorLabel.value);
|
|
||||||
Object.assign(formData.value, defaultFormData);
|
Object.assign(formData.value, defaultFormData);
|
||||||
|
mapUserType(selectorLabel.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function onSubmit() {
|
async function onSubmit() {
|
||||||
|
|
@ -270,15 +277,14 @@ function cardClick(id: string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function mapUserType(label: string) {
|
function mapUserType(label: string) {
|
||||||
if (label === 'personnelSelector1') {
|
const userTypeMap: { [key: string]: string } = {
|
||||||
formData.value.userType = 'USER';
|
USER: 'USER',
|
||||||
} else if (label === 'personnelSelector2') {
|
MESSENGER: 'MESSENGER',
|
||||||
formData.value.userType = 'MESSENGER';
|
DELEGATE: 'DELEGATE',
|
||||||
} else if (label === 'personnelSelector3') {
|
AGENCY: 'AGENCY',
|
||||||
formData.value.userType = 'DELEGATE';
|
};
|
||||||
} else if (label === 'personnelSelector4') {
|
|
||||||
formData.value.userType = 'AGENCY';
|
formData.value.userType = userTypeMap[label];
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
|
|
@ -377,14 +383,6 @@ watch(
|
||||||
female: v.gender === 'female',
|
female: v.gender === 'female',
|
||||||
detail: [
|
detail: [
|
||||||
{ label: 'ประเภท', value: $t(v.userType) },
|
{ label: 'ประเภท', value: $t(v.userType) },
|
||||||
{
|
|
||||||
label: 'ตำแหน่ง',
|
|
||||||
value: v.userRole
|
|
||||||
? userStore.userOption.roleOpts.find(
|
|
||||||
(r) => r.value === v.userRole,
|
|
||||||
)?.label || ''
|
|
||||||
: '',
|
|
||||||
},
|
|
||||||
{ label: 'โทรศัพท์', value: v.telephoneNo },
|
{ label: 'โทรศัพท์', value: v.telephoneNo },
|
||||||
{
|
{
|
||||||
label: 'อายุ',
|
label: 'อายุ',
|
||||||
|
|
@ -427,15 +425,17 @@ watch(
|
||||||
<!-- form -->
|
<!-- form -->
|
||||||
<FormDialog
|
<FormDialog
|
||||||
ref="formDialogRef"
|
ref="formDialogRef"
|
||||||
v-model:formData="formData"
|
|
||||||
v-model:modal="modal"
|
|
||||||
v-model:hqId="hqId"
|
|
||||||
v-model:brId="brId"
|
|
||||||
v-model:username="username"
|
|
||||||
v-model:code="code"
|
|
||||||
title="เพิ่มบุคลากร"
|
title="เพิ่มบุคลากร"
|
||||||
addressTitle="ที่อยู่พนักงาน"
|
addressTitle="ที่อยู่พนักงาน"
|
||||||
addressENTitle="ที่อยู่พนักงาน ENG"
|
addressENTitle="ที่อยู่พนักงาน ENG"
|
||||||
|
v-model:modal="modal"
|
||||||
|
v-model:address="formData.address"
|
||||||
|
v-model:addressEN="formData.addressEN"
|
||||||
|
v-model:provinceId="formData.provinceId"
|
||||||
|
v-model:districtId="formData.districtId"
|
||||||
|
v-model:subDistrictId="formData.subDistrictId"
|
||||||
|
v-model:zipCode="formData.zipCode"
|
||||||
|
:addressSeparator="formData.userType !== ''"
|
||||||
:submit="() => onSubmit()"
|
:submit="() => onSubmit()"
|
||||||
:close="() => onClose()"
|
:close="() => onClose()"
|
||||||
>
|
>
|
||||||
|
|
@ -454,33 +454,61 @@ watch(
|
||||||
style="color: var(--border-color)"
|
style="color: var(--border-color)"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
<div
|
||||||
|
v-if="urlProfile && !profileSubmit"
|
||||||
|
class="col-12 row q-mt-md q-col-gutter-x-md"
|
||||||
|
>
|
||||||
|
<div class="col-6">
|
||||||
|
<q-btn
|
||||||
|
dense
|
||||||
|
unelevated
|
||||||
|
outlined
|
||||||
|
padding="8px"
|
||||||
|
class="cancel-img-btn full-width"
|
||||||
|
label="ยกเลิก"
|
||||||
|
@click="urlProfile = ''"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div class="col-6">
|
||||||
|
<q-btn
|
||||||
|
dense
|
||||||
|
unelevated
|
||||||
|
outlined
|
||||||
|
padding="8px"
|
||||||
|
class="submit-img-btn full-width"
|
||||||
|
label="บันทึก"
|
||||||
|
@click="profileSubmit = true"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<q-btn
|
<q-btn
|
||||||
v-if="urlProfile"
|
v-else-if="urlProfile && profileSubmit"
|
||||||
dense
|
dense
|
||||||
unelevated
|
unelevated
|
||||||
outlined
|
outlined
|
||||||
padding="8px"
|
padding="8px"
|
||||||
icon="mdi-pencil-outline"
|
icon="mdi-pencil-outline"
|
||||||
class="edit-img-btn q-my-md full-width"
|
class="edit-img-btn q-mt-md full-width"
|
||||||
label="แก้ไขโปรไฟล์"
|
label="แก้ไขโปรไฟล์"
|
||||||
@click="inputFile.click()"
|
@click.prevent="inputFile.click(), (profileSubmit = false)"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<q-btn
|
<q-btn
|
||||||
v-else
|
v-else
|
||||||
dense
|
dense
|
||||||
unelevated
|
unelevated
|
||||||
outlined
|
outlined
|
||||||
padding="8px"
|
padding="8px"
|
||||||
class="upload-img-btn q-my-md full-width"
|
class="upload-img-btn q-mt-md full-width"
|
||||||
label="อัปโหลดรูปภาพ"
|
label="อัปโหลดรูปภาพ"
|
||||||
:class="{ dark: $q.dark.isActive }"
|
:class="{ dark: $q.dark.isActive }"
|
||||||
@click="inputFile.click()"
|
@click="inputFile.click()"
|
||||||
/>
|
/>
|
||||||
<div class="text-left">
|
<q-separator class="col-12 q-my-md" />
|
||||||
|
<div class="text-left q-pt-md">
|
||||||
<q-toggle
|
<q-toggle
|
||||||
dense
|
dense
|
||||||
size="md"
|
size="md"
|
||||||
color="primary"
|
|
||||||
v-model="status"
|
v-model="status"
|
||||||
padding="none"
|
padding="none"
|
||||||
class="q-pr-md"
|
class="q-pr-md"
|
||||||
|
|
@ -495,12 +523,12 @@ watch(
|
||||||
dense
|
dense
|
||||||
outlined
|
outlined
|
||||||
separator
|
separator
|
||||||
:addressSeparator="formData.userType"
|
:usernameReadonly="isEdit"
|
||||||
v-model:hqId="hqId"
|
v-model:hqId="hqId"
|
||||||
v-model:brId="brId"
|
v-model:brId="brId"
|
||||||
v-model:userType="formData.userType"
|
v-model:userType="formData.userType"
|
||||||
v-model:userRole="formData.userRole"
|
v-model:userRole="formData.userRole"
|
||||||
v-model:userName="username"
|
v-model:username="formData.username"
|
||||||
v-model:userCode="code"
|
v-model:userCode="code"
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
|
|
@ -538,14 +566,11 @@ watch(
|
||||||
</FormDialog>
|
</FormDialog>
|
||||||
</template>
|
</template>
|
||||||
<style>
|
<style>
|
||||||
.bg-white {
|
|
||||||
background-color: var(--surface-1) !important;
|
|
||||||
}
|
|
||||||
|
|
||||||
.upload-img-preview {
|
.upload-img-preview {
|
||||||
border: 1px solid var(--border-color);
|
border: 1px solid var(--border-color);
|
||||||
border-radius: var(--radius-2);
|
border-radius: var(--radius-2);
|
||||||
height: 12vw;
|
height: 12vw;
|
||||||
|
background-color: var(--surface-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
.upload-img-btn {
|
.upload-img-btn {
|
||||||
|
|
@ -565,4 +590,18 @@ watch(
|
||||||
background-color: transparent;
|
background-color: transparent;
|
||||||
border-radius: var(--radius-2);
|
border-radius: var(--radius-2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.cancel-img-btn {
|
||||||
|
color: hsl(var(--negative-bg));
|
||||||
|
border: 1px solid hsl(var(--negative-bg));
|
||||||
|
background-color: transparent;
|
||||||
|
border-radius: var(--radius-2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.submit-img-btn {
|
||||||
|
color: var(--surface-1);
|
||||||
|
border: 1px solid hsl(var(--positive-bg));
|
||||||
|
background-color: hsl(var(--positive-bg));
|
||||||
|
border-radius: var(--radius-2);
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue