fix: handle optional taskListGroup and creditNote checks in file uploads

This commit is contained in:
puriphatt 2025-01-23 14:51:08 +07:00
parent 4e8e270d62
commit 5c9c035d2b
3 changed files with 49 additions and 38 deletions

View file

@ -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,

View file

@ -906,11 +906,11 @@ watch([currentFormData.value.taskStatus], () => {
/>
<AdditionalFileExpansion
:readonly="!['create', 'edit'].includes(state.mode || '')"
v-if="
view === TaskOrderStatus.Pending ||
view === TaskOrderStatus.Complete
"
:readonly="!['create', 'edit'].includes(state.mode || '')"
v-model:file-data="fileData"
:transform-url="
async (url: string) => {
@ -931,28 +931,34 @@ watch([currentFormData.value.taskStatus], () => {
@upload="
async (f) => {
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);
}
}
"
/>

View file

@ -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);
}
}
"
/>