refactor: add Function edit Personal
This commit is contained in:
parent
54e330a4cf
commit
287d73a1a5
2 changed files with 103 additions and 30 deletions
|
|
@ -371,9 +371,10 @@ export const useEmployeeForm = defineStore('form-employee', () => {
|
|||
profileSubmit: boolean;
|
||||
formDataEmployeeSameAddr: boolean;
|
||||
editReadonly: boolean;
|
||||
statusSavePersonal: boolean;
|
||||
infoEmployeePersonCard: {
|
||||
id: string;
|
||||
img: string;
|
||||
img?: string;
|
||||
name: string;
|
||||
male: boolean;
|
||||
female: boolean;
|
||||
|
|
@ -392,6 +393,7 @@ export const useEmployeeForm = defineStore('form-employee', () => {
|
|||
}
|
||||
| undefined;
|
||||
}>({
|
||||
statusSavePersonal: false,
|
||||
drawerModal: false,
|
||||
imageDialog: false,
|
||||
currentTab: 'personalInfo',
|
||||
|
|
@ -491,7 +493,7 @@ export const useEmployeeForm = defineStore('form-employee', () => {
|
|||
},
|
||||
};
|
||||
|
||||
const resetEmployeeData = structuredClone(defaultFormData);
|
||||
let resetEmployeeData = structuredClone(defaultFormData);
|
||||
const currentFromDataEmployee = ref<EmployeeCreate>(
|
||||
structuredClone(defaultFormData),
|
||||
);
|
||||
|
|
@ -503,10 +505,20 @@ export const useEmployeeForm = defineStore('form-employee', () => {
|
|||
);
|
||||
}
|
||||
|
||||
function resetFormDataEmployee(cb?: (...args: any[]) => unknown) {
|
||||
state.value.dialogType = 'create';
|
||||
// function resetFormDataEmployee(cb?: (...args: any[]) => unknown) {
|
||||
// state.value.dialogType = 'create';
|
||||
// currentFromDataEmployee.value = structuredClone(resetEmployeeData);
|
||||
// cb?.();
|
||||
// }
|
||||
|
||||
function resetFormDataEmployee(clean = false) {
|
||||
if (clean) {
|
||||
state.value.formDataEmployeeOwner = undefined;
|
||||
resetEmployeeData = structuredClone(defaultFormData);
|
||||
state.value.statusSavePersonal = false;
|
||||
return;
|
||||
}
|
||||
currentFromDataEmployee.value = structuredClone(resetEmployeeData);
|
||||
cb?.();
|
||||
}
|
||||
|
||||
async function submitPersonal() {
|
||||
|
|
@ -519,28 +531,61 @@ export const useEmployeeForm = defineStore('form-employee', () => {
|
|||
employeeCheckup: [],
|
||||
employeeOtherInfo: undefined,
|
||||
});
|
||||
if (res) {
|
||||
await assignFormDataEmployee(res.id);
|
||||
state.value.statusSavePersonal = true;
|
||||
}
|
||||
}
|
||||
if (state.value.dialogType === 'edit') {
|
||||
const res = await employeeStore.editById(
|
||||
state.value.currentEmployee?.id || '',
|
||||
{
|
||||
...currentFromDataEmployee.value,
|
||||
status:
|
||||
state.value.currentEmployee?.status === 'CREATED'
|
||||
? 'ACTIVE'
|
||||
: state.value.currentEmployee?.status,
|
||||
customerBranchId: state.value.formDataEmployeeOwner?.id || '',
|
||||
employeeWork: [],
|
||||
employeeCheckup: [],
|
||||
employeeOtherInfo: undefined,
|
||||
},
|
||||
);
|
||||
if (res) {
|
||||
await assignFormDataEmployee(res.id);
|
||||
state.value.statusSavePersonal = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function assignFormDataEmployee(id: string) {
|
||||
async function assignFormDataEmployee(id?: string) {
|
||||
if (!id) {
|
||||
resetEmployeeData = structuredClone(defaultFormData);
|
||||
return;
|
||||
}
|
||||
|
||||
const res = await employeeStore.fetchById(id);
|
||||
|
||||
if (res) {
|
||||
state.value.currentEmployee = res;
|
||||
|
||||
const {
|
||||
createdAt,
|
||||
createdByUserId,
|
||||
statusOrder,
|
||||
id,
|
||||
province,
|
||||
district,
|
||||
subDistrict,
|
||||
updatedAt,
|
||||
updatedByUserId,
|
||||
createdBy,
|
||||
updatedBy,
|
||||
profileImageUrl,
|
||||
...playlond
|
||||
} = res;
|
||||
|
||||
currentFromDataEmployee.value = {
|
||||
resetEmployeeData = {
|
||||
...playlond,
|
||||
provinceId: province?.id,
|
||||
districtId: district?.id,
|
||||
|
|
@ -551,13 +596,15 @@ export const useEmployeeForm = defineStore('form-employee', () => {
|
|||
image: null,
|
||||
};
|
||||
|
||||
currentFromDataEmployee.value = structuredClone(resetEmployeeData);
|
||||
|
||||
const foundBranch = await customerStore.fetchListCustomeBranchById(
|
||||
playlond.customerBranchId,
|
||||
);
|
||||
|
||||
state.value.currentEmployeeCode = playlond.code;
|
||||
|
||||
state.value.profileUrl = profileImageUrl || '';
|
||||
state.value.profileUrl = profileImageUrl || ' ';
|
||||
|
||||
profileImageUrl
|
||||
? (state.value.profileSubmit = true)
|
||||
|
|
@ -573,10 +620,9 @@ export const useEmployeeForm = defineStore('form-employee', () => {
|
|||
state.value.formDataEmployeeSameAddr = false;
|
||||
}
|
||||
|
||||
if (state.value.infoEmployeePersonCard) {
|
||||
state.value.infoEmployeePersonCard[0].img = profileImageUrl || '';
|
||||
if (state.value.infoEmployeePersonCard && profileImageUrl !== null) {
|
||||
state.value.infoEmployeePersonCard[0].img = profileImageUrl;
|
||||
}
|
||||
|
||||
flowStore.rotate();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue