refactor: signal success all status

This commit is contained in:
Thanaphon Frappet 2024-11-28 15:53:22 +07:00
parent ba64702287
commit 9eb2ddea61
2 changed files with 30 additions and 1 deletions

View file

@ -36,6 +36,7 @@ import {
PropOptions,
PropString,
} from 'src/stores/product-service/types';
import { computed, nextTick } from 'vue';
const { locale } = useI18n();
@ -173,6 +174,11 @@ async function triggerChangeStatusWork(step: Step) {
res.workStatus;
}
}
await nextTick();
if (successAll.value) {
await requestListStore.editStatusRequestWork(step, !!successAll.value);
}
}
async function triggerChangeStatusFile(opt: {
@ -247,6 +253,27 @@ async function triggerViewFile(opt: {
if (!opt.download) window.open(url, '_blank');
}
const successAll = computed(() => {
return !!flow.value?.step.every((_, i) => {
return workList.value
?.filter((v) => {
return v.productService.work?.attributes.workflowStep?.[
i
]?.productsId.includes(v.productService.productId);
})
.every((v) => {
const status = v.stepStatus.find(
({ step }) => step === i + 1,
)?.workStatus;
return (
status === RequestWorkStatus.Completed ||
status === RequestWorkStatus.Ended
);
});
});
});
</script>
<template>
<div class="column surface-0 fullscreen" v-if="data">
@ -484,6 +511,7 @@ async function triggerViewFile(opt: {
? pageState.currentStep
: v.step.step,
requestWorkId: value.id || '',
su,
});
}
"

View file

@ -236,7 +236,7 @@ export const useRequestList = defineStore('request-list', () => {
return null;
}
async function editStatusRequestWork(body: Step) {
async function editStatusRequestWork(body: Step, successAll?: boolean) {
const res = await api.put<Step>(
`/request-work/${body.requestWorkId}/step-status/${body.step}`,
{
@ -245,6 +245,7 @@ export const useRequestList = defineStore('request-list', () => {
requestWorkId: undefined,
step: undefined,
},
{ params: { successAll } },
);
if (res.status < 400) return res.data;