From ff13ea497d9d9dbc4d6a61f0ee70959ed4b4e00a Mon Sep 17 00:00:00 2001 From: Net Date: Thu, 29 Aug 2024 16:59:58 +0700 Subject: [PATCH] refactor: assignOcrEmployeeData --- src/pages/03_customer-management/MainPage.vue | 84 +++++++++++++++++-- 1 file changed, 79 insertions(+), 5 deletions(-) diff --git a/src/pages/03_customer-management/MainPage.vue b/src/pages/03_customer-management/MainPage.vue index 054b2c77..215bec49 100644 --- a/src/pages/03_customer-management/MainPage.vue +++ b/src/pages/03_customer-management/MainPage.vue @@ -56,6 +56,7 @@ import { formMenuIconEmployee, uploadFileListEmployee, uploadFileListCustomer, + countryCode, } from './constant'; import { useCustomerForm, useEmployeeForm } from './form'; import { storeToRefs } from 'pinia'; @@ -553,6 +554,12 @@ function createEmployeeForm() { employeeFormState.value.isEmployeeEdit = true; } +function returnCountryCode(country: string) { + const tempValue = countryCode?.find((v) => v.label.includes(country)); + + return tempValue?.value; +} + // TODO: When in employee form, if select address same as customer then auto fill watch( @@ -594,6 +601,56 @@ watch( }, ); +function assignOcrEmployeeData(data: { + document: string; + fields: { name: string; value: string }[]; + result: string; +}) { + const map = data.fields.reduce>((a, c) => { + a[c.name] = c.value; + return a; + }, {}); + + const temp = data.document.split('_').at(0) || ''; + + if (data.document.includes('passport')) { + if (!currentFromDataEmployee.value.passportNumber) + currentFromDataEmployee.value.passportNumber = map['passport_no'] || ''; + if (!currentFromDataEmployee.value.passportIssueDate) + currentFromDataEmployee.value.passportIssueDate = + new Date(map['issue_date']) || ''; + if (!currentFromDataEmployee.value.passportExpiryDate) + currentFromDataEmployee.value.passportExpiryDate = + new Date(map['expire_date']) || ''; + + if (currentFromDataEmployee.value.passportIssuingPlace) + currentFromDataEmployee.value.passportIssuingPlace = temp; + + if (currentFromDataEmployee.value.passportIssuingCountry) + currentFromDataEmployee.value.passportIssuingCountry = + returnCountryCode(temp) || ''; + } + + if (data.document.includes('visa')) { + if (!currentFromDataEmployee.value.visaType) + currentFromDataEmployee.value.visaType = map['visa_type'] || ''; + + if (!currentFromDataEmployee.value.visaIssueDate) + currentFromDataEmployee.value.visaIssueDate = + new Date(map['issue_date']) || ''; + + if (!currentFromDataEmployee.value.visaIssuingPlace) + currentFromDataEmployee.value.visaIssuingPlace = map['issue_place'] || ''; + + if (!currentFromDataEmployee.value.visaExpiryDate) + currentFromDataEmployee.value.visaExpiryDate = + new Date(map['valid_until']) || ''; + + if (!currentFromDataEmployee.value.visaNumber) + currentFromDataEmployee.value.visaNumber = map['visa_no'] || ''; + } +} + watch( () => employeeFormState.value.currentTab, () => { @@ -2348,8 +2405,17 @@ const emptyCreateDialog = ref(false); " @send-ocr=" async (group, file) => { - if (file) await ocrStore.sendOcr({ file, category: group }); - employeeFormState.ocr = false; + if (file) { + const res = await ocrStore.sendOcr({ + file, + category: group, + }); + employeeFormState.ocr = false; + + if (res) { + assignOcrEmployeeData(res); + } + } } " > @@ -3353,9 +3419,17 @@ const emptyCreateDialog = ref(false); " @send-ocr=" async (group, file) => { - if (file) - await ocrStore.sendOcr({ file, category: group }); - employeeFormState.ocr = false; + if (file) { + const res = await ocrStore.sendOcr({ + file, + category: group, + }); + employeeFormState.ocr = false; + + if (res) { + assignOcrEmployeeData(res); + } + } } " >