refactor: edit map data

This commit is contained in:
Net 2024-08-28 17:36:30 +07:00 committed by Methapon Metanipat
parent 659f2f5da5
commit 3529f81352

View file

@ -181,33 +181,17 @@ export const useCustomerForm = defineStore('form-customer', () => {
contactName: v.contactName || '',
file: await customerStore.listAttachment(v.id).then(async (r) => {
if (r) {
const fileGroups: Record<
string,
{ label: string; files: { label: string }[] }
> = {};
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),
})),
r.map(async (item) => {
const fragment = item.split('-');
const group = fragment.length === 1 ? 'other' : fragment.at(0);
return {
url: await customerStore.getAttachment(v.id, item),
name: item,
group: group,
};
}),
);
}
return [];
@ -321,6 +305,7 @@ export const useCustomerForm = defineStore('form-customer', () => {
assignFormData,
submitFormCustomer,
addCurrentCustomerBranch,
deleteAttachment,
};
});
@ -475,8 +460,8 @@ export const useCustomerBranchForm = defineStore('form-customer-branch', () => {
return {
state,
initForm,
currentFormData,
initForm,
isFormDataDifferent,
submitForm,
};