refactor(04): calculate stat

This commit is contained in:
puriphatt 2024-09-04 14:45:53 +07:00
parent f03eb722b5
commit d8a6b346ab
2 changed files with 41 additions and 8 deletions

View file

@ -1257,7 +1257,23 @@ function openPropertiesDialog(type: 'service' | 'work') {
propertiesDialog.value = true; propertiesDialog.value = true;
} }
async function calculateStats() { async function calculateStats(type?: 'service' | 'product') {
if (type === 'service' && productMode.value === 'service') {
const resStatsService = await fetchStatsService({
productGroupId: currentIdGrop.value,
});
stat.value[1].count = resStatsService ?? 0;
return;
}
if (type === 'product' && productMode.value === 'product') {
const resStatsProduct = await fetchStatsProduct({
productGroupId: currentIdGrop.value,
});
stat.value[2].count = resStatsProduct ?? 0;
return;
}
const resStatsGroup = await fetchStatsProductGroup(); const resStatsGroup = await fetchStatsProductGroup();
const resStatsService = await fetchStatsService(); const resStatsService = await fetchStatsService();
const resStatsProduct = await fetchStatsProduct(); const resStatsProduct = await fetchStatsProduct();
@ -1321,6 +1337,7 @@ async function enterGroup(
toService?: boolean, toService?: boolean,
) { ) {
expandedTree.value = []; expandedTree.value = [];
filterStat.value = [];
expandedTree.value.push(id); expandedTree.value.push(id);
pathGroupName.value = name; pathGroupName.value = name;
currentIdType.value = ''; currentIdType.value = '';
@ -1368,6 +1385,7 @@ async function enterNext(type: 'service' | 'product') {
} }
if (type === 'service') { if (type === 'service') {
console.log('service');
productMode.value = 'service'; productMode.value = 'service';
productAndServiceTab.value = 'service'; productAndServiceTab.value = 'service';
currentIdType.value = 'type'; currentIdType.value = 'type';
@ -1384,7 +1402,6 @@ async function enterNext(type: 'service' | 'product') {
filterStat.value.push('group'); filterStat.value.push('group');
filterStat.value.push('service'); filterStat.value.push('service');
} }
flowStore.rotate(); flowStore.rotate();
} }
@ -1555,8 +1572,17 @@ watch(
}, },
); );
watch([currentStatusList, productMode], () => { watch([currentStatusList, productMode], async () => {
currentNoAction.value = handleStatus(); currentNoAction.value = handleStatus();
if (productMode.value === 'group') {
await calculateStats();
}
if (productMode.value === 'service') {
await calculateStats('service');
}
if (productMode.value === 'product') {
await calculateStats('product');
}
}); });
</script> </script>
@ -1716,7 +1742,6 @@ watch([currentStatusList, productMode], () => {
currentIdType = ''; currentIdType = '';
currentStatusList = []; currentStatusList = [];
productMode = 'group'; productMode = 'group';
return; return;
} }
} }
@ -1743,10 +1768,8 @@ watch([currentStatusList, productMode], () => {
if (currentIdType === v.id) { if (currentIdType === v.id) {
expandedTree.pop(); expandedTree.pop();
currentIdType = ''; currentIdType = '';
filterStat = []; filterStat = [];
productMode = 'group'; productMode = 'group';
return; return;
} }
} }

View file

@ -413,8 +413,18 @@ const useProductServiceStore = defineStore('api-product-service', () => {
} }
// Service // Service
async function fetchStatsService() { async function fetchStatsService(opts?: { productGroupId?: string }) {
const res = await api.get('/service/stats'); const params = new URLSearchParams();
for (const [k, v] of Object.entries(opts || {})) {
v !== undefined && params.append(k, v.toString());
}
const query = params.toString();
const res = await api.get(
`/service/stats${(params && '?'.concat(query)) || ''}`,
);
if (!res) return false; if (!res) return false;