refactor: handle put attachment
This commit is contained in:
parent
ae83a574e0
commit
22f19ca8cc
2 changed files with 196 additions and 89 deletions
|
|
@ -78,6 +78,7 @@ import { DialogContainer, DialogHeader } from 'components/dialog';
|
|||
import KebabAction from 'src/components/shared/KebabAction.vue';
|
||||
import { nextTick } from 'vue';
|
||||
import FormEmployeeVisa from 'components/03_customer-management/FormEmployeeVisa.vue';
|
||||
import { group } from 'node:console';
|
||||
|
||||
const { t, locale } = useI18n();
|
||||
const $q = useQuasar();
|
||||
|
|
@ -2712,7 +2713,6 @@ const emptyCreateDialog = ref(false);
|
|||
v-model="currentFromDataEmployee.file"
|
||||
hide-action
|
||||
:readonly="!employeeFormState.isEmployeeEdit"
|
||||
:group-list="uploadFileListEmployee"
|
||||
:menu="uploadFileListEmployee"
|
||||
:columns="columnsAttachment"
|
||||
@submit="
|
||||
|
|
@ -2829,7 +2829,8 @@ const emptyCreateDialog = ref(false);
|
|||
|
||||
return tempValue;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
if (group === 'visa') {
|
||||
const res = await ocrStore.sendOcr({
|
||||
file: file,
|
||||
category: group,
|
||||
|
|
@ -2852,12 +2853,20 @@ const emptyCreateDialog = ref(false);
|
|||
:auto-save="currentFromDataEmployee.id !== ''"
|
||||
:download="
|
||||
(obj) => {
|
||||
employeeStore.getFile({
|
||||
parentId: currentFromDataEmployee.id || '',
|
||||
group: obj.group,
|
||||
fileId: obj._meta.id,
|
||||
download: true,
|
||||
});
|
||||
if (obj.group !== 'attachment') {
|
||||
employeeStore.getFile({
|
||||
parentId: currentFromDataEmployee.id || '',
|
||||
group: obj.group,
|
||||
fileId: obj._meta.id,
|
||||
download: true,
|
||||
});
|
||||
} else {
|
||||
employeeStore.getAttachment({
|
||||
parentId: currentFromDataEmployee.id || '',
|
||||
name: obj._meta.name,
|
||||
download: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
"
|
||||
:delete-item="
|
||||
|
|
@ -2882,53 +2891,65 @@ const emptyCreateDialog = ref(false);
|
|||
"
|
||||
:save="
|
||||
async (
|
||||
group: 'passport' | 'visa',
|
||||
group: 'passport' | 'visa' | 'attachment',
|
||||
_meta: any,
|
||||
file: File | undefined,
|
||||
) => {
|
||||
let status: boolean = false;
|
||||
if (group !== 'attachment') {
|
||||
if (file !== undefined && currentFromDataEmployee.id) {
|
||||
const res = await employeeStore.postMeta({
|
||||
parentId: currentFromDataEmployee.id || '',
|
||||
group,
|
||||
meta: _meta,
|
||||
file,
|
||||
});
|
||||
|
||||
if (file !== undefined && currentFromDataEmployee.id) {
|
||||
const res = await employeeStore.postMeta({
|
||||
parentId: currentFromDataEmployee.id || '',
|
||||
group,
|
||||
meta: _meta,
|
||||
file,
|
||||
});
|
||||
if (res) {
|
||||
status = true;
|
||||
}
|
||||
} else {
|
||||
const {
|
||||
id,
|
||||
employeeId,
|
||||
createdAt,
|
||||
updatedAt,
|
||||
...payload
|
||||
} = _meta;
|
||||
|
||||
if (res) {
|
||||
status = true;
|
||||
const res = await employeeStore.putMeta({
|
||||
parentId: currentFromDataEmployee.id || '',
|
||||
group,
|
||||
metaId: _meta.id,
|
||||
meta: payload,
|
||||
file,
|
||||
});
|
||||
if (res) {
|
||||
status = true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const {
|
||||
id,
|
||||
employeeId,
|
||||
createdAt,
|
||||
updatedAt,
|
||||
...payload
|
||||
} = _meta;
|
||||
const res = await employeeStore.putMeta({
|
||||
parentId: currentFromDataEmployee.id || '',
|
||||
group,
|
||||
metaId: _meta.id,
|
||||
meta: payload,
|
||||
file,
|
||||
});
|
||||
if (res) {
|
||||
if (file !== undefined) {
|
||||
await employeeStore.uploadAttachment(
|
||||
currentFromDataEmployee.id || '',
|
||||
file,
|
||||
file.name,
|
||||
);
|
||||
status = true;
|
||||
}
|
||||
}
|
||||
|
||||
await employeeFormStore.assignFormDataEmployee(
|
||||
currentFromDataEmployee.id,
|
||||
);
|
||||
|
||||
return status;
|
||||
}
|
||||
"
|
||||
:get-file-list="
|
||||
async (group: 'passport' | 'visa') => {
|
||||
if (!!currentFromDataEmployee.id) {
|
||||
async (group: 'passport' | 'visa' | 'attachment') => {
|
||||
if (
|
||||
!!currentFromDataEmployee.id &&
|
||||
group !== 'attachment'
|
||||
) {
|
||||
const resMeta = await employeeStore.getMetaList({
|
||||
parentId: currentFromDataEmployee.id,
|
||||
group,
|
||||
|
|
@ -2937,7 +2958,7 @@ const emptyCreateDialog = ref(false);
|
|||
const tempValue = resMeta.map(async (i: any) => {
|
||||
return {
|
||||
_meta: { ...i },
|
||||
name: i.id || '',
|
||||
name: `${group}-${dateFormat(i.expireDate)}` || '',
|
||||
group: group,
|
||||
url: await employeeStore.getFile({
|
||||
parentId: currentFromDataEmployee.id || '',
|
||||
|
|
@ -2948,9 +2969,29 @@ const emptyCreateDialog = ref(false);
|
|||
};
|
||||
});
|
||||
|
||||
return await waitAll(tempValue);
|
||||
} else {
|
||||
const res = await employeeStore.listAttachment({
|
||||
parentId: currentFromDataEmployee.id || '',
|
||||
});
|
||||
|
||||
const tempValue = (res as string[]).map(
|
||||
async (i: any) => {
|
||||
return {
|
||||
_meta: { id: i, name: i },
|
||||
name: i || '',
|
||||
group: group,
|
||||
url: await employeeStore.getAttachment({
|
||||
parentId: currentFromDataEmployee.id || '',
|
||||
name: i,
|
||||
}),
|
||||
file: undefined,
|
||||
};
|
||||
},
|
||||
);
|
||||
|
||||
return await waitAll(tempValue);
|
||||
}
|
||||
return [];
|
||||
}
|
||||
"
|
||||
>
|
||||
|
|
@ -4534,7 +4575,8 @@ const emptyCreateDialog = ref(false);
|
|||
|
||||
return tempValue;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
if (group === 'visa') {
|
||||
const res = await ocrStore.sendOcr({
|
||||
file: file,
|
||||
category: group,
|
||||
|
|
@ -4557,12 +4599,20 @@ const emptyCreateDialog = ref(false);
|
|||
:auto-save="currentFromDataEmployee.id !== ''"
|
||||
:download="
|
||||
(obj) => {
|
||||
employeeStore.getFile({
|
||||
parentId: currentFromDataEmployee.id || '',
|
||||
group: obj.group,
|
||||
fileId: obj._meta.id,
|
||||
download: true,
|
||||
});
|
||||
if (obj.group !== 'attachment') {
|
||||
employeeStore.getFile({
|
||||
parentId: currentFromDataEmployee.id || '',
|
||||
group: obj.group,
|
||||
fileId: obj._meta.id,
|
||||
download: true,
|
||||
});
|
||||
} else {
|
||||
employeeStore.getAttachment({
|
||||
parentId: currentFromDataEmployee.id || '',
|
||||
name: obj._meta.name,
|
||||
download: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
"
|
||||
:delete-item="
|
||||
|
|
@ -4587,41 +4637,50 @@ const emptyCreateDialog = ref(false);
|
|||
"
|
||||
:save="
|
||||
async (
|
||||
group: 'passport' | 'visa',
|
||||
group: 'passport' | 'visa' | 'attachment',
|
||||
_meta: any,
|
||||
file: File | undefined,
|
||||
) => {
|
||||
let status: boolean = false;
|
||||
if (file !== undefined && currentFromDataEmployee.id) {
|
||||
const res = await employeeStore.postMeta({
|
||||
parentId: currentFromDataEmployee.id || '',
|
||||
group,
|
||||
meta: _meta,
|
||||
file,
|
||||
});
|
||||
if (group !== 'attachment') {
|
||||
if (file !== undefined && currentFromDataEmployee.id) {
|
||||
const res = await employeeStore.postMeta({
|
||||
parentId: currentFromDataEmployee.id || '',
|
||||
group,
|
||||
meta: _meta,
|
||||
file,
|
||||
});
|
||||
|
||||
if (res) {
|
||||
status = true;
|
||||
if (res) {
|
||||
status = true;
|
||||
}
|
||||
} else {
|
||||
const {
|
||||
id,
|
||||
employeeId,
|
||||
createdAt,
|
||||
updatedAt,
|
||||
...payload
|
||||
} = _meta;
|
||||
|
||||
const res = await employeeStore.putMeta({
|
||||
parentId: currentFromDataEmployee.id || '',
|
||||
group,
|
||||
metaId: _meta.id,
|
||||
meta: payload,
|
||||
file,
|
||||
});
|
||||
if (res) {
|
||||
status = true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const {
|
||||
id,
|
||||
employeeId,
|
||||
createdAt,
|
||||
updatedAt,
|
||||
...payload
|
||||
} = _meta;
|
||||
|
||||
console.log(_meta);
|
||||
|
||||
const res = await employeeStore.putMeta({
|
||||
parentId: currentFromDataEmployee.id || '',
|
||||
group,
|
||||
metaId: _meta.id,
|
||||
meta: payload,
|
||||
file,
|
||||
});
|
||||
if (res) {
|
||||
if (file !== undefined) {
|
||||
await employeeStore.uploadAttachment(
|
||||
currentFromDataEmployee.id || '',
|
||||
file,
|
||||
file.name,
|
||||
);
|
||||
status = true;
|
||||
}
|
||||
}
|
||||
|
|
@ -4632,8 +4691,11 @@ const emptyCreateDialog = ref(false);
|
|||
}
|
||||
"
|
||||
:get-file-list="
|
||||
async (group: 'passport' | 'visa') => {
|
||||
if (!!currentFromDataEmployee.id) {
|
||||
async (group: 'passport' | 'visa' | 'attachment') => {
|
||||
if (
|
||||
!!currentFromDataEmployee.id &&
|
||||
group !== 'attachment'
|
||||
) {
|
||||
const resMeta = await employeeStore.getMetaList({
|
||||
parentId: currentFromDataEmployee.id,
|
||||
group,
|
||||
|
|
@ -4642,7 +4704,7 @@ const emptyCreateDialog = ref(false);
|
|||
const tempValue = resMeta.map(async (i: any) => {
|
||||
return {
|
||||
_meta: { ...i },
|
||||
name: i.id || '',
|
||||
name: `${group}-${dateFormat(i.expireDate)}` || '',
|
||||
group: group,
|
||||
url: await employeeStore.getFile({
|
||||
parentId: currentFromDataEmployee.id || '',
|
||||
|
|
@ -4653,9 +4715,29 @@ const emptyCreateDialog = ref(false);
|
|||
};
|
||||
});
|
||||
|
||||
return await waitAll(tempValue);
|
||||
} else {
|
||||
const res = await employeeStore.listAttachment({
|
||||
parentId: currentFromDataEmployee.id || '',
|
||||
});
|
||||
|
||||
const tempValue = (res as string[]).map(
|
||||
async (i: any) => {
|
||||
return {
|
||||
_meta: { id: i, name: i },
|
||||
name: i || '',
|
||||
group: group,
|
||||
url: await employeeStore.getAttachment({
|
||||
parentId: currentFromDataEmployee.id || '',
|
||||
name: i,
|
||||
}),
|
||||
file: undefined,
|
||||
};
|
||||
},
|
||||
);
|
||||
|
||||
return await waitAll(tempValue);
|
||||
}
|
||||
return [];
|
||||
}
|
||||
"
|
||||
>
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ import {
|
|||
calculateDaysUntilExpire,
|
||||
dialog,
|
||||
} from 'src/stores/utils';
|
||||
|
||||
import useEmployeeStore from 'stores/employee';
|
||||
import { useInvoice, useReceipt } from 'stores/payment';
|
||||
import useCustomerStore from 'stores/customer';
|
||||
import useOptionStore from 'stores/options';
|
||||
|
|
@ -98,6 +98,7 @@ type Node = {
|
|||
|
||||
type ProductGroupId = string;
|
||||
|
||||
const employeeStore = useEmployeeStore();
|
||||
const route = useRoute();
|
||||
const useReceiptStore = useReceipt();
|
||||
const configStore = useConfigStore();
|
||||
|
|
@ -2243,7 +2244,8 @@ async function getInvoiceCodeFullPay() {
|
|||
|
||||
return tempValue;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
if (group === 'visa') {
|
||||
const res = await ocrStore.sendOcr({
|
||||
file: file,
|
||||
category: group,
|
||||
|
|
@ -2269,25 +2271,48 @@ async function getInvoiceCodeFullPay() {
|
|||
}
|
||||
"
|
||||
:get-file-list="
|
||||
async (group: 'passport' | 'visa') => {
|
||||
if (formDataEmployee.attachment !== undefined) {
|
||||
const resMeta = formDataEmployee.attachment.filter(
|
||||
(v) => v.group === group,
|
||||
);
|
||||
async (group: 'passport' | 'visa' | 'attachment') => {
|
||||
if (!!currentFromDataEmployee.id && group !== 'attachment') {
|
||||
const resMeta = await employeeStore.getMetaList({
|
||||
parentId: currentFromDataEmployee.id,
|
||||
group,
|
||||
});
|
||||
|
||||
const tempValue = resMeta.map(async (i: any) => {
|
||||
return {
|
||||
_meta: { ...i._meta },
|
||||
name: i.id || '',
|
||||
_meta: { ...i },
|
||||
name: `${group}-${dateFormat(i.expireDate)}` || '',
|
||||
group: group,
|
||||
url: i.url,
|
||||
url: await employeeStore.getFile({
|
||||
parentId: currentFromDataEmployee.id || '',
|
||||
group,
|
||||
fileId: i.id,
|
||||
}),
|
||||
file: undefined,
|
||||
};
|
||||
});
|
||||
|
||||
return await waitAll(tempValue);
|
||||
} else {
|
||||
const res = await employeeStore.listAttachment({
|
||||
parentId: currentFromDataEmployee.id || '',
|
||||
});
|
||||
|
||||
const tempValue = (res as string[]).map(async (i: any) => {
|
||||
return {
|
||||
_meta: { id: i, name: i },
|
||||
name: i || '',
|
||||
group: group,
|
||||
url: await employeeStore.getAttachment({
|
||||
parentId: currentFromDataEmployee.id || '',
|
||||
name: i,
|
||||
}),
|
||||
file: undefined,
|
||||
};
|
||||
});
|
||||
|
||||
return await waitAll(tempValue);
|
||||
}
|
||||
return [];
|
||||
}
|
||||
"
|
||||
>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue