refactor: edit assign treeFile

This commit is contained in:
Net 2024-08-28 09:47:05 +07:00 committed by Methapon Metanipat
parent 86a0c1f775
commit d66c2b3469

View file

@ -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,