From 5c9c035d2b134edbf92a06d363bb8db875c89cd0 Mon Sep 17 00:00:00 2001 From: puriphatt Date: Thu, 23 Jan 2025 14:51:08 +0700 Subject: [PATCH] fix: handle optional taskListGroup and creditNote checks in file uploads --- .../09_task-order/SelectReadyRequestWork.vue | 5 ++- .../09_task-order/order_view/MainPage.vue | 40 ++++++++++-------- src/pages/11_credit-note/FormPage.vue | 42 ++++++++++--------- 3 files changed, 49 insertions(+), 38 deletions(-) diff --git a/src/pages/09_task-order/SelectReadyRequestWork.vue b/src/pages/09_task-order/SelectReadyRequestWork.vue index 54f3fa2b..4ad33238 100644 --- a/src/pages/09_task-order/SelectReadyRequestWork.vue +++ b/src/pages/09_task-order/SelectReadyRequestWork.vue @@ -22,7 +22,7 @@ const emit = defineEmits<{ }>(); const props = defineProps<{ - taskListGroup: { + taskListGroup?: { product: RequestWork['productService']['product']; list: (RequestWork & { _template?: { @@ -210,7 +210,7 @@ function close() { function onDialogOpen() { // assign selected to group - assignTempGroup(); + !props.creditNote && assignTempGroup(); // match group to check selectedEmployee.value = []; @@ -226,6 +226,7 @@ function onDialogOpen() { } function assignTempGroup() { + if (!props.taskListGroup) return; props.taskListGroup.forEach((newGroup) => { const existingGroup = tempGroupEdit.value.find( (g) => g.product.id === newGroup.product.id, diff --git a/src/pages/09_task-order/order_view/MainPage.vue b/src/pages/09_task-order/order_view/MainPage.vue index 66eef2a7..16dcdadd 100644 --- a/src/pages/09_task-order/order_view/MainPage.vue +++ b/src/pages/09_task-order/order_view/MainPage.vue @@ -906,11 +906,11 @@ watch([currentFormData.value.taskStatus], () => { /> { fileList = f; - fileData = []; - Array.from(f).forEach((el) => { - fileData.push({ - name: el.name, - progress: 1, - loaded: 0, - total: el.size, - placeholder: true, - url: fileToUrl(el), + if (!currentFormData.id) { + fileData = []; + + Array.from(f).forEach((el) => { + fileData.push({ + name: el.name, + progress: 1, + loaded: 0, + total: el.size, + placeholder: true, + url: fileToUrl(el), + }); }); - }); - - if (!currentFormData.id) return; - - await uploadFile(currentFormData.id, f); + } else { + await uploadFile(currentFormData.id, f); + } } " @remove=" async (n) => { - if (!currentFormData.id) return; - await remove(currentFormData.id, n); + if (!currentFormData.id) { + const attIndex = fileData.findIndex((v) => v.name === n); + + fileData.splice(attIndex, 1); + } else { + await remove(currentFormData.id, n); + } } " /> diff --git a/src/pages/11_credit-note/FormPage.vue b/src/pages/11_credit-note/FormPage.vue index b775184f..ae336397 100644 --- a/src/pages/11_credit-note/FormPage.vue +++ b/src/pages/11_credit-note/FormPage.vue @@ -674,32 +674,36 @@ onMounted(async () => { @upload=" async (f) => { attachmentList = f; - attachmentData = []; - Array.from(f).forEach((el) => { - attachmentData.push({ - name: el.name, - progress: 1, - loaded: 0, - total: el.size, - placeholder: true, - url: fileToUrl(el), + if (!creditNoteData) { + attachmentData = []; + + Array.from(f).forEach((el) => { + attachmentData.push({ + name: el.name, + progress: 1, + loaded: 0, + total: el.size, + placeholder: true, + url: fileToUrl(el), + }); }); - }); - - if (!creditNoteData) return; - - await uploadFile(creditNoteData.id, f); + } else { + await uploadFile(creditNoteData.id, f); + } } " @remove=" async (n) => { - const attIndex = attachmentData.findIndex((v) => v.name === n); + if (!creditNoteData) { + const attIndex = attachmentData.findIndex( + (v) => v.name === n, + ); - attachmentData.splice(attIndex, 1); - - if (!creditNoteData) return; - await remove(creditNoteData.id, n); + attachmentData.splice(attIndex, 1); + } else { + await remove(creditNoteData.id, n); + } } " />