From 0b83c943c08b0307b746bfd280a319e225424337 Mon Sep 17 00:00:00 2001 From: puriphatt Date: Tue, 15 Oct 2024 09:42:16 +0700 Subject: [PATCH] fix: product count & ref delete & fetch worker --- src/pages/05_quotation/ProductServiceForm.vue | 32 ++++++++++++++++++- src/pages/05_quotation/QuotationForm.vue | 23 +++++++++---- 2 files changed, 47 insertions(+), 8 deletions(-) diff --git a/src/pages/05_quotation/ProductServiceForm.vue b/src/pages/05_quotation/ProductServiceForm.vue index fa7022ae..612f953b 100644 --- a/src/pages/05_quotation/ProductServiceForm.vue +++ b/src/pages/05_quotation/ProductServiceForm.vue @@ -134,9 +134,33 @@ function toggleDelete(node?: Node) { selectedItems.value = []; } else { const targetItem = selectedItems.value.find((i) => i.id === node?.id); - deleteItem(nodes.value, nodes.value.indexOf(node)); + const targetNode = nodes.value.find((i) => i === node); + targetItem && deleteItem(selectedItems.value, selectedItems.value.indexOf(targetItem)); + targetNode && deleteItem(nodes.value, nodes.value.indexOf(targetNode)); + if (node.type === 'type') { + const countProducts = (node: Node[]) => { + let count = 0; + + node.forEach((item) => { + if (item.type === 'product') { + count++; + } + + if (item.children && item.children.length > 0) { + count += countProducts(item.children); + } + }); + + return count; + }; + const count = node.children && countProducts(node.children); + + if (count) productCount.value = productCount.value - count; + } else { + productCount.value--; + } } } @@ -201,6 +225,7 @@ function mapNode() { title: v.name, subtitle: v.code, opened: v.work.length > 0, + attributes: v.attributes, checked: true, icon: 'mdi-server-outline', bg: 'hsla(var(--orange-5-hsl)/0.1)', @@ -216,6 +241,7 @@ function mapNode() { const pricePerUnit = p.product.vatIncluded ? precisionRound(price / (1 + (config.value?.vat || 0.07))) : price; + productCount.value++; return { type: 'product', id: p.product.id, @@ -243,9 +269,11 @@ function mapNode() { const withNameObjects = v.work .filter((w: Work) => w.name) .flatMap((w: Work) => ({ + type: 'work', id: w.id, title: w.name, subtitle: ' ', + attributes: w.attributes, opened: w.productOnWork.length > 0, checked: true, children: w.productOnWork.map((p) => { @@ -257,6 +285,7 @@ function mapNode() { : price; productCount.value++; return { + type: 'product', id: p.product.id, title: p.product.name, subtitle: p.product.code || ' ', @@ -284,6 +313,7 @@ function mapNode() { : price; productCount.value++; return { + type: 'product', id: v.id, title: v.name, subtitle: v.code, diff --git a/src/pages/05_quotation/QuotationForm.vue b/src/pages/05_quotation/QuotationForm.vue index 8ac58364..5e9f641e 100644 --- a/src/pages/05_quotation/QuotationForm.vue +++ b/src/pages/05_quotation/QuotationForm.vue @@ -4,7 +4,7 @@ import { storeToRefs } from 'pinia'; import { useQuasar } from 'quasar'; import { computed, nextTick, onMounted, reactive, ref, watch } from 'vue'; import { dialogCheckData } from 'stores/utils'; -import { quotationProductTree } from './utils'; +import { ProductTree, quotationProductTree } from './utils'; // NOTE: Import stores import { setLocale, dateFormat, calculateAge } from 'src/utils/datetime'; @@ -544,11 +544,11 @@ watch( url.searchParams.set('customerBranchId', v); history.pushState({}, '', url.toString()); - // if (!v) return; - // const retEmp = await customerStore.fetchBranchEmployee(v); - // if (retEmp) { - // workerList.value = retEmp.data.result; - // } + if (!v) return; + const retEmp = await customerStore.fetchBranchEmployee(v); + if (retEmp) { + workerList.value = retEmp.data.result; + } }, ); @@ -561,6 +561,15 @@ watch( history.pushState({}, '', url.toString()); }, ); + +const productServiceNodes = ref(); + +watch( + () => productServiceList.value, + () => { + productServiceNodes.value = quotationProductTree(productServiceList.value); + }, +);