From 1458a3240365f1bda016a324c9a794c05a54b742 Mon Sep 17 00:00:00 2001 From: puriphatt Date: Fri, 27 Dec 2024 10:26:26 +0700 Subject: [PATCH] feat: order => add validation and status change handling in TableEmployee component --- src/pages/09_task-order/TableEmployee.vue | 43 +++++- .../09_task-order/order_view/MainPage.vue | 132 +++++++++++++----- 2 files changed, 140 insertions(+), 35 deletions(-) diff --git a/src/pages/09_task-order/TableEmployee.vue b/src/pages/09_task-order/TableEmployee.vue index 4fcbdc36..f98831a8 100644 --- a/src/pages/09_task-order/TableEmployee.vue +++ b/src/pages/09_task-order/TableEmployee.vue @@ -15,6 +15,7 @@ import { TaskStatus } from 'src/stores/task-order/types'; const props = withDefaults( defineProps<{ + validate?: boolean; checkboxOn?: boolean; checkAll?: boolean; stepOn?: boolean; @@ -210,7 +211,47 @@ function handleCheck( class="" > - + + + + {{ $t(`taskOrder.status.Complete`) }} + + + + {{ $t(`taskOrder.status.Redo`) }} + + + ([]); const summaryPrice = computed(() => getPrice(taskListGroup.value)); +const selectedEmployee = ref< + (RequestWork & { + _template?: { + id: string; + templateName: string; + templateStepName: string; + step: number; + } | null; + })[][][] +>([]); +const failedDialog = ref(false); +const taskStatusRecords = ref< + { + requestWorkId: string; + step: number; + failedComment?: string; + failedType?: string; + code?: string; + }[] +>([]); + function getPrice( list: { product: RequestWork['productService']['product']; @@ -199,6 +221,9 @@ const messengerListGroup = computed(() => }, ], }); + if (selectedEmployee.value.length < acc.length) { + selectedEmployee.value.push([[]]); + } } if (indexUser !== -1) { @@ -578,13 +603,50 @@ function taskStatusCount(index: number, id: string) { } } +function viewDocument(id: string, routeName: 'order' | 'receive') { + window.open(`/task-order/${id}/doc-product-${routeName}`, '_blank'); +} + +function handleChangeStatus( + records: { + data: (RequestWork & { + _template?: { + id: string; + templateName: string; + templateStepName: string; + step: number; + } | null; + })[]; + status: TaskStatus; + }, + messengerIndex: number, + productIndex: number, +) { + const { data, status } = records; + + if (data.length === 0) return; + + taskStatusRecords.value = data.map((v) => ({ + code: `${v.productService.product.code}-${v.request.code}`, + requestWorkId: v.id || '', + step: v._template?.step || 0, + })); + + if (status === TaskStatus.Failed) { + failedDialog.value = true; + return; + } + + taskOrderFormStore.changeStatus(taskStatusRecords.value, status, () => { + if (!currentFormData.value.id) return; + selectedEmployee.value[messengerIndex][productIndex] = []; + taskOrderFormStore.assignFormData(currentFormData.value.id, 'info'); + }); +} + watch([currentFormData.value.taskStatus], () => { fetchStatus(); }); - -function viewDocument(id: string, routeName: 'order' | 'receive') { - window.open(`/task-order/${id}/doc-prouct-${routeName}`, '_blank'); -}