From 9b96d2248013a89c28e7e90b5cc395840799f1b1 Mon Sep 17 00:00:00 2001 From: puriphatt Date: Tue, 19 Nov 2024 17:39:56 +0700 Subject: [PATCH] fix/refactor: handle submit properties --- src/pages/04_product-service/MainPage.vue | 49 +++++++++++++++++++++-- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/src/pages/04_product-service/MainPage.vue b/src/pages/04_product-service/MainPage.vue index 3d793ea4..79e14cc3 100644 --- a/src/pages/04_product-service/MainPage.vue +++ b/src/pages/04_product-service/MainPage.vue @@ -480,6 +480,8 @@ const filterStat = ref<('group' | 'service' | 'product')[]>([]); const refAddServiceWork = ref(); const refEditServiceWork = ref(); +const tempWorkItems = ref([]); + // แบ่งหน้า const currentPageGroup = ref(1); const maxPageGroup = ref(1); @@ -886,6 +888,9 @@ async function assignFormDataProductService(id: string) { currentService.value = JSON.parse(JSON.stringify(res)); + const workflowRet = await getWorkflowTemplate(res.attributes.workflowId); + if (workflowRet) currWorkflow.value = workflowRet; + prevService.value = { code: res.code, name: res.name, @@ -1035,6 +1040,7 @@ function clearFormService() { status: undefined, productGroupId: '', }; + tempWorkItems.value = []; splitPay.value = 0; workItems.value = []; selectProduct.value = []; @@ -1580,7 +1586,9 @@ function handleChangeWorkflowId(workflowId: string) { currWorkflow.value.step.map((step) => ({ name: step.name, attributes: step.attributes, - productsId: [], + productsId: workItems.value[currentWorkIndex.value].product.map( + (p) => p.id, + ), })), ), ) @@ -1589,10 +1597,24 @@ function handleChangeWorkflowId(workflowId: string) { } } +function handleSubmitSameWorkflow() { + const tempStep = JSON.parse( + JSON.stringify( + tempWorkItems.value[currentWorkIndex.value].attributes.workflowStep, + ), + ); + + workItems.value[currentWorkIndex.value].attributes.workflowStep.forEach( + (step, i) => { + step.productsId = tempStep[i].productsId; + }, + ); +} + watch( () => formDataProductService.value.attributes.workflowId, async (a, b) => { - if (a && a !== b) { + if (a && b && a !== b) { handleChangeWorkflowId(a); } }, @@ -4113,9 +4135,30 @@ watch( v-model:data-step="workItems[currentWorkIndex].attributes.workflowStep" v-model:workflow-id="formDataProductService.attributes.workflowId" v-model="propertiesDialog" + @show=" + () => { + tempWorkItems[currentWorkIndex] = JSON.parse( + JSON.stringify(workItems[currentWorkIndex]), + ); + } + " @submit=" (v) => { - currWorkflow = v; + if (dialogService) { + workItems[currentWorkIndex].attributes.workflowId = v.id; + workItems[currentWorkIndex].attributes.workflowStep.forEach( + (step) => { + step.productsId = workItems[currentWorkIndex].product.map( + (p) => p.id, + ); + }, + ); + } + if (v.id === currWorkflow?.id) { + handleSubmitSameWorkflow(); + } else { + currWorkflow = v; + } } " >