feat: 09 => edit task order (order)

This commit is contained in:
puriphatt 2025-01-23 14:23:18 +07:00
parent c7438edd79
commit 4e8e270d62
4 changed files with 124 additions and 44 deletions

View file

@ -22,6 +22,18 @@ const emit = defineEmits<{
}>(); }>();
const props = defineProps<{ 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; creditNote?: boolean;
fetchParams?: Parameters<typeof requestListStore.getRequestWorkList>[0]; fetchParams?: Parameters<typeof requestListStore.getRequestWorkList>[0];
}>(); }>();
@ -39,6 +51,20 @@ const taskList = defineModel<
}); });
const open = defineModel<boolean>('open', { default: false }); const open = defineModel<boolean>('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< const selectedEmployee = ref<
(RequestWork & { (RequestWork & {
taskStatus: TaskStatus; taskStatus: TaskStatus;
@ -56,15 +82,28 @@ let group = computed(() =>
data.value.reduce< data.value.reduce<
{ {
product: RequestWork['productService']['product']; product: RequestWork['productService']['product'];
list: RequestWork[]; list: (RequestWork & {
_template?: {
id: string;
templateName: string;
templateStepName: string;
step: number;
responsibleInstitution: (string | { group: string })[];
} | null;
})[];
}[] }[]
>((acc, curr) => { >((acc, curr) => {
let exist = acc.find( let exist = acc.find(
(item) => curr.productService.productId == item.product.id, (item) => curr.productService.productId == item.product.id,
); );
if (exist) exist.list.push(curr); if (exist) exist.list.push({ ...curr, _template: getTemplateData(curr) });
else acc.push({ product: curr.productService.product, list: [curr] }); else
acc.push({
product: curr.productService.product,
// list: [curr],
list: [{ ...curr, _template: getTemplateData(curr) }],
});
return acc; return acc;
}, []), }, []),
@ -74,7 +113,12 @@ let state = reactive({
search: '', search: '',
}); });
onMounted(getList); onMounted(async () => {
await getList();
if (tempGroupEdit.value.length === 0) {
tempGroupEdit.value = JSON.parse(JSON.stringify(group.value));
}
});
watch(() => state.search, getList); watch(() => state.search, getList);
async function getList() { async function getList() {
@ -90,35 +134,11 @@ async function getList() {
data.value = res.result; 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) { function getStep(requestWork: RequestWork) {
const target = requestWork.stepStatus.find( const target = requestWork.stepStatus.find(
(v) => v.workStatus === RequestWorkStatus.Ready, (v) =>
v.workStatus === RequestWorkStatus.Ready ||
v.workStatus === RequestWorkStatus.InProgress,
); );
return target?.step || 0; return target?.step || 0;
} }
@ -135,6 +155,7 @@ function getTemplateData(requestWork: RequestWork) {
step: step.order, step: step.order,
templateName: flow.name, templateName: flow.name,
templateStepName: step.name || '-', templateStepName: step.name || '-',
responsibleInstitution: step.responsibleInstitution || [],
}; };
} }
@ -149,17 +170,22 @@ function submit() {
const curr = v.stepStatus.find( const curr = v.stepStatus.find(
(s) => (s) =>
s.workStatus === s.workStatus ===
(props.creditNote (props.creditNote
? RequestWorkStatus.Canceled ? RequestWorkStatus.Canceled
: RequestWorkStatus.Ready), : RequestWorkStatus.Ready) ||
s.workStatus ===
(props.creditNote
? RequestWorkStatus.Canceled
: RequestWorkStatus.InProgress),
); );
if (curr) { if (curr) {
const task: Task = { const task: Task = {
...curr, ...curr,
attributes: curr.attributes, attributes: curr.attributes,
workStatus: props.creditNote workStatus:
? RequestWorkStatus.Canceled curr.workStatus || props.creditNote
: RequestWorkStatus.Ready, ? RequestWorkStatus.Ready
: RequestWorkStatus.Canceled,
taskOrderId: '', taskOrderId: '',
requestWork: selectedEmployee.value[i], requestWork: selectedEmployee.value[i],
}; };
@ -183,9 +209,13 @@ function close() {
} }
function onDialogOpen() { function onDialogOpen() {
// assign selected to group
assignTempGroup();
// match group to check
selectedEmployee.value = []; selectedEmployee.value = [];
if (taskList.value.length === 0) return; if (taskList.value.length === 0) return;
const matchingItems = group.value const matchingItems = tempGroupEdit.value
.flatMap((g) => g.list) .flatMap((g) => g.list)
.filter((l) => .filter((l) =>
l.stepStatus.some((s) => l.stepStatus.some((s) =>
@ -194,6 +224,27 @@ function onDialogOpen() {
); );
selectedEmployee.value = JSON.parse(JSON.stringify(matchingItems)); 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
});
}
});
}
</script> </script>
<template> <template>
@ -205,9 +256,9 @@ function onDialogOpen() {
</template> </template>
<section class="col column full-width no-wrap surface-2 scroll"> <section class="col column full-width no-wrap surface-2 scroll">
<template v-if="group.length > 0"> <template v-if="tempGroupEdit.length > 0">
<div <div
v-for="{ product, list } in group" v-for="{ product, list } in tempGroupEdit"
:key="product.id" :key="product.id"
class="bordered-b" class="bordered-b"
> >

View file

@ -103,7 +103,14 @@ export const useTaskOrderForm = defineStore('task-order-form', () => {
} }
if (state.value.mode === 'edit' && !!currentFormData.value.id) { if (state.value.mode === 'edit' && !!currentFormData.value.id) {
const res = await taskOrderStore.editTaskOrder(currentFormData.value); const taskProduct = opt?.taskProduct?.map((p) => ({
productId: p.productId,
discount: p.discount,
}));
const res = await taskOrderStore.editTaskOrder({
...currentFormData.value,
taskProduct: taskProduct,
});
if (res) { if (res) {
succeed = true; succeed = true;
} }

View file

@ -20,6 +20,7 @@ import {
MainButton, MainButton,
EditButton, EditButton,
UndoButton, UndoButton,
CancelButton,
} from 'src/components/button'; } from 'src/components/button';
import FormGroupHead from 'src/pages/08_request-list/FormGroupHead.vue'; import FormGroupHead from 'src/pages/08_request-list/FormGroupHead.vue';
import FailRemarkDialog from '../receive_view/FailRemarkDialog.vue'; import FailRemarkDialog from '../receive_view/FailRemarkDialog.vue';
@ -75,6 +76,20 @@ const taskStatusRecords = ref<
failedType?: string; failedType?: string;
}[] }[]
>([]); >([]);
const tempGroupEdit = ref<
{
product: RequestWork['productService']['product'];
list: (RequestWork & {
_template?: {
id: string;
templateName: string;
templateStepName: string;
step: number;
responsibleInstitution: (string | { group: string })[];
} | null;
})[];
}[]
>([]);
const pageState = reactive({ const pageState = reactive({
productDialog: false, productDialog: false,
@ -856,7 +871,7 @@ watch([currentFormData.value.taskStatus], () => {
" "
> >
<DocumentExpansion <DocumentExpansion
:readonly="state.mode !== 'create'" :readonly="!['create', 'edit'].includes(state.mode || '')"
v-model:registered-branch-id="currentFormData.registeredBranchId" v-model:registered-branch-id="currentFormData.registeredBranchId"
v-model:institution-id="currentFormData.institutionId" v-model:institution-id="currentFormData.institutionId"
v-model:task-name="currentFormData.taskName" v-model:task-name="currentFormData.taskName"
@ -947,7 +962,7 @@ watch([currentFormData.value.taskStatus], () => {
view === TaskOrderStatus.Pending || view === TaskOrderStatus.Pending ||
view === TaskOrderStatus.Complete view === TaskOrderStatus.Complete
" "
:readonly="false" :readonly="!['create', 'edit'].includes(state.mode || '')"
/> />
<template <template
@ -1185,7 +1200,11 @@ watch([currentFormData.value.taskStatus], () => {
/> />
</template> </template>
<SaveButton <SaveButton
v-if="state.mode !== 'create' && view === TaskOrderStatus.Validate" v-if="
state.mode !== 'create' &&
view === TaskOrderStatus.Validate &&
fullTaskOrder?.taskOrderStatus !== TaskOrderStatus.Pending
"
:disabled=" :disabled="
!fullTaskOrder?.taskList.some((t) => !fullTaskOrder?.taskList.some((t) =>
[ [
@ -1228,9 +1247,11 @@ watch([currentFormData.value.taskStatus], () => {
<!-- SEC: Dialog --> <!-- SEC: Dialog -->
<SelectReadyRequestWork <SelectReadyRequestWork
:task-list-group="taskListGroup"
:fetch-params="{ readyToTask: true }" :fetch-params="{ readyToTask: true }"
v-model:open="pageState.productDialog" v-model:open="pageState.productDialog"
v-model:task-list="currentFormData.taskList" v-model:task-list="currentFormData.taskList"
v-model:temp-group-edit="tempGroupEdit"
@after-submit=" @after-submit="
() => { () => {
taskProduct = []; taskProduct = [];

View file

@ -113,6 +113,7 @@ export const useTaskOrderStore = defineStore('taskorder-store', () => {
contactName: body.contactName, contactName: body.contactName,
taskStatus: body.taskStatus, taskStatus: body.taskStatus,
taskName: body.taskName, taskName: body.taskName,
taskProduct: body.taskProduct,
}); });
if (res.status < 400) { if (res.status < 400) {