fix: branch INACTIVE can't show subBranch

This commit is contained in:
Net 2024-08-23 16:13:18 +07:00
parent f5cf3aec57
commit 7e559136af

View file

@ -157,14 +157,21 @@ const { locale } = useI18n();
const { data: branchData } = storeToRefs(branchStore);
const treeData = computed(() => {
const arr: BranchWithChildren[] = [];
const map: Record<string, BranchWithChildren> = {};
const children: Branch[] = [];
branchData.value?.result.forEach((a) => {
if (a.isHeadOffice) arr.push(Object.assign(a, { branch: [] }));
else arr.find((b) => b.id === a.headOfficeId)?.branch.push(a);
branchData.value?.result.forEach((v) => {
if (v.isHeadOffice) map[v.id] = Object.assign(v, { branch: [] });
else children.push(v);
});
return arr;
children.forEach((v) => {
if (v.headOfficeId && map[v.headOfficeId]) {
map[v.headOfficeId].branch.push(v);
}
});
return Object.values(map);
});
async function calculateStats() {