refactor: handle submit work properties

This commit is contained in:
puriphatt 2024-11-27 10:59:03 +07:00
parent e902bcce8d
commit 925ed7dd9e
2 changed files with 39 additions and 90 deletions

View file

@ -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) => ({

View file

@ -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"
/>
<!-- <div v-if="serviceTab === 1" class="row q-pt-sm">
<SelectFlow
class="col-4"
v-model:value="formDataProductService.attributes.workflowId"
:label="$t('flow.title')"
simple
@update-value="
async (id) => {
if (id) {
console.log('2');
const ret = await getWorkflowTemplate(id);
if (ret) currWorkflow = ret;
handleChangeWorkflowId(id);
}
}
"
/>
</div> -->
<FormServiceWork
v-if="serviceTab === 2"
ref="refAddServiceWork"
@ -4146,38 +4139,12 @@ watch(
"
@submit="
(v) => {
if (
!workItems[currentWorkIndex].attributes.workflowId &&
!dialogService
) {
workItems[currentWorkIndex].attributes.workflowId = v.id;
workItems[currentWorkIndex].attributes.workflowStep.forEach(
(step) => {
if (!step.hasOwnProperty('productId')) {
console.log(1.1);
step.productsId = workItems[currentWorkIndex].product.map(
(p) => p.id,
);
}
},
);
}
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;
return;
}
currWorkflow = v;
handleSubmitWorkflow(v.id);
}
"
></DialogProperties>
@ -4484,26 +4451,6 @@ watch(
v-model:service-name-th="formDataProductService.name"
/>
<!-- <div v-if="serviceTab === 1" class="row q-pt-sm">
<SelectFlow
:readonly="!infoServiceEdit"
class="col-4"
v-model:value="formDataProductService.attributes.workflowId"
:label="$t('flow.title')"
simple
@update-value="
async (id) => {
if (id) {
console.log('2');
const ret = await getWorkflowTemplate(id);
if (ret) currWorkflow = ret;
handleChangeWorkflowId(id);
}
}
"
/>
</div> -->
<FormServiceWork
v-if="serviceTab === 2"
ref="refEditServiceWork"