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