refactor: package workflow (#73)

* fix: service attributes type

* feat: select workflow component

* refactor: dialog properties => select work flow

* refactor: package => work new workflow step

* fix: useless  in future (service properties)

* fix: handle work undefine

---------

Co-authored-by: puriphatt <puriphat@frappet.com>
This commit is contained in:
Methapon Metanipat 2024-11-13 16:06:32 +07:00 committed by GitHub
parent bd718eb492
commit 6e796049d5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 374 additions and 187 deletions

View file

@ -1,17 +1,20 @@
<script setup lang="ts"> <script setup lang="ts">
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import { moveItemUp, moveItemDown, deleteItem, dialog } from 'stores/utils'; import { moveItemUp, moveItemDown, deleteItem, dialog } from 'stores/utils';
import { nextTick, ref, watch } from 'vue';
import { WorkflowTemplate } from 'src/stores/workflow-template/types';
import { ServiceCreate, WorkItems } from 'stores/product-service/types';
import NoData from 'components/NoData.vue'; import NoData from 'components/NoData.vue';
import WorkManagementComponent from './WorkManagementComponent.vue'; import WorkManagementComponent from './WorkManagementComponent.vue';
import AddButton from '../button/AddButton.vue'; import AddButton from '../button/AddButton.vue';
import { ServiceCreate, WorkItems } from 'stores/product-service/types';
import TreeView from '../shared/TreeView.vue'; import TreeView from '../shared/TreeView.vue';
import { nextTick, ref, watch } from 'vue';
const { t } = useI18n(); const { t } = useI18n();
const workItems = defineModel<WorkItems[]>('workItems', { default: [] }); const workItems = defineModel<WorkItems[]>('workItems', { default: [] });
const workflow = defineModel<WorkflowTemplate>('workflow');
const props = defineProps<{ const props = defineProps<{
service?: ServiceCreate; service?: ServiceCreate;
@ -75,11 +78,20 @@ async function addWork() {
id: '', id: '',
name: '', name: '',
attributes: { attributes: {
workflowName: '', workflowStep: workflow.value?.step
? JSON.parse(
JSON.stringify(
workflow.value.step.map((step) => ({
name: step.name,
attributes: step.attributes,
productsId: [],
})),
),
)
: [],
additional: [], additional: [],
showTotalPrice: false, showTotalPrice: false,
stepProperties: [], workflowId: workflow.value ? workflow.value.id : '',
workflowId: '',
}, },
product: [], product: [],
}); });

View file

