fix: product count & ref delete & fetch worker

This commit is contained in:
puriphatt 2024-10-15 09:42:16 +07:00
parent 62edd051e6
commit 0b83c943c0
2 changed files with 47 additions and 8 deletions

View file

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

View file

@ -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<ProductTree>();
watch(
() => productServiceList.value,
() => {
productServiceNodes.value = quotationProductTree(productServiceList.value);
},
);
</script>
<template>
@ -942,7 +951,7 @@ watch(
<!-- add product service -->
<ProductServiceForm
v-model="pageState.productServiceModal"
:nodes="quotationProductTree(productServiceList)"
v-model:nodes="productServiceNodes"
v-model:product-group="productGroup"
v-model:product-list="productList"
v-model:service-list="serviceList"