From 4a6f192d5ff6c0335408f130e32d7991c9753331 Mon Sep 17 00:00:00 2001 From: puriphatt Date: Wed, 4 Dec 2024 13:35:36 +0700 Subject: [PATCH] refactor: package => step count --- src/pages/04_product-service/MainPage.vue | 24 ++++++++++++++++++----- src/stores/product-service/types.ts | 2 ++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/pages/04_product-service/MainPage.vue b/src/pages/04_product-service/MainPage.vue index dc5573bd..b9c12a97 100644 --- a/src/pages/04_product-service/MainPage.vue +++ b/src/pages/04_product-service/MainPage.vue @@ -5,7 +5,6 @@ import { onMounted } from 'vue'; import { storeToRefs } from 'pinia'; import { useQuasar, type QTableProps } from 'quasar'; -import SelectFlow from 'src/components/shared/select/SelectFlow.vue'; import DialogProperties from 'src/components/dialog/DialogProperties.vue'; import ProductCardComponent from 'components/04_product-service/ProductCardComponent.vue'; import StatCard from 'components/StatCardComponent.vue'; @@ -926,6 +925,7 @@ async function assignFormDataProductService(id: string) { product: item.productOnWork.map((productOnWorkItem) => ({ id: productOnWorkItem.product.id, installmentNo: productOnWorkItem.installmentNo, + stepCount: productOnWorkItem.stepCount, })), }); }); @@ -1075,10 +1075,23 @@ function assignFormDataProductServiceCreate() { id: item.id, name: item.name, attributes: item.attributes, - product: item.product.map((productItem) => ({ - id: productItem.id, - installmentNo: productItem.installmentNo, - })), + product: item.product.map((productItem) => { + const stepCount = item.attributes.workflowStep.reduce((count, step) => { + if ( + step.attributes?.properties?.length > 0 && + step.productsId.includes(productItem.id) + ) { + return count + 1; + } + return count; + }, 0); + + return { + id: productItem.id, + installmentNo: productItem.installmentNo, + stepCount: stepCount, + }; + }), }); }); } @@ -1089,6 +1102,7 @@ async function submitService(notClose = false) { if (profileFileImg.value) formDataProductService.value.image = profileFileImg.value; + if (dialogService.value) { formDataProductService.value.productGroupId = currentIdGroup.value; formDataProductService.value.work.forEach((s) => (s.id = undefined)); diff --git a/src/stores/product-service/types.ts b/src/stores/product-service/types.ts index 0a110b5f..0beb9d98 100644 --- a/src/stores/product-service/types.ts +++ b/src/stores/product-service/types.ts @@ -58,6 +58,7 @@ export interface ServiceCreate { product: { id: string; installmentNo?: number; + stepCount: number; }[]; name: string; }[]; @@ -136,6 +137,7 @@ export interface ProductOnWork { workId: string; order: number; installmentNo: number; + stepCount: number; } export interface WorkItems {