refactor: add tab passport
This commit is contained in:
parent
6879d0868c
commit
e969db16e0
3 changed files with 505 additions and 147 deletions
|
|
@ -588,6 +588,7 @@ export const useEmployeeForm = defineStore('form-employee', () => {
|
|||
currentEmployeeCode: string;
|
||||
currentEmployee: Employee | null;
|
||||
currentIndex: number;
|
||||
currentIndexPassport: number;
|
||||
profileUrl: string;
|
||||
isEmployeeEdit: boolean;
|
||||
profileSubmit: boolean;
|
||||
|
|
@ -617,6 +618,7 @@ export const useEmployeeForm = defineStore('form-employee', () => {
|
|||
ocr: boolean;
|
||||
}>({
|
||||
isImageEdit: false,
|
||||
currentIndexPassport: -1,
|
||||
currentIndex: -1,
|
||||
statusSavePersonal: false,
|
||||
drawerModal: false,
|
||||
|
|
@ -718,6 +720,7 @@ export const useEmployeeForm = defineStore('form-employee', () => {
|
|||
|
||||
employeePassport: [
|
||||
{
|
||||
id: undefined,
|
||||
number: '',
|
||||
type: '',
|
||||
issueDate: new Date(),
|
||||
|
|
@ -763,6 +766,7 @@ export const useEmployeeForm = defineStore('form-employee', () => {
|
|||
// }
|
||||
|
||||
function resetFormDataEmployee(clean = false) {
|
||||
state.value.currentIndexPassport = -1;
|
||||
if (clean) {
|
||||
state.value.currentTab = 'personalInfo';
|
||||
state.value.formDataEmployeeOwner = undefined;
|
||||
|
|
@ -776,6 +780,58 @@ export const useEmployeeForm = defineStore('form-employee', () => {
|
|||
currentFromDataEmployee.value = structuredClone(resetEmployeeData);
|
||||
}
|
||||
|
||||
async function submitPassport() {
|
||||
if (
|
||||
currentFromDataEmployee.value.employeePassport?.[
|
||||
state.value.currentIndexPassport
|
||||
] === undefined
|
||||
)
|
||||
return;
|
||||
|
||||
if (
|
||||
currentFromDataEmployee.value.employeePassport?.[
|
||||
state.value.currentIndexPassport
|
||||
].id === undefined
|
||||
) {
|
||||
const res = await employeeStore.postMeta({
|
||||
parentId: currentFromDataEmployee.value.id || '',
|
||||
group: 'passport',
|
||||
meta: currentFromDataEmployee.value.employeePassport?.[
|
||||
state.value.currentIndexPassport
|
||||
],
|
||||
});
|
||||
|
||||
if (res) {
|
||||
currentFromDataEmployee.value.employeePassport[
|
||||
state.value.currentIndexPassport
|
||||
].id = res.id;
|
||||
}
|
||||
}
|
||||
if (
|
||||
currentFromDataEmployee.value.employeePassport?.[
|
||||
state.value.currentIndexPassport
|
||||
].id !== undefined
|
||||
) {
|
||||
const { id, ...payload } =
|
||||
currentFromDataEmployee.value.employeePassport?.[
|
||||
state.value.currentIndexPassport
|
||||
];
|
||||
|
||||
await employeeStore.putMeta({
|
||||
parentId: currentFromDataEmployee.value.id || '',
|
||||
group: 'passport',
|
||||
metaId:
|
||||
currentFromDataEmployee.value.employeePassport?.[
|
||||
state.value.currentIndexPassport
|
||||
].id || '',
|
||||
meta: payload,
|
||||
});
|
||||
}
|
||||
|
||||
await assignFormDataEmployee(currentFromDataEmployee.value.id);
|
||||
state.value.currentIndexPassport = -1;
|
||||
}
|
||||
|
||||
async function submitOther() {
|
||||
if (!currentFromDataEmployee.value.employeeOtherInfo) return;
|
||||
|
||||
|
|
@ -802,6 +858,25 @@ export const useEmployeeForm = defineStore('form-employee', () => {
|
|||
await assignFormDataEmployee(currentFromDataEmployee.value.id);
|
||||
}
|
||||
|
||||
async function deletePassport() {
|
||||
const res = await employeeStore.delMeta({
|
||||
parentId: currentFromDataEmployee.value.id || '',
|
||||
group: 'passport',
|
||||
metaId:
|
||||
currentFromDataEmployee.value.employeePassport?.[
|
||||
state.value.currentIndexPassport
|
||||
].id || '',
|
||||
});
|
||||
|
||||
if (res) {
|
||||
currentFromDataEmployee.value.employeePassport?.splice(
|
||||
state.value.currentIndexPassport,
|
||||
1,
|
||||
);
|
||||
await assignFormDataEmployee(currentFromDataEmployee.value.id);
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteWorkHistory() {
|
||||
if (!currentFromDataEmployee.value.employeeWork) return;
|
||||
|
||||
|
|
@ -990,6 +1065,22 @@ export const useEmployeeForm = defineStore('form-employee', () => {
|
|||
provinceId: province?.id || '',
|
||||
districtId: district?.id || '',
|
||||
subDistrictId: subDistrict?.id || '',
|
||||
|
||||
employeePassport: structuredClone(
|
||||
payload.employeePassport?.length === 0
|
||||
? defaultFormData.employeePassport
|
||||
: payload.employeePassport?.map((item) => ({
|
||||
id: item.id,
|
||||
number: item.number,
|
||||
type: item.type,
|
||||
issueDate: item.issueDate,
|
||||
expireDate: item.expireDate,
|
||||
issueCountry: item.issueCountry,
|
||||
issuePlace: item.issuePlace,
|
||||
previousPassportRef: item.previousPassportRef,
|
||||
})),
|
||||
),
|
||||
|
||||
employeeCheckup: structuredClone(
|
||||
payload.employeeCheckup?.length === 0
|
||||
? defaultFormData.employeeCheckup
|
||||
|
|
@ -1029,6 +1120,17 @@ export const useEmployeeForm = defineStore('form-employee', () => {
|
|||
};
|
||||
|
||||
currentFromDataEmployee.value = structuredClone(resetEmployeeData);
|
||||
|
||||
state.value.currentIndexPassport =
|
||||
(currentFromDataEmployee.value.employeePassport?.length || 0) - 1;
|
||||
|
||||
if (
|
||||
currentFromDataEmployee.value.employeePassport?.[
|
||||
state.value.currentIndexPassport
|
||||
].id !== undefined
|
||||
) {
|
||||
state.value.currentIndexPassport = -1;
|
||||
}
|
||||
const foundBranch = await customerStore.fetchListCustomeBranchById(
|
||||
payload.customerBranchId,
|
||||
);
|
||||
|
|
@ -1075,16 +1177,36 @@ export const useEmployeeForm = defineStore('form-employee', () => {
|
|||
});
|
||||
}
|
||||
|
||||
function addPassport() {
|
||||
currentFromDataEmployee.value.employeePassport?.push({
|
||||
id: undefined,
|
||||
number: '',
|
||||
type: '',
|
||||
issueDate: new Date(),
|
||||
expireDate: new Date(),
|
||||
issueCountry: '',
|
||||
issuePlace: '',
|
||||
previousPassportRef: '',
|
||||
});
|
||||
|
||||
state.value.currentIndexPassport =
|
||||
(currentFromDataEmployee.value.employeePassport?.length || 0) - 1;
|
||||
}
|
||||
|
||||
return {
|
||||
state,
|
||||
currentFromDataEmployee,
|
||||
resetEmployeeData,
|
||||
|
||||
addPassport,
|
||||
|
||||
submitPassport,
|
||||
submitOther,
|
||||
submitWorkHistory,
|
||||
submitPersonal,
|
||||
submitHealthCheck,
|
||||
|
||||
deletePassport,
|
||||
deleteWorkHistory,
|
||||
deleteHealthCheck,
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue