refactor: add upload file of employee
This commit is contained in:
parent
13b8b480c6
commit
30c78ef269
2 changed files with 162 additions and 112 deletions
|
|
@ -15,6 +15,7 @@ import useOptionStore from 'stores/options';
|
||||||
import { useQuotationForm } from './form';
|
import { useQuotationForm } from './form';
|
||||||
import useOcrStore from 'stores/ocr';
|
import useOcrStore from 'stores/ocr';
|
||||||
import { deleteItem } from 'stores/utils';
|
import { deleteItem } from 'stores/utils';
|
||||||
|
import { runOcr, parseResultMRZ } from 'src/utils/ocr';
|
||||||
|
|
||||||
// NOTE Import Types
|
// NOTE Import Types
|
||||||
import { QuotationPayload } from 'src/stores/quotations/types';
|
import { QuotationPayload } from 'src/stores/quotations/types';
|
||||||
|
|
@ -49,6 +50,7 @@ import {
|
||||||
uploadFileListEmployee,
|
uploadFileListEmployee,
|
||||||
columnsAttachment,
|
columnsAttachment,
|
||||||
} from 'src/pages/03_customer-management/constant';
|
} from 'src/pages/03_customer-management/constant';
|
||||||
|
import { group } from 'node:console';
|
||||||
|
|
||||||
defineProps<{
|
defineProps<{
|
||||||
readonly?: boolean;
|
readonly?: boolean;
|
||||||
|
|
@ -80,9 +82,12 @@ const $q = useQuasar();
|
||||||
const {
|
const {
|
||||||
currentFormData: quotationFormData,
|
currentFormData: quotationFormData,
|
||||||
currentFormState: quotationFormState,
|
currentFormState: quotationFormState,
|
||||||
|
newWorkerList,
|
||||||
|
fileItemNewWorker,
|
||||||
} = storeToRefs(quotationForm);
|
} = storeToRefs(quotationForm);
|
||||||
|
|
||||||
const refSelectZoneEmployee = ref<InstanceType<typeof SelectZone>>();
|
const refSelectZoneEmployee = ref<InstanceType<typeof SelectZone>>();
|
||||||
|
const mrz = ref<Awaited<ReturnType<typeof parseResultMRZ>>>();
|
||||||
const selectedBranchIssuer = ref('');
|
const selectedBranchIssuer = ref('');
|
||||||
const selectedCustomer = ref('');
|
const selectedCustomer = ref('');
|
||||||
const toggleWorker = ref(true);
|
const toggleWorker = ref(true);
|
||||||
|
|
@ -91,9 +96,18 @@ const branchId = ref('');
|
||||||
const date = ref();
|
const date = ref();
|
||||||
|
|
||||||
const preSelectedWorker = ref<Employee[]>([]);
|
const preSelectedWorker = ref<Employee[]>([]);
|
||||||
const selectedWorker = ref<Employee[]>([]);
|
const selectedWorker = ref<
|
||||||
|
(Employee & {
|
||||||
|
attachment?: {
|
||||||
|
name?: string;
|
||||||
|
group?: string;
|
||||||
|
url?: string;
|
||||||
|
file?: File;
|
||||||
|
_meta?: Record<string, any>;
|
||||||
|
}[];
|
||||||
|
})[]
|
||||||
|
>([]);
|
||||||
const workerList = ref<Employee[]>([]);
|
const workerList = ref<Employee[]>([]);
|
||||||
const newWorkerList = ref<EmployeeWorker[]>([]);
|
|
||||||
|
|
||||||
const agentPrice = ref(false);
|
const agentPrice = ref(false);
|
||||||
const summaryPrice = ref<{
|
const summaryPrice = ref<{
|
||||||
|
|
@ -141,8 +155,18 @@ const selectedGroup = ref<ProductGroup | null>(null);
|
||||||
|
|
||||||
const selectedProductServiceId = ref('');
|
const selectedProductServiceId = ref('');
|
||||||
|
|
||||||
const formDataEmployee = ref<EmployeeWorker>({
|
const formDataEmployee = ref<
|
||||||
alienReferencNumber: '',
|
EmployeeWorker & {
|
||||||
|
attachment?: {
|
||||||
|
name?: string;
|
||||||
|
group?: string;
|
||||||
|
url?: string;
|
||||||
|
file?: File;
|
||||||
|
_meta?: Record<string, any>;
|
||||||
|
}[];
|
||||||
|
}
|
||||||
|
>({
|
||||||
|
passportNo: '',
|
||||||
documentExpireDate: new Date(),
|
documentExpireDate: new Date(),
|
||||||
lastNameEN: '',
|
lastNameEN: '',
|
||||||
lastName: '',
|
lastName: '',
|
||||||
|
|
@ -154,6 +178,7 @@ const formDataEmployee = ref<EmployeeWorker>({
|
||||||
nationality: '',
|
nationality: '',
|
||||||
gender: '',
|
gender: '',
|
||||||
dateOfBirth: new Date(),
|
dateOfBirth: new Date(),
|
||||||
|
attachment: [],
|
||||||
});
|
});
|
||||||
|
|
||||||
const productServiceList = ref<
|
const productServiceList = ref<
|
||||||
|
|
@ -163,7 +188,7 @@ const productServiceList = ref<
|
||||||
function convertDataToFormSubmit() {
|
function convertDataToFormSubmit() {
|
||||||
quotationFormData.value.productServiceList = JSON.parse(
|
quotationFormData.value.productServiceList = JSON.parse(
|
||||||
JSON.stringify(
|
JSON.stringify(
|
||||||
productServiceList.value.map((v, i) => ({
|
productServiceList.value.map((v) => ({
|
||||||
workerIndex: [0, 1],
|
workerIndex: [0, 1],
|
||||||
discount: 1,
|
discount: 1,
|
||||||
amount: 1,
|
amount: 1,
|
||||||
|
|
@ -174,11 +199,27 @@ function convertDataToFormSubmit() {
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
selectedWorker.value.forEach((v, i) => {
|
||||||
|
if (v.attachment !== undefined) {
|
||||||
|
v.attachment.forEach((value) => {
|
||||||
|
fileItemNewWorker.value.push({
|
||||||
|
employeeIndex: i,
|
||||||
|
name: value.name,
|
||||||
|
group: value.group as 'passport' | 'visa' | 'in-country-notice',
|
||||||
|
url: value.url,
|
||||||
|
file: value.file,
|
||||||
|
_meta: value._meta,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
quotationFormData.value.worker = JSON.parse(
|
quotationFormData.value.worker = JSON.parse(
|
||||||
JSON.stringify(
|
JSON.stringify(
|
||||||
selectedWorker.value.map((v, i) => {
|
selectedWorker.value.map((v) => {
|
||||||
if (v.id === undefined) {
|
if (v.id === undefined) {
|
||||||
return v;
|
const { attachment, ...payload } = v;
|
||||||
|
return payload;
|
||||||
} else {
|
} else {
|
||||||
return v.id;
|
return v.id;
|
||||||
}
|
}
|
||||||
|
|
@ -205,7 +246,7 @@ async function getAllProduct(
|
||||||
|
|
||||||
function setDefaultFormEmployee() {
|
function setDefaultFormEmployee() {
|
||||||
formDataEmployee.value = {
|
formDataEmployee.value = {
|
||||||
alienReferencNumber: '',
|
passportNo: '',
|
||||||
documentExpireDate: new Date(),
|
documentExpireDate: new Date(),
|
||||||
lastNameEN: '',
|
lastNameEN: '',
|
||||||
lastName: '',
|
lastName: '',
|
||||||
|
|
@ -217,6 +258,7 @@ function setDefaultFormEmployee() {
|
||||||
nationality: '',
|
nationality: '',
|
||||||
gender: '',
|
gender: '',
|
||||||
dateOfBirth: new Date(),
|
dateOfBirth: new Date(),
|
||||||
|
attachment: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
employeeFormState.value.dialogModal = false;
|
employeeFormState.value.dialogModal = false;
|
||||||
|
|
@ -769,8 +811,7 @@ watch(
|
||||||
:title="$t('form.title.create', { name: $t('customer.employee') })"
|
:title="$t('form.title.create', { name: $t('customer.employee') })"
|
||||||
:submit="
|
:submit="
|
||||||
() => {
|
() => {
|
||||||
newWorkerList.push(formDataEmployee);
|
quotationForm.injectNewEmployee({ data: formDataEmployee }, () =>
|
||||||
quotationForm.injectNewEmployee(formDataEmployee, () =>
|
|
||||||
setDefaultFormEmployee(),
|
setDefaultFormEmployee(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -899,9 +940,7 @@ watch(
|
||||||
title="form.field.basicInformation"
|
title="form.field.basicInformation"
|
||||||
prefixId="dialog"
|
prefixId="dialog"
|
||||||
dense
|
dense
|
||||||
v-model:alien-reference-number="
|
v-model:passport-no="formDataEmployee.passportNo"
|
||||||
formDataEmployee.alienReferencNumber
|
|
||||||
"
|
|
||||||
v-model:document-expire-date="formDataEmployee.documentExpireDate"
|
v-model:document-expire-date="formDataEmployee.documentExpireDate"
|
||||||
class="q-mb-md"
|
class="q-mb-md"
|
||||||
/>
|
/>
|
||||||
|
|
@ -927,108 +966,68 @@ watch(
|
||||||
|
|
||||||
<UploadFileGroup
|
<UploadFileGroup
|
||||||
show-title
|
show-title
|
||||||
v-model:current-id="currentFromDataEmployee.id"
|
v-model="formDataEmployee.attachment"
|
||||||
v-model="currentFromDataEmployee.file"
|
|
||||||
hide-action
|
hide-action
|
||||||
:group-list="uploadFileListEmployee"
|
|
||||||
:menu="uploadFileListEmployee"
|
:menu="uploadFileListEmployee"
|
||||||
:columns="columnsAttachment"
|
:columns="columnsAttachment"
|
||||||
:ocr="
|
:ocr="
|
||||||
async (group, file) => {
|
async (group, file) => {
|
||||||
const res = await ocrStore.sendOcr({
|
if (group === 'passport') {
|
||||||
file: file,
|
mrz = await runOcr(file, parseResultMRZ);
|
||||||
category: group,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (res) {
|
if (mrz !== null) {
|
||||||
const tempValue = {
|
const mapMrz = Object.entries(mrz.result).map(
|
||||||
status: true,
|
([key, value]) => ({
|
||||||
group,
|
name: key,
|
||||||
meta: res.fields,
|
value: value,
|
||||||
};
|
}),
|
||||||
|
);
|
||||||
|
const tempValue = {
|
||||||
|
status: true,
|
||||||
|
group,
|
||||||
|
meta: mapMrz,
|
||||||
|
};
|
||||||
|
|
||||||
return tempValue;
|
return tempValue;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const res = await ocrStore.sendOcr({
|
||||||
|
file: file,
|
||||||
|
category: group,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (res) {
|
||||||
|
const tempValue = {
|
||||||
|
status: true,
|
||||||
|
group,
|
||||||
|
meta: res.fields,
|
||||||
|
};
|
||||||
|
|
||||||
|
return tempValue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return { status: false, group, meta: [] };
|
|
||||||
}
|
return { status: true, group, meta: [] };
|
||||||
"
|
|
||||||
:auto-save="currentFromDataEmployee.id !== ''"
|
|
||||||
:download="
|
|
||||||
(obj) => {
|
|
||||||
employeeStore.getFile({
|
|
||||||
parentId: currentFromDataEmployee.id || '',
|
|
||||||
group: obj.group,
|
|
||||||
fileId: obj._meta.id,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
"
|
"
|
||||||
:delete-item="
|
:delete-item="
|
||||||
async (obj) => {
|
async () => {
|
||||||
const res = await employeeStore.delMeta({
|
return true;
|
||||||
parentId: currentFromDataEmployee.id || '',
|
|
||||||
group: obj.group,
|
|
||||||
metaId: obj._meta.id,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (res) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
"
|
|
||||||
:save="
|
|
||||||
async (
|
|
||||||
group: 'passport' | 'visa',
|
|
||||||
_meta: any,
|
|
||||||
file: File | undefined,
|
|
||||||
) => {
|
|
||||||
if (file !== undefined && currentFromDataEmployee.id) {
|
|
||||||
const res = await employeeStore.postMeta({
|
|
||||||
parentId: currentFromDataEmployee.id || '',
|
|
||||||
group,
|
|
||||||
meta: _meta,
|
|
||||||
file,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (res) {
|
|
||||||
return 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) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
"
|
"
|
||||||
:get-file-list="
|
:get-file-list="
|
||||||
async (group: 'passport' | 'visa') => {
|
async (group: 'passport' | 'visa') => {
|
||||||
if (!!currentFromDataEmployee.id) {
|
if (formDataEmployee.attachment !== undefined) {
|
||||||
const resMeta = await employeeStore.getMetaList({
|
const resMeta = formDataEmployee.attachment.filter(
|
||||||
parentId: currentFromDataEmployee.id,
|
(v) => v.group === group,
|
||||||
group,
|
);
|
||||||
});
|
|
||||||
|
|
||||||
const tempValue = resMeta.map(async (i: any) => {
|
const tempValue = resMeta.map(async (i: any) => {
|
||||||
return {
|
return {
|
||||||
_meta: { ...i },
|
_meta: { ...i._meta },
|
||||||
name: i.id || '',
|
name: i.id || '',
|
||||||
group: group,
|
group: group,
|
||||||
url: await employeeStore.getFile({
|
url: i.url,
|
||||||
parentId: currentFromDataEmployee.id || '',
|
|
||||||
group,
|
|
||||||
fileId: i.id,
|
|
||||||
}),
|
|
||||||
file: undefined,
|
file: undefined,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import { QuotationPayload, EmployeeWorker } from 'src/stores/quotations/types';
|
||||||
|
|
||||||
// NOTE: Import stores
|
// NOTE: Import stores
|
||||||
import { useQuotationStore } from 'stores/quotations';
|
import { useQuotationStore } from 'stores/quotations';
|
||||||
|
import useEmployeeStore from 'stores/employee';
|
||||||
|
|
||||||
const DEFAULT_DATA: QuotationPayload = {
|
const DEFAULT_DATA: QuotationPayload = {
|
||||||
productServiceList: [],
|
productServiceList: [],
|
||||||
|
|
@ -32,9 +33,30 @@ export const useQuotationForm = defineStore('form-quotation', () => {
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
|
|
||||||
const quotationStore = useQuotationStore();
|
const quotationStore = useQuotationStore();
|
||||||
|
const employeeStore = useEmployeeStore();
|
||||||
|
const newWorkerList = ref<
|
||||||
|
(EmployeeWorker & {
|
||||||
|
attachment?: {
|
||||||
|
name?: string;
|
||||||
|
group?: string;
|
||||||
|
url?: string;
|
||||||
|
file?: File;
|
||||||
|
_meta?: Record<string, any>;
|
||||||
|
}[];
|
||||||
|
})[]
|
||||||
|
>([]);
|
||||||
|
|
||||||
let resetFormData = structuredClone(DEFAULT_DATA);
|
let resetFormData = structuredClone(DEFAULT_DATA);
|
||||||
|
const fileItemNewWorker = ref<
|
||||||
|
{
|
||||||
|
employeeIndex: number;
|
||||||
|
name?: string;
|
||||||
|
group: 'passport' | 'visa' | 'in-country-notice';
|
||||||
|
url?: string;
|
||||||
|
file?: File;
|
||||||
|
_meta?: Record<string, any>;
|
||||||
|
}[]
|
||||||
|
>([]);
|
||||||
const currentTreeData = ref();
|
const currentTreeData = ref();
|
||||||
const currentFormData = ref<QuotationPayload & { id?: string }>(
|
const currentFormData = ref<QuotationPayload & { id?: string }>(
|
||||||
structuredClone(resetFormData),
|
structuredClone(resetFormData),
|
||||||
|
|
@ -56,7 +78,8 @@ export const useQuotationForm = defineStore('form-quotation', () => {
|
||||||
if (clean) {
|
if (clean) {
|
||||||
currentFormData.value = structuredClone(DEFAULT_DATA);
|
currentFormData.value = structuredClone(DEFAULT_DATA);
|
||||||
resetFormData = structuredClone(DEFAULT_DATA);
|
resetFormData = structuredClone(DEFAULT_DATA);
|
||||||
|
fileItemNewWorker.value = [];
|
||||||
|
newWorkerList.value = [];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -92,7 +115,19 @@ export const useQuotationForm = defineStore('form-quotation', () => {
|
||||||
|
|
||||||
async function submitQuotation() {
|
async function submitQuotation() {
|
||||||
if (currentFormState.value.mode === 'create') {
|
if (currentFormState.value.mode === 'create') {
|
||||||
await quotationStore.createQuotation(currentFormData.value);
|
const res = await quotationStore.createQuotation(currentFormData.value);
|
||||||
|
|
||||||
|
if (res !== null) {
|
||||||
|
fileItemNewWorker.value.forEach(async (v) => {
|
||||||
|
if (v.group === undefined) return;
|
||||||
|
await employeeStore.postMeta({
|
||||||
|
group: v.group,
|
||||||
|
parentId: res.worker[v.employeeIndex].employeeId,
|
||||||
|
meta: v._meta,
|
||||||
|
file: v.file,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (currentFormState.value.mode === 'edit' && currentFormData.value.id) {
|
if (currentFormState.value.mode === 'edit' && currentFormData.value.id) {
|
||||||
await quotationStore.editQuotation({
|
await quotationStore.editQuotation({
|
||||||
|
|
@ -104,20 +139,34 @@ export const useQuotationForm = defineStore('form-quotation', () => {
|
||||||
currentFormState.value.mode = 'info';
|
currentFormState.value.mode = 'info';
|
||||||
}
|
}
|
||||||
|
|
||||||
function injectNewEmployee(data: EmployeeWorker, callback?: () => void) {
|
function injectNewEmployee(
|
||||||
currentFormData.value.worker.push({
|
obj: {
|
||||||
alienReferencNumber: data.alienReferencNumber,
|
data: EmployeeWorker & {
|
||||||
documentExpireDate: data.documentExpireDate,
|
attachment?: {
|
||||||
lastNameEN: data.lastNameEN,
|
name?: string;
|
||||||
lastName: data.lastName,
|
group?: string;
|
||||||
middleNameEN: data.middleNameEN,
|
url?: string;
|
||||||
middleName: data.middleName,
|
file?: File;
|
||||||
firstNameEN: data.firstNameEN,
|
_meta?: Record<string, any>;
|
||||||
firstName: data.firstName,
|
}[];
|
||||||
namePrefix: data.namePrefix,
|
};
|
||||||
nationality: data.nationality,
|
},
|
||||||
gender: data.gender,
|
callback?: () => void,
|
||||||
dateOfBirth: data.dateOfBirth,
|
) {
|
||||||
|
newWorkerList.value.push({
|
||||||
|
// passportNo: obj.data.passportNo, wait api add
|
||||||
|
//documentExpireDate: obj.data.documentExpireDate,
|
||||||
|
lastNameEN: obj.data.lastNameEN,
|
||||||
|
lastName: obj.data.lastName,
|
||||||
|
middleNameEN: obj.data.middleNameEN,
|
||||||
|
middleName: obj.data.middleName,
|
||||||
|
firstNameEN: obj.data.firstNameEN,
|
||||||
|
firstName: obj.data.firstName,
|
||||||
|
namePrefix: obj.data.namePrefix,
|
||||||
|
nationality: obj.data.nationality,
|
||||||
|
gender: obj.data.gender,
|
||||||
|
dateOfBirth: obj.data.dateOfBirth,
|
||||||
|
attachment: obj.data.attachment,
|
||||||
});
|
});
|
||||||
|
|
||||||
callback?.();
|
callback?.();
|
||||||
|
|
@ -141,6 +190,8 @@ export const useQuotationForm = defineStore('form-quotation', () => {
|
||||||
return {
|
return {
|
||||||
currentFormState,
|
currentFormState,
|
||||||
currentFormData,
|
currentFormData,
|
||||||
|
newWorkerList,
|
||||||
|
fileItemNewWorker,
|
||||||
|
|
||||||
isFormDataDifferent,
|
isFormDataDifferent,
|
||||||
injectNewEmployee,
|
injectNewEmployee,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue