diff --git a/src/pages/09_task-order/SelectReadyRequestWork.vue b/src/pages/09_task-order/SelectReadyRequestWork.vue index b79133c1..54f3fa2b 100644 --- a/src/pages/09_task-order/SelectReadyRequestWork.vue +++ b/src/pages/09_task-order/SelectReadyRequestWork.vue @@ -22,6 +22,18 @@ const emit = defineEmits<{ }>(); const props = defineProps<{ + taskListGroup: { + product: RequestWork['productService']['product']; + list: (RequestWork & { + _template?: { + id: string; + templateName: string; + templateStepName: string; + step: number; + responsibleInstitution: (string | { group: string })[]; + } | null; + })[]; + }[]; creditNote?: boolean; fetchParams?: Parameters[0]; }>(); @@ -39,6 +51,20 @@ const taskList = defineModel< }); const open = defineModel('open', { default: false }); +const tempGroupEdit = defineModel< + { + product: RequestWork['productService']['product']; + list: (RequestWork & { + _template?: { + id: string; + templateName: string; + templateStepName: string; + step: number; + responsibleInstitution: (string | { group: string })[]; + } | null; + })[]; + }[] +>('tempGroupEdit', { default: [] }); const selectedEmployee = ref< (RequestWork & { taskStatus: TaskStatus; @@ -56,15 +82,28 @@ let group = computed(() => data.value.reduce< { product: RequestWork['productService']['product']; - list: RequestWork[]; + list: (RequestWork & { + _template?: { + id: string; + templateName: string; + templateStepName: string; + step: number; + responsibleInstitution: (string | { group: string })[]; + } | null; + })[]; }[] >((acc, curr) => { let exist = acc.find( (item) => curr.productService.productId == item.product.id, ); - if (exist) exist.list.push(curr); - else acc.push({ product: curr.productService.product, list: [curr] }); + if (exist) exist.list.push({ ...curr, _template: getTemplateData(curr) }); + else + acc.push({ + product: curr.productService.product, + // list: [curr], + list: [{ ...curr, _template: getTemplateData(curr) }], + }); return acc; }, []), @@ -74,7 +113,12 @@ let state = reactive({ search: '', }); -onMounted(getList); +onMounted(async () => { + await getList(); + if (tempGroupEdit.value.length === 0) { + tempGroupEdit.value = JSON.parse(JSON.stringify(group.value)); + } +}); watch(() => state.search, getList); async function getList() { @@ -90,35 +134,11 @@ async function getList() { data.value = res.result; } -// function toggle(item: RequestWork) { -// switch (selected(item)) { -// case true: -// return deselect(item); -// case false: -// return select(item); -// } -// } - -// function select(item: RequestWork) { -// if (selected(item)) return; -// selectedEmployee.value = selectedEmployee.value -// ? selectedEmployee.value.concat(item) -// : [item]; -// } - -// function deselect(item: RequestWork) { -// const idx = selectedEmployee.value?.findIndex((v) => v.id === item.id); -// if (idx !== -1) selectedEmployee.value?.splice(idx, 1); -// } - -// function selected(item: RequestWork): boolean { -// return !!selectedEmployee.value?.some((v) => v.id === item.id); -// } -// - function getStep(requestWork: RequestWork) { const target = requestWork.stepStatus.find( - (v) => v.workStatus === RequestWorkStatus.Ready, + (v) => + v.workStatus === RequestWorkStatus.Ready || + v.workStatus === RequestWorkStatus.InProgress, ); return target?.step || 0; } @@ -135,6 +155,7 @@ function getTemplateData(requestWork: RequestWork) { step: step.order, templateName: flow.name, templateStepName: step.name || '-', + responsibleInstitution: step.responsibleInstitution || [], }; } @@ -149,17 +170,22 @@ function submit() { const curr = v.stepStatus.find( (s) => s.workStatus === - (props.creditNote - ? RequestWorkStatus.Canceled - : RequestWorkStatus.Ready), + (props.creditNote + ? RequestWorkStatus.Canceled + : RequestWorkStatus.Ready) || + s.workStatus === + (props.creditNote + ? RequestWorkStatus.Canceled + : RequestWorkStatus.InProgress), ); if (curr) { const task: Task = { ...curr, attributes: curr.attributes, - workStatus: props.creditNote - ? RequestWorkStatus.Canceled - : RequestWorkStatus.Ready, + workStatus: + curr.workStatus || props.creditNote + ? RequestWorkStatus.Ready + : RequestWorkStatus.Canceled, taskOrderId: '', requestWork: selectedEmployee.value[i], }; @@ -183,9 +209,13 @@ function close() { } function onDialogOpen() { + // assign selected to group + assignTempGroup(); + + // match group to check selectedEmployee.value = []; if (taskList.value.length === 0) return; - const matchingItems = group.value + const matchingItems = tempGroupEdit.value .flatMap((g) => g.list) .filter((l) => l.stepStatus.some((s) => @@ -194,6 +224,27 @@ function onDialogOpen() { ); selectedEmployee.value = JSON.parse(JSON.stringify(matchingItems)); } + +function assignTempGroup() { + props.taskListGroup.forEach((newGroup) => { + const existingGroup = tempGroupEdit.value.find( + (g) => g.product.id === newGroup.product.id, + ); + + if (existingGroup) { + newGroup.list.forEach((newItem) => { + if (!existingGroup.list.some((item) => item.id === newItem.id)) { + existingGroup.list.push(newItem); + } + }); + } else { + tempGroupEdit.value.push({ + ...newGroup, + list: [...newGroup.list], // Ensure a new reference + }); + } + }); +}
-