From 7a700b050af8f8b1738040b1c2fac31f5ba72ac9 Mon Sep 17 00:00:00 2001 From: Net Date: Tue, 27 Aug 2024 16:19:18 +0700 Subject: [PATCH] refactor: map tree --- src/pages/03_customer-management/form.ts | 25 ++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/pages/03_customer-management/form.ts b/src/pages/03_customer-management/form.ts index 6441cfd1..62491a1c 100644 --- a/src/pages/03_customer-management/form.ts +++ b/src/pages/03_customer-management/form.ts @@ -2,6 +2,7 @@ import { ref, toRaw, watch } from 'vue'; import { defineStore } from 'pinia'; import { CustomerBranchCreate, CustomerCreate } from 'stores/customer/types'; import { Employee, EmployeeCreate } from 'stores/employee/types'; +import { useI18n } from 'vue-i18n'; import useMyBranch from 'stores/my-branch'; import useCustomerStore from 'stores/customer'; @@ -9,6 +10,7 @@ import useEmployeeStore from 'stores/employee'; import useFlowStore from 'stores/flow'; export const useCustomerForm = defineStore('form-customer', () => { + const { t } = useI18n(); const apiBaseUrl = import.meta.env.VITE_API_BASE_URL; const customerStore = useCustomerStore(); @@ -46,6 +48,7 @@ export const useCustomerForm = defineStore('form-customer', () => { editCustomerId?: string; editCustomerCode?: string; editCustomerBranchId?: string; + treeFile: { lable: string; file: { lable: string }[] }[]; }>({ dialogType: 'info', dialogOpen: false, @@ -59,6 +62,7 @@ export const useCustomerForm = defineStore('form-customer', () => { editCustomerId: '', editCustomerBranchId: '', defaultCustomerImageUrl: '', + treeFile: [], }); watch( @@ -82,6 +86,8 @@ export const useCustomerForm = defineStore('form-customer', () => { resetFormData = structuredClone(defaultFormData); resetFormData.registeredBranchId = branchStore.currentMyBranch?.id || ''; state.value.editCustomerId = ''; + state.value.treeFile = []; + return; } @@ -163,6 +169,25 @@ 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); + + if ( + !state.value.treeFile.some( + (x) => x.lable === t(`customer.typeFile.${temp || ''}`), + ) + ) { + state.value.treeFile.push({ + lable: t(`customer.typeFile.${temp || ''}`), + file: r + .filter((x) => x.includes(temp || '')) + .map((x) => ({ + lable: x, + })), + }); + } + }); + return await Promise.all( r.map(async (item) => ({ url: await customerStore.getAttachment(v.id, item),