@@ -2472,6 +2522,21 @@ watch(
v-model:insuranceCompanyOption="
optionStore.globalOption.insurancePlace
"
+ @save="
+ (index) => {
+ employeeFormState.currentIndex = index;
+ }
+ "
+ @edit="
+ (index) => {
+ if (
+ currentFromDataEmployee.employeeCheckup?.[index].statusSave
+ ) {
+ currentFromDataEmployee.employeeCheckup[index].statusSave =
+ false;
+ }
+ }
+ "
/>
{
drawerModal: boolean;
currentEmployeeCode: string;
currentEmployee: Employee | null;
+ currentIndex: number;
profileUrl: string;
isEmployeeEdit: boolean;
profileSubmit: boolean;
@@ -265,6 +266,7 @@ export const useEmployeeForm = defineStore('form-employee', () => {
}
| undefined;
}>({
+ currentIndex: 0,
statusSavePersonal: false,
drawerModal: false,
imageDialog: false,
@@ -385,6 +387,7 @@ export const useEmployeeForm = defineStore('form-employee', () => {
function resetFormDataEmployee(clean = false) {
if (clean) {
+ state.value.currentTab = 'personalInfo';
state.value.formDataEmployeeOwner = undefined;
resetEmployeeData = structuredClone(defaultFormData);
state.value.statusSavePersonal = false;
@@ -393,6 +396,77 @@ export const useEmployeeForm = defineStore('form-employee', () => {
currentFromDataEmployee.value = structuredClone(resetEmployeeData);
}
+ async function submitWorkHistory() {
+ if (!currentFromDataEmployee.value.employeeWork) return;
+
+ if (
+ !currentFromDataEmployee.value.employeeWork[state.value.currentIndex].id
+ ) {
+ const res = await employeeStore.createEmployeeWork(
+ currentFromDataEmployee.value?.id || '',
+ currentFromDataEmployee.value.employeeWork[state.value.currentIndex],
+ );
+ if (res) {
+ currentFromDataEmployee.value.employeeWork[
+ state.value.currentIndex
+ ].id = res.id;
+ currentFromDataEmployee.value.employeeWork[
+ state.value.currentIndex
+ ].statusSave = true;
+ }
+ } else {
+ const res = await employeeStore.editByIdEmployeeWork(
+ currentFromDataEmployee.value?.id || '',
+ currentFromDataEmployee.value.employeeWork[state.value.currentIndex],
+ );
+
+ if (res) {
+ currentFromDataEmployee.value.employeeWork[
+ state.value.currentIndex
+ ].statusSave = true;
+ }
+ }
+
+ await assignFormDataEmployee(currentFromDataEmployee.value.id);
+ }
+
+ async function submitHealthCheck() {
+ if (!currentFromDataEmployee.value.employeeCheckup) return;
+
+ if (
+ !currentFromDataEmployee.value.employeeCheckup[state.value.currentIndex]
+ .id
+ ) {
+ const res = await employeeStore.createEmployeeCheckup(
+ state.value.currentEmployee?.id || '',
+ currentFromDataEmployee.value.employeeCheckup[state.value.currentIndex],
+ );
+
+ if (res) {
+ currentFromDataEmployee.value.employeeCheckup[
+ state.value.currentIndex
+ ].id = res.id;
+
+ currentFromDataEmployee.value.employeeCheckup[
+ state.value.currentIndex
+ ].statusSave = true;
+ }
+ } else {
+ const res = await employeeStore.editByIdEmployeeCheckup(
+ state.value.currentEmployee?.id || '',
+ currentFromDataEmployee.value.employeeCheckup[state.value.currentIndex],
+ );
+
+ if (res) {
+ currentFromDataEmployee.value.employeeCheckup[
+ state.value.currentIndex
+ ].statusSave = true;
+ }
+ }
+
+ await assignFormDataEmployee(currentFromDataEmployee.value.id);
+ }
+
async function submitPersonal() {
if (state.value.dialogType === 'create') {
const res = await employeeStore.create({
@@ -403,8 +477,10 @@ export const useEmployeeForm = defineStore('form-employee', () => {
employeeCheckup: [],
employeeOtherInfo: undefined,
});
+
if (res) {
await assignFormDataEmployee(res.id);
+ currentFromDataEmployee.value.id = res.id;
state.value.statusSavePersonal = true;
}
}
@@ -462,9 +538,20 @@ export const useEmployeeForm = defineStore('form-employee', () => {
provinceId: province?.id,
districtId: district?.id,
subDistrictId: subDistrict?.id,
- employeeCheckup: structuredClone(playlond.employeeCheckup),
- employeeOtherInfo: structuredClone(playlond.employeeOtherInfo),
- employeeWork: structuredClone(playlond.employeeWork),
+ employeeCheckup: structuredClone(
+ playlond.employeeCheckup?.length === 0
+ ? defaultFormData.employeeCheckup
+ : playlond.employeeCheckup?.map((item) => ({
+ ...item,
+ statusSave: true,
+ })),
+ ),
+ employeeOtherInfo: structuredClone(playlond.employeeOtherInfo || {}),
+ employeeWork: structuredClone(
+ playlond.employeeWork?.length === 0
+ ? defaultFormData.employeeWork
+ : playlond.employeeWork,
+ ),
image: null,
};
@@ -518,7 +605,9 @@ export const useEmployeeForm = defineStore('form-employee', () => {
currentFromDataEmployee,
resetEmployeeData,
+ submitWorkHistory,
submitPersonal,
+ submitHealthCheck,
resetFormDataEmployee,
assignFormDataEmployee,
diff --git a/src/stores/employee/index.ts b/src/stores/employee/index.ts
index a4d2c44b..06d24d94 100644
--- a/src/stores/employee/index.ts
+++ b/src/stores/employee/index.ts
@@ -82,7 +82,7 @@ const useEmployeeStore = defineStore('api-employee', () => {
transactionId?: string;
},
) {
- const { code, image, ...payload } = data;
+ const { id, code, image, ...payload } = data;
const res = await api.post<
Employee & { profileImageUrl: string; profileImageUploadUrl: string }
>('/employee', payload, {
@@ -196,9 +196,9 @@ const useEmployeeStore = defineStore('api-employee', () => {
transactionId?: string;
},
) {
- const { ...payload } = data;
+ const { id, statusSave, ...payload } = data;
const res = await api.put(
- `/employee/${employeeId}/checkup}`,
+ `/employee/${employeeId}/checkup/${id}`,
{ ...payload },
{
headers: {
@@ -269,7 +269,7 @@ const useEmployeeStore = defineStore('api-employee', () => {
}
async function editById(
- id: string,
+ employeeId: string,
data: Partial,
flow?: {
sessionId?: string;
@@ -277,10 +277,10 @@ const useEmployeeStore = defineStore('api-employee', () => {
transactionId?: string;
},
) {
- const { code, image, ...payload } = data;
+ const { id, code, image, ...payload } = data;
const res = await api.put<
Employee & { imageUrl: string; profileImageUploadUrl: string }
- >(`/employee/${id}`, payload, {
+ >(`/employee/${employeeId}`, payload, {
headers: {
'X-Session-Id': flow?.sessionId,
'X-Rtid': flow?.refTransactionId || flowStore.rtid,
diff --git a/src/stores/employee/types.ts b/src/stores/employee/types.ts
index 2193fe5b..c9864991 100644
--- a/src/stores/employee/types.ts
+++ b/src/stores/employee/types.ts
@@ -57,6 +57,7 @@ export type Employee = {
};
export type EmployeeCreate = {
+ id?: string;
code: string;
image: File | null;
customerBranchId: string;