@ -65,16 +65,16 @@ function manageProperties(
) { ) {
if (property === 'all' && propertiesOption.value) { if (property === 'all' && propertiesOption.value) {
if ( if (
formServiceProperties.value.stepProperties[stepIndex].attributes formServiceProperties.value.stepProperties[stepIndex].properties
.length === propertiesOption.value.length .length === propertiesOption.value.length
) { ) {
formServiceProperties.value.stepProperties[stepIndex].attributes = []; formServiceProperties.value.stepProperties[stepIndex].properties = [];
return; return;
} }
for (const ops of propertiesOption.value) { for (const ops of propertiesOption.value) {
if ( if (
formServiceProperties.value.stepProperties[stepIndex].attributes.some( formServiceProperties.value.stepProperties[stepIndex].properties.some(
(prop) => prop.fieldName === ops.value, (prop) => prop.fieldName === ops.value,
) )
) { ) {
@ -82,14 +82,14 @@ function manageProperties(
} }
if (ops.type === 'date') { if (ops.type === 'date') {
formServiceProperties.value.stepProperties[stepIndex].attributes.push({ formServiceProperties.value.stepProperties[stepIndex].properties.push({
type: ops.type, type: ops.type,
fieldName: ops.value, fieldName: ops.value,
}); });
} }
if (ops.type === 'array') { if (ops.type === 'array') {
formServiceProperties.value.stepProperties[stepIndex].attributes.push({ formServiceProperties.value.stepProperties[stepIndex].properties.push({
type: ops.type, type: ops.type,
fieldName: ops.value, fieldName: ops.value,
options: [], options: [],
@ -97,7 +97,7 @@ function manageProperties(
} }
if (ops.type === 'string') { if (ops.type === 'string') {
formServiceProperties.value.stepProperties[stepIndex].attributes.push({ formServiceProperties.value.stepProperties[stepIndex].properties.push({
type: ops.type, type: ops.type,
fieldName: ops.value, fieldName: ops.value,
isPhoneNumber: false, isPhoneNumber: false,
@ -106,7 +106,7 @@ function manageProperties(
} }
if (ops.type === 'number') { if (ops.type === 'number') {
formServiceProperties.value.stepProperties[stepIndex].attributes.push({ formServiceProperties.value.stepProperties[stepIndex].properties.push({
type: ops.type, type: ops.type,
fieldName: ops.value, fieldName: ops.value,
comma: false, comma: false,
@ -118,26 +118,26 @@ function manageProperties(
return; return;
} }
if (formServiceProperties.value.stepProperties[stepIndex].attributes) { if (formServiceProperties.value.stepProperties[stepIndex].properties) {
const propertyIndex = formServiceProperties.value.stepProperties[ const propertyIndex = formServiceProperties.value.stepProperties[
stepIndex stepIndex
].attributes.findIndex((prop) => prop.fieldName === property); ].properties.findIndex((prop) => prop.fieldName === property);
if (propertyIndex !== -1) { if (propertyIndex !== -1) {
formServiceProperties.value.stepProperties[stepIndex].attributes.splice( formServiceProperties.value.stepProperties[stepIndex].properties.splice(
propertyIndex, propertyIndex,
1, 1,
); );
} else { } else {
if (propertyType === 'date') { if (propertyType === 'date') {
formServiceProperties.value.stepProperties[stepIndex].attributes.push({ formServiceProperties.value.stepProperties[stepIndex].properties.push({
type: propertyType, type: propertyType,
fieldName: property, fieldName: property,
}); });
} }
if (propertyType === 'array') { if (propertyType === 'array') {
formServiceProperties.value.stepProperties[stepIndex].attributes.push({ formServiceProperties.value.stepProperties[stepIndex].properties.push({
type: propertyType, type: propertyType,
fieldName: property, fieldName: property,
options: [], options: [],
@ -145,7 +145,7 @@ function manageProperties(
} }
if (propertyType === 'string') { if (propertyType === 'string') {
formServiceProperties.value.stepProperties[stepIndex].attributes.push({ formServiceProperties.value.stepProperties[stepIndex].properties.push({
type: propertyType, type: propertyType,
fieldName: property, fieldName: property,
isPhoneNumber: false, isPhoneNumber: false,
@ -154,7 +154,7 @@ function manageProperties(
} }
if (propertyType === 'number') { if (propertyType === 'number') {
formServiceProperties.value.stepProperties[stepIndex].attributes.push({ formServiceProperties.value.stepProperties[stepIndex].properties.push({
type: propertyType, type: propertyType,
fieldName: property, fieldName: property,
comma: false, comma: false,
@ -167,9 +167,9 @@ function manageProperties(
} }
function shouldShowItem(opt: Option, stepIndex: number) { function shouldShowItem(opt: Option, stepIndex: number) {
if (formServiceProperties.value.stepProperties[stepIndex].attributes) { if (formServiceProperties.value.stepProperties[stepIndex].properties) {
const additionalFieldNames = new Set( const additionalFieldNames = new Set(
formServiceProperties.value.stepProperties[stepIndex].attributes.map( formServiceProperties.value.stepProperties[stepIndex].properties.map(
(o) => o.fieldName, (o) => o.fieldName,
), ),
); );
@ -188,19 +188,19 @@ function changeType(fieldName: string, stepIndex: number) {
const idx = formServiceProperties.value.stepProperties[ const idx = formServiceProperties.value.stepProperties[
stepIndex stepIndex
].attributes.findIndex((v) => v.fieldName === fieldName); ].properties.findIndex((v) => v.fieldName === fieldName);
if (!idx) return; if (!idx) return;
if (defaultPropType === 'date') { if (defaultPropType === 'date') {
formServiceProperties.value.stepProperties[stepIndex].attributes.push({ formServiceProperties.value.stepProperties[stepIndex].properties.push({
type: defaultPropType, type: defaultPropType,
fieldName, fieldName,
}); });
} }
if (defaultPropType === 'array') { if (defaultPropType === 'array') {
formServiceProperties.value.stepProperties[stepIndex].attributes.push({ formServiceProperties.value.stepProperties[stepIndex].properties.push({
type: defaultPropType, type: defaultPropType,
fieldName, fieldName,
options: [], options: [],
@ -208,7 +208,7 @@ function changeType(fieldName: string, stepIndex: number) {
} }
if (defaultPropType === 'string') { if (defaultPropType === 'string') {
formServiceProperties.value.stepProperties[stepIndex].attributes.push({ formServiceProperties.value.stepProperties[stepIndex].properties.push({
type: defaultPropType, type: defaultPropType,
fieldName, fieldName,
isPhoneNumber: false, isPhoneNumber: false,
@ -217,7 +217,7 @@ function changeType(fieldName: string, stepIndex: number) {
} }
if (defaultPropType === 'number') { if (defaultPropType === 'number') {
formServiceProperties.value.stepProperties[stepIndex].attributes.push({ formServiceProperties.value.stepProperties[stepIndex].properties.push({
type: defaultPropType, type: defaultPropType,
fieldName, fieldName,
comma: false, comma: false,
@ -298,7 +298,7 @@ watch(
formServiceProperties.value.stepProperties.push({ formServiceProperties.value.stepProperties.push({
id: s.id, id: s.id,
productsId: [], productsId: [],
attributes: [], properties: [],
}); });
}); });
}, },
@ -366,7 +366,7 @@ watch(
<q-list <q-list
dense dense
v-if=" v-if="
formServiceProperties?.stepProperties[stepIndex].attributes && formServiceProperties?.stepProperties[stepIndex].properties &&
propertiesOption propertiesOption
" "
> >
@ -380,7 +380,7 @@ watch(
<q-icon <q-icon
v-if=" v-if="
formServiceProperties?.stepProperties[stepIndex] formServiceProperties?.stepProperties[stepIndex]
.attributes.length === propertiesOption.length .properties.length === propertiesOption.length
" "
name="mdi-checkbox-marked" name="mdi-checkbox-marked"
size="xs" size="xs"
@ -412,7 +412,7 @@ watch(
formServiceProperties?.stepProperties[stepIndex] && formServiceProperties?.stepProperties[stepIndex] &&
formServiceProperties?.stepProperties[ formServiceProperties?.stepProperties[
stepIndex stepIndex
].attributes.some((add) => add.fieldName === ops.value) ].properties.some((add) => add.fieldName === ops.value)
" "
name="mdi-checkbox-marked" name="mdi-checkbox-marked"
size="xs" size="xs"
@ -443,19 +443,19 @@ watch(
<div <div
v-for="(p, index) in formServiceProperties?.stepProperties[ v-for="(p, index) in formServiceProperties?.stepProperties[
stepIndex stepIndex
].attributes" ].properties"
:key="index" :key="index"
class="bordered surface-1 rounded q-py-sm q-px-md row items-start" class="bordered surface-1 rounded q-py-sm q-px-md row items-start"
:class="{ :class="{
'q-mt-md': index === 0, 'q-mt-md': index === 0,
'q-mb-sm': 'q-mb-sm':
index !== index !==
formServiceProperties.stepProperties[stepIndex].attributes formServiceProperties.stepProperties[stepIndex].properties
.length - .length -
1, 1,
'q-mb-md': 'q-mb-md':
index === index ===
formServiceProperties.stepProperties[stepIndex].attributes formServiceProperties.stepProperties[stepIndex].properties
.length - .length -
1, 1,
}" }"
@ -472,7 +472,7 @@ watch(
style="color: hsl(var(--text-mute-2))" style="color: hsl(var(--text-mute-2))"
@click=" @click="
moveItemUp( moveItemUp(
formServiceProperties.stepProperties[stepIndex].attributes, formServiceProperties.stepProperties[stepIndex].properties,
index, index,
) )
" "
@ -486,14 +486,14 @@ watch(
:size="$q.screen.xs ? 'xs' : ''" :size="$q.screen.xs ? 'xs' : ''"
:disable=" :disable="
index === index ===
formServiceProperties.stepProperties[stepIndex].attributes formServiceProperties.stepProperties[stepIndex].properties
.length - .length -
1 1
" "
style="color: hsl(var(--text-mute-2))" style="color: hsl(var(--text-mute-2))"
@click=" @click="
moveItemDown( moveItemDown(
formServiceProperties.stepProperties[stepIndex].attributes, formServiceProperties.stepProperties[stepIndex].properties,
index, index,
) )
" "
@ -552,13 +552,13 @@ watch(
(t: 'string' | 'number' | 'date' | 'array') => { (t: 'string' | 'number' | 'date' | 'array') => {
if ( if (
!formServiceProperties.stepProperties[stepIndex] !formServiceProperties.stepProperties[stepIndex]
.attributes .properties
) )
return; return;
if (t === 'date') { if (t === 'date') {
formServiceProperties.stepProperties[ formServiceProperties.stepProperties[
stepIndex stepIndex
].attributes[index] = { ].properties[index] = {
type: t, type: t,
fieldName: p.fieldName, fieldName: p.fieldName,
}; };
@ -567,7 +567,7 @@ watch(
if (t === 'array') { if (t === 'array') {
formServiceProperties.stepProperties[ formServiceProperties.stepProperties[
stepIndex stepIndex
].attributes[index] = { ].properties[index] = {
type: t, type: t,
fieldName: p.fieldName, fieldName: p.fieldName,
options: [], options: [],
@ -577,7 +577,7 @@ watch(
if (t === 'string') { if (t === 'string') {
formServiceProperties.stepProperties[ formServiceProperties.stepProperties[
stepIndex stepIndex
].attributes[index] = { ].properties[index] = {
type: t, type: t,
fieldName: p.fieldName, fieldName: p.fieldName,
isPhoneNumber: false, isPhoneNumber: false,
@ -588,7 +588,7 @@ watch(
if (t === 'number') { if (t === 'number') {
formServiceProperties.stepProperties[ formServiceProperties.stepProperties[
stepIndex stepIndex
].attributes[index] = { ].properties[index] = {
type: t, type: t,
fieldName: p.fieldName, fieldName: p.fieldName,
comma: false, comma: false,
@ -786,7 +786,7 @@ watch(
class="q-ml-sm" class="q-ml-sm"
@click=" @click="
confirmDelete( confirmDelete(
formServiceProperties.stepProperties[stepIndex].attributes, formServiceProperties.stepProperties[stepIndex].properties,
index, index,
) )
" "

View file

@ -1,5 +1,4 @@
<script lang="ts" setup> <script lang="ts" setup>
import { QSelect } from 'quasar';
import { storeToRefs } from 'pinia'; import { storeToRefs } from 'pinia';
import { Icon } from '@iconify/vue'; import { Icon } from '@iconify/vue';
import { onMounted, ref, watch } from 'vue'; import { onMounted, ref, watch } from 'vue';
@ -9,9 +8,7 @@ import useProductServiceStore from 'stores/product-service';
import { formatNumberDecimal } from 'stores/utils'; import { formatNumberDecimal } from 'stores/utils';
import { useWorkflowTemplate } from 'src/stores/workflow-template'; import { useWorkflowTemplate } from 'src/stores/workflow-template';
import { Attributes, Product } from 'stores/product-service/types'; import { Attributes, Product } from 'stores/product-service/types';
import { WorkflowTemplate } from 'src/stores/workflow-template/types';
import SelectInput from '../shared/SelectInput.vue';
import NoData from '../NoData.vue'; import NoData from '../NoData.vue';
import { AddButton } from '../button'; import { AddButton } from '../button';
@ -23,7 +20,6 @@ const workflowStore = useWorkflowTemplate();
const { fetchListOfWork } = productServiceStore; const { fetchListOfWork } = productServiceStore;
const { splitPay, workNameItems } = storeToRefs(productServiceStore); const { splitPay, workNameItems } = storeToRefs(productServiceStore);
const { getWorkflowTemplateList } = workflowStore;
const { data: workflowData } = storeToRefs(workflowStore); const { data: workflowData } = storeToRefs(workflowStore);
const props = withDefaults( const props = withDefaults(
@ -72,48 +68,6 @@ defineEmits<{
(e: 'workProperties'): void; (e: 'workProperties'): void;
}>(); }>();
function mapFlowName(id: string): string {
if (!id) return workName.value || '';
const targetFlow = workflowData.value.find((w) => w.id === id);
// workName.value = targetFlow?.name;
return targetFlow?.name || attributes.value.workflowName || '';
}
function mapStepName(id: string) {
const targetFlow = workflowData.value.find(
(w) => w.id === attributes.value.workflowId,
);
if (!targetFlow) return;
const name = targetFlow.step.find((s) => s.id === id)?.name;
return name || '-';
}
function selectFlow(workflow: WorkflowTemplate) {
workName.value = workflow.name;
attributes.value.workflowId = workflow.id;
attributes.value.workflowName = workflow.name;
attributes.value.stepProperties = workflow.step.map((s) => ({
id: s.id,
attributes: [],
productsId: [],
}));
}
async function filter(val: string, update: (...args: unknown[]) => void) {
update(
async () => {
await fetchWorkflowOption(val);
},
(ref: QSelect) => {
if (val !== '' && ref.options && ref.options?.length > 0) {
ref.setOptionIndex(-1);
ref.moveOptionSelection(1, true);
}
},
);
}
async function fetchWorkflowOption(val?: string) { async function fetchWorkflowOption(val?: string) {
const res = await workflowStore.getWorkflowTemplateList({ const res = await workflowStore.getWorkflowTemplateList({
query: val, query: val,
@ -123,13 +77,12 @@ async function fetchWorkflowOption(val?: string) {
} }
function toggleCheckProductInStep(id: string, stepIndex: number) { function toggleCheckProductInStep(id: string, stepIndex: number) {
const index = const index = attributes.value.workflowStep[stepIndex].productsId.indexOf(id);
attributes.value.stepProperties[stepIndex].productsId.indexOf(id);
if (!attributes.value.stepProperties[stepIndex].productsId.includes(id)) { if (!attributes.value.workflowStep[stepIndex].productsId.includes(id)) {
attributes.value.stepProperties[stepIndex].productsId.push(id); attributes.value.workflowStep[stepIndex].productsId.push(id);
} else { } else {
attributes.value.stepProperties[stepIndex].productsId.splice(index, 1); attributes.value.workflowStep[stepIndex].productsId.splice(index, 1);
} }
} }
@ -160,7 +113,7 @@ watch(
() => attributes.value.workflowId, () => attributes.value.workflowId,
() => { () => {
if (props.readonly) return; if (props.readonly) return;
attributes.value.stepProperties.forEach((s) => { attributes.value.workflowStep.forEach((s) => {
s.productsId = productItems.value.map((p) => p.id); s.productsId = productItems.value.map((p) => p.id);
}); });
}, },
@ -582,29 +535,33 @@ watch(
</div> </div>
</template> </template>
<div class="q-py-md q-px-md full-width column"> <div class="q-py-md q-px-md full-width column">
<span <span class="app-text-muted">
v-if=" {{
attributes.stepProperties?.length === 0 || !attributes.workflowId
!attributes.stepProperties ? $t('general.no', { msg: $t('flow.title') })
" : attributes.workflowStep?.length === 0
class="app-text-muted" ? $t('flow.noProcessStep')
> : attributes.workflowStep?.every(
{{ $t('flow.noProcessStep') }} (s) => !s.attributes.properties?.length,
)
? $t('productService.service.noPropertiesYet')
: ''
}}
</span> </span>
<template <template
v-for="(step, stepIndex) in attributes.stepProperties" v-for="(step, stepIndex) in attributes.workflowStep"
:key="step.id" :key="stepIndex"
> >
<span <span
v-if=" v-if="
attributes.stepProperties?.length > 0 && attributes.workflowStep[stepIndex].attributes.properties
step.attributes.length > 0 .length > 0
" "
> >
<q-icon name="mdi-circle-medium" /> <q-icon name="mdi-circle-medium" />
{{ $t('flow.stepNo', { msg: stepIndex + 1 }) }}: {{ $t('flow.stepNo', { msg: stepIndex + 1 }) }}:
{{ mapStepName(step.id) }} {{ step.name }}
<!-- step att --> <!-- step att -->
<section <section
@ -612,13 +569,13 @@ watch(
> >
<div <div
v-if=" v-if="
attributes.stepProperties[stepIndex].attributes.length > attributes.workflowStep[stepIndex].attributes.properties
0 .length > 0
" "
class="row q-gutter-sm" class="row q-gutter-sm"
> >
<span <span
v-for="(att, i) in step.attributes" v-for="(att, i) in step.attributes.properties"
:key="i" :key="i"
class="surface-2 bordered rounded q-px-xs" class="surface-2 bordered rounded q-px-xs"
> >
@ -635,7 +592,7 @@ watch(
class="q-pt-sm q-pl-lg column" class="q-pt-sm q-pl-lg column"
:class="{ :class="{
'q-pb-sm': 'q-pb-sm':
stepIndex !== attributes.stepProperties.length - 1, stepIndex !== attributes.workflowStep.length - 1,
}" }"
> >
<span class="app-text-muted-2 text-caption"> <span class="app-text-muted-2 text-caption">
@ -652,9 +609,10 @@ watch(
> >
<div v-for="product in productItems" :key="product.id"> <div v-for="product in productItems" :key="product.id">
<q-checkbox <q-checkbox
v-if="attributes.workflowStep[stepIndex].productsId"
:disable="readonly" :disable="readonly"
:model-value=" :model-value="
attributes.stepProperties[ attributes.workflowStep[
stepIndex stepIndex
].productsId.includes(product.id) ].productsId.includes(product.id)
" "
@ -675,18 +633,6 @@ watch(
</section> </section>
</span> </span>
</template> </template>
<span
v-if="
attributes.workflowId &&
attributes.stepProperties?.every(
(s) => s.attributes.length === 0,
)
"
class="app-text-muted"
>
{{ $t('productService.service.noPropertiesYet') }}
</span>
</div> </div>
</q-expansion-item> </q-expansion-item>
<!-- <div class="q-py-md q-px-md full-width"> <!-- <div class="q-py-md q-px-md full-width">

View file

@ -4,27 +4,41 @@ import { moveItemUp, moveItemDown, dialog, deleteItem } from 'stores/utils';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import useOptionStore from 'src/stores/options'; import useOptionStore from 'src/stores/options';
import { useWorkflowTemplate } from 'src/stores/workflow-template';
import { Option } from 'stores/options/types'; import { Option } from 'stores/options/types';
import {
WorkFlowPayloadStep,
WorkflowTemplate,
} from 'src/stores/workflow-template/types';
import SelectFlow from '../shared/select/SelectFlow.vue';
import NoData from '../NoData.vue'; import NoData from '../NoData.vue';
import DialogForm from '../DialogForm.vue'; import DialogForm from '../DialogForm.vue';
import { WorkFlowPayloadStep } from 'src/stores/workflow-template/types';
const { t } = useI18n(); const { t } = useI18n();
const { getWorkflowTemplate } = useWorkflowTemplate();
const optionStore = useOptionStore(); const optionStore = useOptionStore();
const props = defineProps<{ const props = defineProps<{
stepIndex?: number; stepIndex?: number;
selectFlow?: boolean;
}>();
const emit = defineEmits<{
(e: 'submit', currWorkflow: WorkflowTemplate): void;
}>(); }>();
const model = defineModel<boolean>({ required: true, default: false }); const model = defineModel<boolean>({ required: true, default: false });
const workflowId = defineModel<string>('workflowId', { default: '' });
const dataStep = defineModel<WorkFlowPayloadStep[]>('dataStep', { const dataStep = defineModel<WorkFlowPayloadStep[]>('dataStep', {
required: true,
default: [], default: [],
}); });
const tempStep = ref<WorkFlowPayloadStep[]>([]); const tempStep = ref<WorkFlowPayloadStep[]>([]);
const tempWorkflowId = ref<string>('');
const propertiesOption = ref(); const propertiesOption = ref();
const currWorkflow = ref<WorkflowTemplate>();
const typeOption = [ const typeOption = [
{ {
label: 'Text', label: 'Text',
@ -53,9 +67,13 @@ const typeOption = [
]; ];
function submit() { function submit() {
workflowId.value = tempWorkflowId.value;
dataStep.value = JSON.parse(JSON.stringify(tempStep.value)); dataStep.value = JSON.parse(JSON.stringify(tempStep.value));
model.value = false; model.value = false;
if (props.selectFlow && currWorkflow.value) {
emit('submit', currWorkflow.value);
}
} }
function close() { function close() {
@ -241,12 +259,37 @@ function confirmDelete(items: unknown[], index: number) {
}); });
} }
function assignTemp() {
propertiesOption.value = optionStore.globalOption?.servicePropertiesField;
tempStep.value = JSON.parse(JSON.stringify(dataStep.value));
tempWorkflowId.value = workflowId.value;
}
watch( watch(
() => model.value, () => model.value,
() => { () => {
if (model.value) { if (model.value) {
propertiesOption.value = optionStore.globalOption?.servicePropertiesField; assignTemp();
tempStep.value = JSON.parse(JSON.stringify(dataStep.value)); }
},
);
watch(
() => tempWorkflowId.value,
async (a, b) => {
if (props.selectFlow && a !== b && a) {
const ret = await getWorkflowTemplate(a);
if (ret) {
currWorkflow.value = ret;
tempStep.value =
ret.step.length > 0
? ret.step.map((s) => ({
name: s.name,
attributes: s.attributes,
}))
: [];
}
} }
}, },
); );
@ -263,8 +306,41 @@ watch(
:close="close" :close="close"
> >
<div class="column"> <div class="column">
<div
v-if="selectFlow"
class="bordered-b surface-3 row items-center no-wrap q-py-sm"
:class="{
'q-px-lg': $q.screen.gt.sm,
'q-px-md': !$q.screen.gt.sm,
}"
>
{{ $t('flow.title') }}
<SelectFlow
style="width: 18vw"
class="q-ml-sm"
v-model:value="tempWorkflowId"
:label="$t('flow.title')"
simple
/>
</div>
<template v-if="$slots.prepend">
<slot name="prepend"></slot>
</template>
<div
v-if="tempStep.length === 0"
class="row surface-1 rounded bordered items-center justify-center col"
:class="{
'q-ma-lg': $q.screen.gt.sm,
'q-ma-md': !$q.screen.gt.sm,
}"
>
<NoData :text="$t('general.no', { msg: $t('flow.processStep') })" />
</div>
<section <section
v-for="(step, stepIndex) in dataStep" v-for="(step, stepIndex) in tempStep"
:key="stepIndex" :key="stepIndex"
class="column" class="column"
> >

View file

@ -0,0 +1,107 @@
<script setup lang="ts">
import { ref, onMounted } from 'vue';
import { createSelect, SelectProps } from './select';
import SelectInput from '../SelectInput.vue';
import { WorkflowTemplate } from 'src/stores/workflow-template/types';
import { useWorkflowTemplate } from 'src/stores/workflow-template';
type SelectOption = WorkflowTemplate;
const value = defineModel<string | null | undefined>('value', {
required: true,
});
const valueOption = defineModel<SelectOption>('valueOption', {
required: false,
});
const selectOptions = ref<SelectOption[]>([]);
const { getWorkflowTemplateList: getList, getWorkflowTemplate: getById } =
useWorkflowTemplate();
defineEmits<{
(e: 'create'): void;
(e: 'updateValue', val: string): void;
}>();
type ExclusiveProps = {
selectFirstValue?: boolean;
};
const props = defineProps<SelectProps<typeof getList> & ExclusiveProps>();
const { getOptions, setFirstValue, getSelectedOption, filter } =
createSelect<SelectOption>(
{
value,
valueOption,
selectOptions,
getList: async (query) => {
const ret = await getList({
query,
...props.params,
});
if (ret) return ret.result;
},
getByValue: async (id) => {
const ret = await getById(id);
if (ret) return ret;
},
},
{ valueField: 'id' },
);
onMounted(async () => {
await getOptions();
if (props.autoSelectOnSingle && selectOptions.value.length === 1) {
setFirstValue();
}
if (props.selectFirstValue) {
setDefaultValue();
} else await getSelectedOption();
});
function setDefaultValue() {
setFirstValue();
}
</script>
<template>
<SelectInput
v-model="value"
incremental
:label
:placeholder
:readonly
:disable="disabled"
:option="
selectOptions.map((v) => {
const ret = {
label: v.name,
value: v.id,
};
return ret;
})
"
:hide-selected="false"
:fill-input="false"
:rules="
required ? [(v: string) => !!v || $t('form.error.required')] : undefined
"
@filter="filter"
@update:model-value="(v) => $emit('updateValue', v as string)"
>
<template #append v-if="clearable">
<q-icon
v-if="!readonly && value"
name="mdi-close-circle"
@click.stop="value = ''"
class="cursor-pointer clear-btn"
/>
</template>
</SelectInput>
</template>

View file

@ -1,10 +1,12 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref, watch, reactive } from 'vue'; import { nextTick, ref, watch, reactive } from 'vue';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import { onMounted } from 'vue'; import { onMounted } from 'vue';
import { storeToRefs } from 'pinia'; import { storeToRefs } from 'pinia';
import { useQuasar, type QTableProps } from 'quasar'; 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 ProductCardComponent from 'components/04_product-service/ProductCardComponent.vue';
import StatCard from 'components/StatCardComponent.vue'; import StatCard from 'components/StatCardComponent.vue';
import DrawerInfo from 'components/DrawerInfo.vue'; import DrawerInfo from 'components/DrawerInfo.vue';
@ -14,7 +16,6 @@ import BasicInfoProduct from 'components/04_product-service/BasicInfoProduct.vue
import PriceDataComponent from 'components/04_product-service/PriceDataComponent.vue'; import PriceDataComponent from 'components/04_product-service/PriceDataComponent.vue';
import TotalProductCardComponent from 'components/04_product-service/TotalProductCardComponent.vue'; import TotalProductCardComponent from 'components/04_product-service/TotalProductCardComponent.vue';
import FormServiceWork from 'components/04_product-service/FormServiceWork.vue'; import FormServiceWork from 'components/04_product-service/FormServiceWork.vue';
import ServiceProperties from 'components/04_product-service/ServiceProperties.vue';
import WorkNameManagement from 'components/04_product-service/WorkNameManagement.vue'; import WorkNameManagement from 'components/04_product-service/WorkNameManagement.vue';
import useOptionStore from 'stores/options'; import useOptionStore from 'stores/options';
import FormServiceProperties from 'components/04_product-service/FormServiceProperties.vue'; import FormServiceProperties from 'components/04_product-service/FormServiceProperties.vue';
@ -40,6 +41,7 @@ import useFlowStore from 'stores/flow';
import { dateFormat } from 'src/utils/datetime'; import { dateFormat } from 'src/utils/datetime';
import { formatNumberDecimal, isRoleInclude } from 'stores/utils'; import { formatNumberDecimal, isRoleInclude } from 'stores/utils';
const { getWorkflowTemplate } = useWorkflowTemplate();
import { Status } from 'stores/types'; import { Status } from 'stores/types';
@ -60,6 +62,7 @@ import {
} from 'stores/product-service/types'; } from 'stores/product-service/types';
import { computed } from 'vue'; import { computed } from 'vue';
import { WorkflowTemplate } from 'src/stores/workflow-template/types'; import { WorkflowTemplate } from 'src/stores/workflow-template/types';
import { useWorkflowTemplate } from 'src/stores/workflow-template';
const flowStore = useFlowStore(); const flowStore = useFlowStore();
const navigatorStore = useNavigator(); const navigatorStore = useNavigator();
@ -261,15 +264,14 @@ const formDataProduct = ref<ProductCreate>({
image: undefined, image: undefined,
}); });
const workflow = ref<WorkflowTemplate>(); const currWorkflow = ref<WorkflowTemplate>();
const formDataProductService = ref<ServiceCreate>({ const formDataProductService = ref<ServiceCreate>({
work: [], work: [],
attributes: { attributes: {
showTotalPrice: false, showTotalPrice: false,
additional: [], additional: [],
workflowId: '', workflowId: '',
workflowName: '', workflowStep: [],
stepProperties: [],
}, },
detail: '', detail: '',
name: '', name: '',
@ -860,10 +862,9 @@ const prevService = ref<ServiceCreate>({
work: [], work: [],
attributes: { attributes: {
showTotalPrice: false, showTotalPrice: false,
workflowName: '',
workflowId: '', workflowId: '',
stepProperties: [],
additional: [], additional: [],
workflowStep: [],
}, },
detail: '', detail: '',
name: '', name: '',
@ -1019,16 +1020,16 @@ function clearFormProduct() {
} }
function clearFormService() { function clearFormService() {
currWorkflow.value = undefined;
formDataProductService.value = { formDataProductService.value = {
code: '', code: '',
name: '', name: '',
detail: '', detail: '',
attributes: { attributes: {
workflowName: '',
workflowId: '', workflowId: '',
stepProperties: [],
additional: [], additional: [],
showTotalPrice: false, showTotalPrice: false,
workflowStep: [],
}, },
work: [], work: [],
status: undefined, status: undefined,
@ -1183,8 +1184,11 @@ function submitAddWorkProduct() {
installmentNo: splitPay.value > 0 ? 1 : 0, installmentNo: splitPay.value > 0 ? 1 : 0,
nameEn: '', nameEn: '',
}); });
workItems.value[currentWorkIndex.value].attributes.stepProperties.forEach( workItems.value[currentWorkIndex.value].attributes.workflowStep.forEach(
(s) => { (s) => {
if (!s.hasOwnProperty('productsId')) {
s.productsId = [];
}
s.productsId.push(i.id); s.productsId.push(i.id);
}, },
); );
@ -1192,7 +1196,7 @@ function submitAddWorkProduct() {
}); });
// filter remain product // filter remain product
workItems.value[currentWorkIndex.value].attributes.stepProperties.forEach( workItems.value[currentWorkIndex.value].attributes.workflowStep.forEach(
(s) => { (s) => {
s.productsId = s.productsId.filter((pid) => s.productsId = s.productsId.filter((pid) =>
selectProduct.value.some((i) => i.id === pid), selectProduct.value.some((i) => i.id === pid),
@ -1254,10 +1258,9 @@ function triggerConfirmCloseWork() {
const tempValueProperties = ref<Attributes>({ const tempValueProperties = ref<Attributes>({
showTotalPrice: false, showTotalPrice: false,
workflowName: '',
workflowId: '', workflowId: '',
stepProperties: [],
additional: [], additional: [],
workflowStep: [],
}); });
const currentPropertiesMode = ref<'service' | 'work'>('service'); const currentPropertiesMode = ref<'service' | 'work'>('service');
@ -1331,7 +1334,7 @@ async function alternativeFetch() {
} }
} }
function cloneServiceData() { async function cloneServiceData() {
if (!currentService.value) return; if (!currentService.value) return;
const currentSelectedImage = formDataProductService.value.selectedImage; const currentSelectedImage = formDataProductService.value.selectedImage;
formDataProductService.value = { formDataProductService.value = {
@ -1340,6 +1343,7 @@ function cloneServiceData() {
}; };
formDataProductService.value.selectedImage = currentSelectedImage; formDataProductService.value.selectedImage = currentSelectedImage;
await nextTick();
workItems.value = currentService.value.work.map((item) => { workItems.value = currentService.value.work.map((item) => {
return { return {
id: item.id, id: item.id,
@ -1565,6 +1569,34 @@ watch(
if (profileFileImg.value !== null) isImageEdit.value = true; if (profileFileImg.value !== null) isImageEdit.value = true;
}, },
); );
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: [],
})),
),
)
: [];
});
}
}
watch(
() => formDataProductService.value.attributes.workflowId,
async (a, b) => {
if (a && a !== b) {
handleChangeWorkflowId(a);
}
},
);
</script> </script>
<template> <template>
@ -3982,6 +4014,7 @@ watch(
</div> </div>
<SaveButton id="btn-info-basic-save" icon-only type="submit" /> <SaveButton id="btn-info-basic-save" icon-only type="submit" />
</div> </div>
<BasicInformation <BasicInformation
v-if="serviceTab === 1" v-if="serviceTab === 1"
dense dense
@ -3991,10 +4024,30 @@ watch(
v-model:service-name-th="formDataProductService.name" 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 <FormServiceWork
v-if="serviceTab === 2" v-if="serviceTab === 2"
ref="refAddServiceWork" ref="refAddServiceWork"
v-model:work-items="workItems" v-model:work-items="workItems"
v-model:workflow="currWorkflow"
:tree-view="serviceTreeView" :tree-view="serviceTreeView"
:service="formDataProductService" :service="formDataProductService"
dense dense
@ -4048,43 +4101,19 @@ watch(
</div> --> </div> -->
</DialogForm> </DialogForm>
<!-- service properties --> <!-- service properties, work properties -->
<DialogForm <DialogProperties
no-address v-if="workItems[currentWorkIndex]"
no-app-box selectFlow
height="75vh" v-model:data-step="workItems[currentWorkIndex].attributes.workflowStep"
width="75%" v-model:workflow-id="formDataProductService.attributes.workflowId"
:title="$t('productService.service.properties')" v-model="propertiesDialog"
v-model:modal="propertiesDialog" @submit="
:submit=" (v) => {
() => { currWorkflow = v;
if (currentPropertiesMode === 'service') {
formDataProductService.attributes = JSON.parse(
JSON.stringify(tempValueProperties),
);
}
if (currentPropertiesMode === 'work') {
workItems[currentWorkIndex].attributes = JSON.parse(
JSON.stringify(tempValueProperties),
);
}
propertiesDialog = false;
} }
" "
:close=" ></DialogProperties>
() => {
propertiesDialog = false;
}
"
>
<section class="col column">
<ServiceProperties
v-model:properties-option="propertiesOption"
v-model:form-service-properties="tempValueProperties"
/>
</section>
</DialogForm>
<!-- manage work name --> <!-- manage work name -->
<DialogForm <DialogForm
@ -4387,15 +4416,36 @@ watch(
v-model:service-name-th="formDataProductService.name" 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 <FormServiceWork
v-if="serviceTab === 2" v-if="serviceTab === 2"
ref="refEditServiceWork" ref="refEditServiceWork"
v-model:work-items="workItems"
v-model:workflow="currWorkflow"
:service="formDataProductService" :service="formDataProductService"
:tree-view="serviceTreeView" :tree-view="serviceTreeView"
:readonly="!infoServiceEdit" :readonly="!infoServiceEdit"
v-model:work-items="workItems"
dense
:price-display="priceDisplay" :price-display="priceDisplay"
dense
@add-product=" @add-product="
async (index) => { async (index) => {
await fetchListOfProductIsAdd(currentIdGroup); await fetchListOfProductIsAdd(currentIdGroup);

View file

@ -1,5 +1,6 @@
import { Status } from '../types'; import { Status } from '../types';
import { UpdatedBy, CreatedBy } from 'stores/types'; import { UpdatedBy, CreatedBy } from 'stores/types';
import { WorkFlowPayloadStep } from '../workflow-template/types';
export interface TreeProduct { export interface TreeProduct {
name: string; name: string;
@ -73,12 +74,7 @@ export interface Attributes {
showTotalPrice: boolean; showTotalPrice: boolean;
additional?: (PropString | PropNumber | PropDate | PropOptions)[]; additional?: (PropString | PropNumber | PropDate | PropOptions)[];
workflowId: string; workflowId: string;
workflowName: string; workflowStep: (WorkFlowPayloadStep & { productsId: string[] })[];
stepProperties: {
id: string;
productsId: string[];
attributes: (PropString | PropNumber | PropDate | PropOptions)[];
}[];
} }
export type PropString = { export type PropString = {