From 30c78ef269176c91b83de44e1df67cd7ba68b0b4 Mon Sep 17 00:00:00 2001 From: Thanaphon Frappet Date: Tue, 8 Oct 2024 13:45:06 +0700 Subject: [PATCH] refactor: add upload file of employee --- src/pages/05_quotation/QuotationForm.vue | 189 +++++++++++------------ src/pages/05_quotation/form.ts | 85 ++++++++-- 2 files changed, 162 insertions(+), 112 deletions(-) diff --git a/src/pages/05_quotation/QuotationForm.vue b/src/pages/05_quotation/QuotationForm.vue index 8f070375..cf5a50fc 100644 --- a/src/pages/05_quotation/QuotationForm.vue +++ b/src/pages/05_quotation/QuotationForm.vue @@ -15,6 +15,7 @@ import useOptionStore from 'stores/options'; import { useQuotationForm } from './form'; import useOcrStore from 'stores/ocr'; import { deleteItem } from 'stores/utils'; +import { runOcr, parseResultMRZ } from 'src/utils/ocr'; // NOTE Import Types import { QuotationPayload } from 'src/stores/quotations/types'; @@ -49,6 +50,7 @@ import { uploadFileListEmployee, columnsAttachment, } from 'src/pages/03_customer-management/constant'; +import { group } from 'node:console'; defineProps<{ readonly?: boolean; @@ -80,9 +82,12 @@ const $q = useQuasar(); const { currentFormData: quotationFormData, currentFormState: quotationFormState, + newWorkerList, + fileItemNewWorker, } = storeToRefs(quotationForm); const refSelectZoneEmployee = ref>(); +const mrz = ref>>(); const selectedBranchIssuer = ref(''); const selectedCustomer = ref(''); const toggleWorker = ref(true); @@ -91,9 +96,18 @@ const branchId = ref(''); const date = ref(); const preSelectedWorker = ref([]); -const selectedWorker = ref([]); +const selectedWorker = ref< + (Employee & { + attachment?: { + name?: string; + group?: string; + url?: string; + file?: File; + _meta?: Record; + }[]; + })[] +>([]); const workerList = ref([]); -const newWorkerList = ref([]); const agentPrice = ref(false); const summaryPrice = ref<{ @@ -141,8 +155,18 @@ const selectedGroup = ref(null); const selectedProductServiceId = ref(''); -const formDataEmployee = ref({ - alienReferencNumber: '', +const formDataEmployee = ref< + EmployeeWorker & { + attachment?: { + name?: string; + group?: string; + url?: string; + file?: File; + _meta?: Record; + }[]; + } +>({ + passportNo: '', documentExpireDate: new Date(), lastNameEN: '', lastName: '', @@ -154,6 +178,7 @@ const formDataEmployee = ref({ nationality: '', gender: '', dateOfBirth: new Date(), + attachment: [], }); const productServiceList = ref< @@ -163,7 +188,7 @@ const productServiceList = ref< function convertDataToFormSubmit() { quotationFormData.value.productServiceList = JSON.parse( JSON.stringify( - productServiceList.value.map((v, i) => ({ + productServiceList.value.map((v) => ({ workerIndex: [0, 1], discount: 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( JSON.stringify( - selectedWorker.value.map((v, i) => { + selectedWorker.value.map((v) => { if (v.id === undefined) { - return v; + const { attachment, ...payload } = v; + return payload; } else { return v.id; } @@ -205,7 +246,7 @@ async function getAllProduct( function setDefaultFormEmployee() { formDataEmployee.value = { - alienReferencNumber: '', + passportNo: '', documentExpireDate: new Date(), lastNameEN: '', lastName: '', @@ -217,6 +258,7 @@ function setDefaultFormEmployee() { nationality: '', gender: '', dateOfBirth: new Date(), + attachment: [], }; employeeFormState.value.dialogModal = false; @@ -769,8 +811,7 @@ watch( :title="$t('form.title.create', { name: $t('customer.employee') })" :submit=" () => { - newWorkerList.push(formDataEmployee); - quotationForm.injectNewEmployee(formDataEmployee, () => + quotationForm.injectNewEmployee({ data: formDataEmployee }, () => setDefaultFormEmployee(), ); } @@ -899,9 +940,7 @@ watch( title="form.field.basicInformation" prefixId="dialog" dense - v-model:alien-reference-number=" - formDataEmployee.alienReferencNumber - " + v-model:passport-no="formDataEmployee.passportNo" v-model:document-expire-date="formDataEmployee.documentExpireDate" class="q-mb-md" /> @@ -927,108 +966,68 @@ watch(