diff --git a/src/pages/03_customer-management/form.ts b/src/pages/03_customer-management/form.ts index 0a8795ad..37ac8ae6 100644 --- a/src/pages/03_customer-management/form.ts +++ b/src/pages/03_customer-management/form.ts @@ -171,25 +171,29 @@ export const useCustomerForm = defineStore('form-customer', () => { contactName: v.contactName || '', file: await customerStore.listAttachment(v.id).then(async (r) => { if (r) { - r.forEach((item) => { - const temp = item.split('-').at(0); + const fileGroups: Record< + string, + { label: string; files: { label: string }[] } + > = {}; - if ( - !state.value.treeFile.some( - (x) => x.label === t(`customer.typeFile.${temp || ''}`), - ) - ) { - state.value.treeFile.push({ - label: t(`customer.typeFile.${temp || ''}`), - file: r - .filter((x) => x.includes(temp || '')) - .map((x) => ({ - label: x, - })), - }); + r.forEach((file) => { + const temp = file.split('-')[0]; + + if (!fileGroups[temp]) { + fileGroups[temp] = { + label: t(`customer.typeFile.${temp}`), + files: [], + }; } + + fileGroups[temp].files.push({ label: file }); }); + state.value.treeFile = Object.values(fileGroups).map((group) => ({ + label: group.label, + file: group.files, + })); + return await Promise.all( r.map(async (item) => ({ url: await customerStore.getAttachment(v.id, item), @@ -848,6 +852,7 @@ export const useEmployeeForm = defineStore('form-employee', () => { resetEmployeeData = { ...playlond, + provinceId: province?.id, districtId: district?.id, subDistrictId: subDistrict?.id,