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

View file

@ -413,8 +413,18 @@ const useProductServiceStore = defineStore('api-product-service', () => {
}
// Service
async function fetchStatsService() {
const res = await api.get('/service/stats');
async function fetchStatsService(opts?: { productGroupId?: string }) {
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;