refactor: view all stat with no fetch
This commit is contained in:
parent
8ffecc9146
commit
18059db8a0
1 changed files with 27 additions and 15 deletions
|
|
@ -103,6 +103,7 @@ const {
|
|||
const { workNameItems, recordTreeProductType } =
|
||||
storeToRefs(productServiceStore);
|
||||
|
||||
const allStat = ref<{ mode: string; count: number }[]>([]);
|
||||
const stat = ref<
|
||||
{
|
||||
icon: string;
|
||||
|
|
@ -759,7 +760,7 @@ async function deleteServiceConfirm(serviceId?: string) {
|
|||
totalService.value = totalService.value - 1;
|
||||
}
|
||||
flowStore.rotate();
|
||||
calculateStats();
|
||||
calculateStats({ reFetch: true });
|
||||
},
|
||||
cancel: () => {},
|
||||
});
|
||||
|
|
@ -791,7 +792,7 @@ async function deleteProductConfirm(id?: string) {
|
|||
totalProduct.value = totalProduct.value - 1;
|
||||
}
|
||||
flowStore.rotate();
|
||||
calculateStats();
|
||||
calculateStats({ reFetch: true });
|
||||
},
|
||||
cancel: () => {},
|
||||
});
|
||||
|
|
@ -819,7 +820,7 @@ async function deleteProductById(productId?: string) {
|
|||
}
|
||||
|
||||
flowStore.rotate();
|
||||
calculateStats();
|
||||
calculateStats({ reFetch: true });
|
||||
editByTree.value = undefined;
|
||||
drawerInfo.value = false;
|
||||
} else {
|
||||
|
|
@ -834,7 +835,7 @@ async function deleteProductById(productId?: string) {
|
|||
}
|
||||
|
||||
flowStore.rotate();
|
||||
calculateStats();
|
||||
calculateStats({ reFetch: true });
|
||||
drawerInfo.value = false;
|
||||
}
|
||||
},
|
||||
|
|
@ -1070,6 +1071,7 @@ async function submitService() {
|
|||
|
||||
const res = await createService(formDataProductService.value);
|
||||
if (res) {
|
||||
allStat.value[1].count = allStat.value[1].count + 1;
|
||||
stat.value[1].count = stat.value[1].count + 1;
|
||||
}
|
||||
totalService.value = totalService.value + 1;
|
||||
|
|
@ -1110,6 +1112,7 @@ async function submitProduct() {
|
|||
const res = await createProduct(formDataProduct.value);
|
||||
|
||||
if (res) {
|
||||
allStat.value[2].count = allStat.value[2].count + 1;
|
||||
stat.value[2].count = stat.value[2].count + 1;
|
||||
}
|
||||
|
||||
|
|
@ -1140,6 +1143,7 @@ async function submitGroup() {
|
|||
const res = await createProductService(formDataGroup.value);
|
||||
|
||||
if (res) {
|
||||
allStat.value[0].count = allStat.value[0].count + 1;
|
||||
stat.value[0].count = stat.value[0].count + 1;
|
||||
}
|
||||
}
|
||||
|
|
@ -1196,8 +1200,11 @@ function openPropertiesDialog(type: 'service' | 'work') {
|
|||
propertiesDialog.value = true;
|
||||
}
|
||||
|
||||
async function calculateStats(type?: 'service' | 'product') {
|
||||
if (type === 'service' && productMode.value === 'service') {
|
||||
async function calculateStats(opt?: {
|
||||
type?: 'service' | 'product';
|
||||
reFetch?: boolean;
|
||||
}) {
|
||||
if (opt && opt.type === 'service' && productMode.value === 'service') {
|
||||
const resStatsService = await fetchStatsService({
|
||||
productGroupId: currentIdGrop.value,
|
||||
});
|
||||
|
|
@ -1205,7 +1212,7 @@ async function calculateStats(type?: 'service' | 'product') {
|
|||
return;
|
||||
}
|
||||
|
||||
if (type === 'product' && productMode.value === 'product') {
|
||||
if (opt && opt.type === 'product' && productMode.value === 'product') {
|
||||
const resStatsProduct = await fetchStatsProduct({
|
||||
productGroupId: currentIdGrop.value,
|
||||
});
|
||||
|
|
@ -1213,13 +1220,18 @@ async function calculateStats(type?: 'service' | 'product') {
|
|||
return;
|
||||
}
|
||||
|
||||
const resStatsGroup = await fetchStatsProductGroup();
|
||||
const resStatsService = await fetchStatsService();
|
||||
const resStatsProduct = await fetchStatsProduct();
|
||||
if (allStat.value.length === 0 || (opt && opt.reFetch)) {
|
||||
const resStatsGroup = await fetchStatsProductGroup();
|
||||
const resStatsService = await fetchStatsService();
|
||||
const resStatsProduct = await fetchStatsProduct();
|
||||
|
||||
stat.value[0].count = resStatsGroup ?? 0;
|
||||
stat.value[1].count = resStatsService ?? 0;
|
||||
stat.value[2].count = resStatsProduct ?? 0;
|
||||
allStat.value.push({ mode: 'group', count: resStatsGroup ?? 0 });
|
||||
allStat.value.push({ mode: 'service', count: resStatsService ?? 0 });
|
||||
allStat.value.push({ mode: 'product', count: resStatsProduct ?? 0 });
|
||||
}
|
||||
stat.value[0].count = allStat.value[0].count;
|
||||
stat.value[1].count = allStat.value[1].count;
|
||||
stat.value[2].count = allStat.value[2].count;
|
||||
}
|
||||
|
||||
async function fetchStatus() {
|
||||
|
|
@ -1465,10 +1477,10 @@ watch([currentStatusList, productMode], async () => {
|
|||
await calculateStats();
|
||||
}
|
||||
if (productMode.value === 'service') {
|
||||
await calculateStats('service');
|
||||
await calculateStats({ type: 'service' });
|
||||
}
|
||||
if (productMode.value === 'product') {
|
||||
await calculateStats('product');
|
||||
await calculateStats({ type: 'product' });
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue