refactor: add delete
This commit is contained in:
parent
9618085ac4
commit
ae5f66eaa4
2 changed files with 115 additions and 2 deletions
|
|
@ -921,6 +921,41 @@ function deleteBranchId(id: string) {
|
||||||
// flowStore.rotate();
|
// flowStore.rotate();
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
async function deleteByIdCheckOrwork(
|
||||||
|
id: string,
|
||||||
|
type: 'healthCheck' | 'workHistory',
|
||||||
|
indexTab: number,
|
||||||
|
) {
|
||||||
|
dialog({
|
||||||
|
color: 'info',
|
||||||
|
icon: 'mdi-alert',
|
||||||
|
title: t('saveConfirmTitle'),
|
||||||
|
actionText: t('ok'),
|
||||||
|
persistent: true,
|
||||||
|
message: t('saveConfirmMessage'),
|
||||||
|
action: async () => {
|
||||||
|
if (type === 'healthCheck') {
|
||||||
|
await employeeStore.deleteByIdCheckUp({
|
||||||
|
employeeId: currentEmployeeId.value,
|
||||||
|
checkUpId: id,
|
||||||
|
});
|
||||||
|
|
||||||
|
formDataEmployee.value.employeeCheckup?.splice(indexTab, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type === 'workHistory') {
|
||||||
|
await employeeStore.deleteByIdWork({
|
||||||
|
employeeId: currentEmployeeId.value,
|
||||||
|
workId: id,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
flowStore.rotate();
|
||||||
|
},
|
||||||
|
cancel: () => {},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
async function onSubmitEmployee(
|
async function onSubmitEmployee(
|
||||||
type: 'personalInfo' | 'healthCheck' | 'workHistory' | 'other',
|
type: 'personalInfo' | 'healthCheck' | 'workHistory' | 'other',
|
||||||
indexTab: number = 0,
|
indexTab: number = 0,
|
||||||
|
|
@ -967,6 +1002,7 @@ async function onSubmitEmployee(
|
||||||
);
|
);
|
||||||
|
|
||||||
if (res) {
|
if (res) {
|
||||||
|
formDataEmployee.value.employeeCheckup[indexTab].id = res.id;
|
||||||
formDataEmployee.value.employeeCheckup[indexTab].statusSave = true;
|
formDataEmployee.value.employeeCheckup[indexTab].statusSave = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -983,6 +1019,7 @@ async function onSubmitEmployee(
|
||||||
);
|
);
|
||||||
|
|
||||||
if (res) {
|
if (res) {
|
||||||
|
formDataEmployee.value.employeeWork[indexTab].id = res.id;
|
||||||
formDataEmployee.value.employeeWork[indexTab].statusSave = true;
|
formDataEmployee.value.employeeWork[indexTab].statusSave = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -3476,6 +3513,15 @@ watch(isMainPage, () => {
|
||||||
onSubmitEmployee('healthCheck', index);
|
onSubmitEmployee('healthCheck', index);
|
||||||
}
|
}
|
||||||
"
|
"
|
||||||
|
@remove="
|
||||||
|
(index) => {
|
||||||
|
deleteByIdCheckOrwork(
|
||||||
|
formDataEmployee.employeeCheckup?.[index].id || '',
|
||||||
|
'healthCheck',
|
||||||
|
index,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
"
|
||||||
/>
|
/>
|
||||||
<FormEmployeeWorkHistory
|
<FormEmployeeWorkHistory
|
||||||
prefix-id="form-dialog"
|
prefix-id="form-dialog"
|
||||||
|
|
@ -3492,6 +3538,15 @@ watch(isMainPage, () => {
|
||||||
onSubmitEmployee('workHistory', index);
|
onSubmitEmployee('workHistory', index);
|
||||||
}
|
}
|
||||||
"
|
"
|
||||||
|
@remove="
|
||||||
|
(index) => {
|
||||||
|
deleteByIdCheckOrwork(
|
||||||
|
formDataEmployee.employeeWork?.[index].id || '',
|
||||||
|
'healthCheck',
|
||||||
|
index,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
"
|
||||||
/>
|
/>
|
||||||
<FormEmployeeOther
|
<FormEmployeeOther
|
||||||
prefix-id="form-dialog"
|
prefix-id="form-dialog"
|
||||||
|
|
|
||||||
|
|
@ -107,7 +107,7 @@ const useEmployeeStore = defineStore('api-employee', () => {
|
||||||
transactionId?: string;
|
transactionId?: string;
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
const { ...payload } = data;
|
const { id, ...payload } = data;
|
||||||
const res = await api.post<EmployeeCheckupCreate>(
|
const res = await api.post<EmployeeCheckupCreate>(
|
||||||
`/employee/${employeeId}/checkup`,
|
`/employee/${employeeId}/checkup`,
|
||||||
{ ...payload },
|
{ ...payload },
|
||||||
|
|
@ -134,7 +134,7 @@ const useEmployeeStore = defineStore('api-employee', () => {
|
||||||
transactionId?: string;
|
transactionId?: string;
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
const { ...payload } = data;
|
const { id, ...payload } = data;
|
||||||
const res = await api.post<EmployeeWorkCreate>(
|
const res = await api.post<EmployeeWorkCreate>(
|
||||||
`/employee/${employeeId}/work`,
|
`/employee/${employeeId}/work`,
|
||||||
{ ...payload },
|
{ ...payload },
|
||||||
|
|
@ -293,6 +293,62 @@ const useEmployeeStore = defineStore('api-employee', () => {
|
||||||
return res.data;
|
return res.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function deleteByIdCheckUp(
|
||||||
|
opt: {
|
||||||
|
employeeId: string;
|
||||||
|
checkUpId?: string;
|
||||||
|
},
|
||||||
|
flow?: {
|
||||||
|
sessionId?: string;
|
||||||
|
refTransactionId?: string;
|
||||||
|
transactionId?: string;
|
||||||
|
},
|
||||||
|
) {
|
||||||
|
const res = await api.delete<Employee>(
|
||||||
|
`/employee/${opt.employeeId}/checkup/${opt.checkUpId}`,
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
'X-Session-Id': flow?.sessionId,
|
||||||
|
'X-Rtid': flow?.refTransactionId || flowStore.rtid,
|
||||||
|
'X-Tid': flow?.transactionId,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!res) return false;
|
||||||
|
if (res.status === 200) return res.data;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function deleteByIdWork(
|
||||||
|
opt: {
|
||||||
|
employeeId: string;
|
||||||
|
workId?: string;
|
||||||
|
},
|
||||||
|
flow?: {
|
||||||
|
sessionId?: string;
|
||||||
|
refTransactionId?: string;
|
||||||
|
transactionId?: string;
|
||||||
|
},
|
||||||
|
) {
|
||||||
|
const res = await api.delete<Employee>(
|
||||||
|
`/employee/${opt.employeeId}/work/${opt.workId}`,
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
'X-Session-Id': flow?.sessionId,
|
||||||
|
'X-Rtid': flow?.refTransactionId || flowStore.rtid,
|
||||||
|
'X-Tid': flow?.transactionId,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!res) return false;
|
||||||
|
if (res.status === 200) return res.data;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
async function deleteById(
|
async function deleteById(
|
||||||
id: string,
|
id: string,
|
||||||
flow?: {
|
flow?: {
|
||||||
|
|
@ -472,9 +528,11 @@ const useEmployeeStore = defineStore('api-employee', () => {
|
||||||
|
|
||||||
createEmployeeCheckup,
|
createEmployeeCheckup,
|
||||||
editByIdEmployeeCheckup,
|
editByIdEmployeeCheckup,
|
||||||
|
deleteByIdCheckUp,
|
||||||
|
|
||||||
createEmployeeWork,
|
createEmployeeWork,
|
||||||
editByIdEmployeeWork,
|
editByIdEmployeeWork,
|
||||||
|
deleteByIdWork,
|
||||||
|
|
||||||
createEmployeeOtherInfo,
|
createEmployeeOtherInfo,
|
||||||
editByIdEmployeeOtherInfo,
|
editByIdEmployeeOtherInfo,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue