diff --git a/src/components/dialog/DialogProperties.vue b/src/components/dialog/DialogProperties.vue index ec988271..93ae6c46 100644 --- a/src/components/dialog/DialogProperties.vue +++ b/src/components/dialog/DialogProperties.vue @@ -69,11 +69,13 @@ const typeOption = [ ]; function submit() { + console.log(tempStep.value); workflowId.value = tempWorkflowId.value; dataStep.value = JSON.parse(JSON.stringify(tempStep.value)); model.value = false; if (props.selectFlow && currWorkflow.value) { + console.log(JSON.parse(JSON.stringify(currWorkflow.value))); emit('submit', currWorkflow.value); } } @@ -276,7 +278,7 @@ watch( if (props.selectFlow && a !== b && a) { const ret = await getWorkflowTemplate(a); if (ret) { - currWorkflow.value = ret; + currWorkflow.value = JSON.parse(JSON.stringify(ret)); tempStep.value = ret.step?.length > 0 ? ret.step.map((s) => ({ diff --git a/src/pages/04_product-service/MainPage.vue b/src/pages/04_product-service/MainPage.vue index c537f8f4..01fcb0cc 100644 --- a/src/pages/04_product-service/MainPage.vue +++ b/src/pages/04_product-service/MainPage.vue @@ -61,7 +61,10 @@ import { Attributes, } from 'stores/product-service/types'; import { computed } from 'vue'; -import { WorkflowTemplate } from 'src/stores/workflow-template/types'; +import { + WorkflowStep, + WorkflowTemplate, +} from 'src/stores/workflow-template/types'; import { useWorkflowTemplate } from 'src/stores/workflow-template'; const flowStore = useFlowStore(); @@ -1581,25 +1584,34 @@ watch( }, ); -function handleChangeWorkflowId(workflowId: string) { - if (workItems.value.length > 0 && currWorkflow.value) { - workItems.value.forEach((w) => { - w.attributes.workflowId = workflowId; - w.attributes.workflowStep = currWorkflow.value - ? JSON.parse( - JSON.stringify( - currWorkflow.value.step.map((step) => ({ - name: step.name, - attributes: step.attributes, - productsId: workItems.value[currentWorkIndex.value].product.map( - (p) => p.id, - ), - })), - ), - ) - : []; - }); - } +function handleSubmitWorkflow(workflowId: string) { + if (workItems.value.length === 0 && !currWorkflow.value) return; + + const workflow = JSON.parse(JSON.stringify(currWorkflow.value)); + + workItems.value.forEach((w, wIndex) => { + w.attributes.workflowId = workflowId; + + if (wIndex === currentWorkIndex.value) { + w.attributes.workflowStep.forEach((s) => { + if (!s.hasOwnProperty('productsId')) { + s.productsId = []; + } + s.productsId = workItems.value[wIndex]?.product.map((p) => p.id); + }); + return; + } else { + w.attributes.workflowStep = JSON.parse( + JSON.stringify( + workflow.step.map((step: WorkflowStep) => ({ + name: step.name, + attributes: step.attributes, + productsId: workItems.value[wIndex]?.product.map((p) => p.id), + })), + ), + ); + } + }); } function handleSubmitSameWorkflow() { @@ -1620,7 +1632,7 @@ watch( () => formDataProductService.value.attributes.workflowId, async (a, b) => { if (a && b && a !== b) { - handleChangeWorkflowId(a); + handleSubmitWorkflow(a); } }, ); @@ -4052,25 +4064,6 @@ watch( v-model:service-name-th="formDataProductService.name" /> - - @@ -4484,26 +4451,6 @@ watch( v-model:service-name-th="formDataProductService.name" /> - -