From f875d11b4f7faa4a26c3cd7a8a71c22fe80a6b1b Mon Sep 17 00:00:00 2001 From: Net Date: Tue, 27 Aug 2024 12:55:11 +0700 Subject: [PATCH] refactor: edit map data --- src/pages/03_customer-management/form.ts | 81 ++++++++++++++---------- 1 file changed, 46 insertions(+), 35 deletions(-) diff --git a/src/pages/03_customer-management/form.ts b/src/pages/03_customer-management/form.ts index 8781bb05..6441cfd1 100644 --- a/src/pages/03_customer-management/form.ts +++ b/src/pages/03_customer-management/form.ts @@ -127,41 +127,52 @@ export const useCustomerForm = defineStore('form-customer', () => { resetFormData.birthDate = new Date(data.birthDate); resetFormData.image = null; - resetFormData.customerBranch = data.branch.map((v) => ({ - id: v.id, - code: v.code || '', - customerCode: '', - provinceId: v.provinceId, - districtId: v.districtId, - subDistrictId: v.subDistrictId, - wageRate: v.wageRate, - payDate: new Date(v.payDate), // Convert the string to a Date object - saleEmployee: v.saleEmployee, - jobDescription: v.jobDescription, - jobPositionEN: v.jobPositionEN, - jobPosition: v.jobPosition, - businessTypeEN: v.businessTypeEN, - businessType: v.businessType, - employmentOffice: v.employmentOffice, - telephoneNo: v.telephoneNo, - email: v.email, - addressEN: v.addressEN, - address: v.address, - workplaceEN: v.workplaceEN, - workplace: v.workplace, - status: v.status, - customerId: v.customerId, - citizenId: v.citizenId || '', - authorizedCapital: v.authorizedCapital || '', - registerDate: new Date(v.registerDate), // Convert the string to a Date object - registerNameEN: v.registerNameEN || '', - registerName: v.registerName || '', - legalPersonNo: v.legalPersonNo || '', - registerCompanyName: '', - statusSave: true, - contactName: v.contactName || '', - file: undefined, - })); + resetFormData.customerBranch = await Promise.all( + data.branch.map(async (v) => ({ + id: v.id, + code: v.code || '', + customerCode: '', + provinceId: v.provinceId, + districtId: v.districtId, + subDistrictId: v.subDistrictId, + wageRate: v.wageRate, + payDate: new Date(v.payDate), // Convert the string to a Date object + saleEmployee: v.saleEmployee, + jobDescription: v.jobDescription, + jobPositionEN: v.jobPositionEN, + jobPosition: v.jobPosition, + businessTypeEN: v.businessTypeEN, + businessType: v.businessType, + employmentOffice: v.employmentOffice, + telephoneNo: v.telephoneNo, + email: v.email, + addressEN: v.addressEN, + address: v.address, + workplaceEN: v.workplaceEN, + workplace: v.workplace, + status: v.status, + customerId: v.customerId, + citizenId: v.citizenId || '', + authorizedCapital: v.authorizedCapital || '', + registerDate: new Date(v.registerDate), // Convert the string to a Date object + registerNameEN: v.registerNameEN || '', + registerName: v.registerName || '', + legalPersonNo: v.legalPersonNo || '', + registerCompanyName: '', + statusSave: true, + contactName: v.contactName || '', + file: await customerStore.listAttachment(v.id).then(async (r) => { + if (r) { + return await Promise.all( + r.map(async (item) => ({ + url: await customerStore.getAttachment(v.id, item), + })), + ); + } + return []; + }), + })), + ); currentFormData.value = structuredClone(resetFormData); }