feat: update emploee store for attachment function

This commit is contained in:
Methapon Metanipat 2024-08-28 09:54:44 +07:00
parent 69d1e1bc72
commit 1b040210b7
3 changed files with 94 additions and 18 deletions

View file

@ -830,10 +830,12 @@ export const useEmployeeForm = defineStore('form-employee', () => {
return;
}
const res = await employeeStore.fetchById(id);
const _data = await employeeStore.fetchById(id);
if (res) {
state.value.currentEmployee = res;
if (_data) {
const _attach = await employeeStore.listAttachment(_data.id);
state.value.currentEmployee = _data;
const {
createdAt,
@ -847,48 +849,59 @@ export const useEmployeeForm = defineStore('form-employee', () => {
createdBy,
updatedBy,
profileImageUrl,
...playlond
} = res;
...payload
} = _data;
resetEmployeeData = {
...playlond,
...payload,
provinceId: province?.id,
districtId: district?.id,
subDistrictId: subDistrict?.id,
employeeCheckup: structuredClone(
playlond.employeeCheckup?.length === 0
payload.employeeCheckup?.length === 0
? defaultFormData.employeeCheckup
: playlond.employeeCheckup?.map((item) => ({
: payload.employeeCheckup?.map((item) => ({
...item,
statusSave: true,
})),
),
employeeOtherInfo: structuredClone(
{
...playlond.employeeOtherInfo,
statusSave: !!playlond.employeeOtherInfo?.id ? true : false,
...payload.employeeOtherInfo,
statusSave: !!payload.employeeOtherInfo?.id ? true : false,
} || {},
),
employeeWork: structuredClone(
playlond.employeeWork?.length === 0
payload.employeeWork?.length === 0
? defaultFormData.employeeWork
: playlond.employeeWork?.map((item) => ({
: payload.employeeWork?.map((item) => ({
...item,
statusSave: true,
})),
),
file: _attach
? await Promise.all(
_attach.map(async (v) => {
const group = v.split('-').at(0);
return {
url: await employeeStore.getAttachment(_data.id, v),
group,
};
}),
)
: [],
image: null,
};
currentFromDataEmployee.value = structuredClone(resetEmployeeData);
const foundBranch = await customerStore.fetchListCustomeBranchById(
playlond.customerBranchId,
payload.customerBranchId,
);
state.value.currentEmployeeCode = playlond.code;
state.value.currentEmployeeCode = payload.code;
state.value.profileUrl = profileImageUrl || ' ';
state.value.profileUrl = profileImageUrl || '';
profileImageUrl
? (state.value.profileSubmit = true)
@ -897,8 +910,8 @@ export const useEmployeeForm = defineStore('form-employee', () => {
state.value.formDataEmployeeOwner = { ...foundBranch };
if (
foundBranch.address === playlond.address &&
foundBranch.zipCode === playlond.zipCode
foundBranch.address === payload.address &&
foundBranch.zipCode === payload.zipCode
) {
state.value.formDataEmployeeSameAddr = true;
} else {