refactor: assignOcrEmployeeData

This commit is contained in:
Net 2024-08-29 16:59:58 +07:00
parent fd1d96db2e
commit ff13ea497d

View file

@ -56,6 +56,7 @@ import {
formMenuIconEmployee, formMenuIconEmployee,
uploadFileListEmployee, uploadFileListEmployee,
uploadFileListCustomer, uploadFileListCustomer,
countryCode,
} from './constant'; } from './constant';
import { useCustomerForm, useEmployeeForm } from './form'; import { useCustomerForm, useEmployeeForm } from './form';
import { storeToRefs } from 'pinia'; import { storeToRefs } from 'pinia';
@ -553,6 +554,12 @@ function createEmployeeForm() {
employeeFormState.value.isEmployeeEdit = true; 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 // TODO: When in employee form, if select address same as customer then auto fill
watch( 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( watch(
() => employeeFormState.value.currentTab, () => employeeFormState.value.currentTab,
() => { () => {
@ -2348,8 +2405,17 @@ const emptyCreateDialog = ref(false);
" "
@send-ocr=" @send-ocr="
async (group, file) => { async (group, file) => {
if (file) await ocrStore.sendOcr({ file, category: group }); if (file) {
employeeFormState.ocr = false; 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=" @send-ocr="
async (group, file) => { async (group, file) => {
if (file) if (file) {
await ocrStore.sendOcr({ file, category: group }); const res = await ocrStore.sendOcr({
employeeFormState.ocr = false; file,
category: group,
});
employeeFormState.ocr = false;
if (res) {
assignOcrEmployeeData(res);
}
}
} }
" "
> >