fix: Personnel => confirm dialog & age
This commit is contained in:
parent
f1e258a3e3
commit
ff00043b17
1 changed files with 85 additions and 22 deletions
|
|
@ -4,6 +4,7 @@ import { api } from 'src/boot/axios';
|
||||||
import { storeToRefs } from 'pinia';
|
import { storeToRefs } from 'pinia';
|
||||||
import useUserStore from 'stores/user';
|
import useUserStore from 'stores/user';
|
||||||
import useBranchStore from 'src/stores/branch';
|
import useBranchStore from 'src/stores/branch';
|
||||||
|
import { dialog } from 'src/stores/utils';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
UserCreate,
|
UserCreate,
|
||||||
|
|
@ -54,7 +55,7 @@ const defaultFormData = {
|
||||||
userType: '',
|
userType: '',
|
||||||
keycloakId: '',
|
keycloakId: '',
|
||||||
profileImage: null,
|
profileImage: null,
|
||||||
birthDate: null,
|
birthDate: '',
|
||||||
responsibleArea: '',
|
responsibleArea: '',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -189,12 +190,35 @@ async function openDialog(id?: string) {
|
||||||
await fetchHqOption();
|
await fetchHqOption();
|
||||||
await fetchRoleOption();
|
await fetchRoleOption();
|
||||||
modal.value = true;
|
modal.value = true;
|
||||||
|
age.value = '';
|
||||||
if (id && userData.value) {
|
if (id && userData.value) {
|
||||||
const foundUser = userData.value.result.find((user) => user.id === id);
|
const foundUser = userData.value.result.find((user) => user.id === id);
|
||||||
|
|
||||||
if (foundUser) {
|
if (foundUser) {
|
||||||
formData.value = {
|
formData.value = {
|
||||||
...foundUser,
|
provinceId: foundUser.provinceId,
|
||||||
|
districtId: foundUser.districtId,
|
||||||
|
subDistrictId: foundUser.subDistrictId,
|
||||||
|
telephoneNo: foundUser.telephoneNo,
|
||||||
|
email: foundUser.email,
|
||||||
|
zipCode: foundUser.zipCode,
|
||||||
|
gender: foundUser.gender,
|
||||||
|
addressEN: foundUser.addressEN,
|
||||||
|
address: foundUser.address,
|
||||||
|
trainingPlace: foundUser.trainingPlace,
|
||||||
|
importNationality: foundUser.importNationality,
|
||||||
|
sourceNationality: foundUser.sourceNationality,
|
||||||
|
licenseNo: foundUser.licenseNo,
|
||||||
|
discountCondition: foundUser.discountCondition,
|
||||||
|
registrationNo: foundUser.registrationNo,
|
||||||
|
lastNameEN: foundUser.lastNameEN,
|
||||||
|
lastName: foundUser.lastName,
|
||||||
|
firstNameEN: foundUser.firstNameEN,
|
||||||
|
firstName: foundUser.firstName,
|
||||||
|
userRole: foundUser.userRole,
|
||||||
|
userType: foundUser.userType,
|
||||||
|
keycloakId: foundUser.keycloakId,
|
||||||
|
responsibleArea: foundUser.responsibleArea,
|
||||||
licenseExpireDate:
|
licenseExpireDate:
|
||||||
(foundUser.licenseExpireDate &&
|
(foundUser.licenseExpireDate &&
|
||||||
new Date(foundUser.licenseExpireDate)) ||
|
new Date(foundUser.licenseExpireDate)) ||
|
||||||
|
|
@ -226,8 +250,7 @@ async function openDialog(id?: string) {
|
||||||
|
|
||||||
function onClose() {
|
function onClose() {
|
||||||
modal.value = false;
|
modal.value = false;
|
||||||
Object.assign(formData.value, defaultFormData);
|
age.value = '';
|
||||||
mapUserType(selectorLabel.value);
|
|
||||||
isEdit.value = false;
|
isEdit.value = false;
|
||||||
hqId.value = '';
|
hqId.value = '';
|
||||||
brId.value = '';
|
brId.value = '';
|
||||||
|
|
@ -235,30 +258,65 @@ function onClose() {
|
||||||
userId.value = '';
|
userId.value = '';
|
||||||
code.value = '';
|
code.value = '';
|
||||||
urlProfile.value = '';
|
urlProfile.value = '';
|
||||||
|
Object.assign(formData.value, defaultFormData);
|
||||||
|
mapUserType(selectorLabel.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function onSubmit() {
|
async function onSubmit() {
|
||||||
formData.value.profileImage = profileFile.value as File;
|
formData.value.profileImage = profileFile.value as File;
|
||||||
if (isEdit.value === true && userId.value) {
|
if (isEdit.value === true && userId.value) {
|
||||||
const formDataEdit = { ...formData.value };
|
dialog({
|
||||||
delete formDataEdit.keycloakId;
|
color: 'primary',
|
||||||
await userStore.editById(userId.value, formDataEdit);
|
icon: 'mdi-pencil-outline',
|
||||||
|
title: 'ยืนยันการแก้ไขข้อมูล',
|
||||||
|
actionText: 'ตกลง',
|
||||||
|
persistent: true,
|
||||||
|
message: 'คุณต้องการแก้ไขข้อมูล ใช่หรือไม่',
|
||||||
|
action: async () => {
|
||||||
|
const formDataEdit = { ...formData.value };
|
||||||
|
delete formDataEdit.keycloakId;
|
||||||
|
delete formDataEdit.profileImage;
|
||||||
|
await userStore.editById(userId.value, formDataEdit);
|
||||||
|
onClose();
|
||||||
|
userStore.fetchList({ includeBranch: true });
|
||||||
|
},
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
formData.value.keycloakId = await createKeycloak();
|
dialog({
|
||||||
if (formData.value.keycloakId) {
|
color: 'primary',
|
||||||
const result = await userStore.create(formData.value);
|
icon: 'mdi-account',
|
||||||
if (result) {
|
title: 'ยืนยันการเพิ่มบุคลากร',
|
||||||
await branchStore.addUser(brId.value, result.id);
|
actionText: 'ตกลง',
|
||||||
}
|
persistent: true,
|
||||||
}
|
message: 'คุณต้องการเพิ่มบุคลากร ใช่หรือไม่',
|
||||||
|
action: async () => {
|
||||||
|
formData.value.keycloakId = await createKeycloak();
|
||||||
|
if (formData.value.keycloakId) {
|
||||||
|
const result = await userStore.create(formData.value);
|
||||||
|
if (result) {
|
||||||
|
await branchStore.addUser(brId.value, result.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
onClose();
|
||||||
|
userStore.fetchList({ includeBranch: true });
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
onClose();
|
|
||||||
userStore.fetchList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function onDelete(id: string) {
|
async function onDelete(id: string) {
|
||||||
await userStore.deleteById(id);
|
dialog({
|
||||||
await userStore.fetchList();
|
color: 'negative',
|
||||||
|
icon: 'mdi-trash-can-outline',
|
||||||
|
title: 'ยืนยันการลบข้อมูล',
|
||||||
|
actionText: 'ตกลง',
|
||||||
|
persistent: true,
|
||||||
|
message: 'คุณต้องการลบข้อมูล ใช่หรือไม่',
|
||||||
|
action: async () => {
|
||||||
|
await userStore.deleteById(id);
|
||||||
|
await userStore.fetchList({ includeBranch: true });
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function mapUserType(label: string) {
|
function mapUserType(label: string) {
|
||||||
|
|
@ -273,8 +331,8 @@ function mapUserType(label: string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function calculateAge(birthDate: Date | null) {
|
function calculateAge(birthDate: Date | null): string {
|
||||||
if (!birthDate) return null;
|
if (!birthDate) return '';
|
||||||
const birthDateTimeStamp = new Date(birthDate).getTime();
|
const birthDateTimeStamp = new Date(birthDate).getTime();
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const diff = now.getTime() - birthDateTimeStamp;
|
const diff = now.getTime() - birthDateTimeStamp;
|
||||||
|
|
@ -284,7 +342,8 @@ function calculateAge(birthDate: Date | null) {
|
||||||
const months = ageDate.getUTCMonth();
|
const months = ageDate.getUTCMonth();
|
||||||
const days = ageDate.getUTCDate() - 1;
|
const days = ageDate.getUTCDate() - 1;
|
||||||
|
|
||||||
age.value = `${years} ปี ${months} เดือน ${days} วัน`;
|
age.value = `${years} ปี`;
|
||||||
|
return `${years} ปี`;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function selectHq(id: string) {
|
async function selectHq(id: string) {
|
||||||
|
|
@ -319,6 +378,8 @@ watch(
|
||||||
(birthDate) => {
|
(birthDate) => {
|
||||||
if (birthDate) {
|
if (birthDate) {
|
||||||
calculateAge(birthDate);
|
calculateAge(birthDate);
|
||||||
|
} else {
|
||||||
|
age.value = '';
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
@ -383,6 +444,7 @@ watch(
|
||||||
{ label: 'ตำแหน่ง', value: v.userType },
|
{ label: 'ตำแหน่ง', value: v.userType },
|
||||||
{ label: 'โทรศัพท์', value: v.telephoneNo },
|
{ label: 'โทรศัพท์', value: v.telephoneNo },
|
||||||
{ label: 'อีเมล', value: v.email },
|
{ label: 'อีเมล', value: v.email },
|
||||||
|
{ label: 'อายุ', value: calculateAge(v.birthDate as Date) },
|
||||||
],
|
],
|
||||||
badge: v.code,
|
badge: v.code,
|
||||||
disabled: v.status === 'INACTIVE',
|
disabled: v.status === 'INACTIVE',
|
||||||
|
|
@ -492,8 +554,8 @@ watch(
|
||||||
option-value="value"
|
option-value="value"
|
||||||
v-model="formData.userRole"
|
v-model="formData.userRole"
|
||||||
:options="userOption.roleOpts"
|
:options="userOption.roleOpts"
|
||||||
|
:rules="[(val: string) => !!val || 'กรุณาเลือกสิทธิ์ผู้ใช้งาน']"
|
||||||
/>
|
/>
|
||||||
<!-- :rules="[(val: string) => !!val || 'กรุณาเลือกสิทธิ์ผู้ใช้งาน']" -->
|
|
||||||
<q-input
|
<q-input
|
||||||
dense
|
dense
|
||||||
outlined
|
outlined
|
||||||
|
|
@ -609,6 +671,7 @@ watch(
|
||||||
class="col-3"
|
class="col-3"
|
||||||
label="เบอร์โทร"
|
label="เบอร์โทร"
|
||||||
v-model="formData.telephoneNo"
|
v-model="formData.telephoneNo"
|
||||||
|
mask="##########"
|
||||||
/>
|
/>
|
||||||
<q-select
|
<q-select
|
||||||
dense
|
dense
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue