refactor: assignOcrEmployeeData
This commit is contained in:
parent
fd1d96db2e
commit
ff13ea497d
1 changed files with 79 additions and 5 deletions
|
|
@ -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<Record<string, string>>((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);
|
||||
}
|
||||
}
|
||||
}
|
||||
"
|
||||
>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue