refactor: function get index
This commit is contained in:
parent
9d61ab8946
commit
7816634c36
2 changed files with 22 additions and 42 deletions
|
|
@ -467,6 +467,7 @@ async function toggleStatusCustomer(id: string, status: boolean) {
|
|||
async function deleteEmployeeById(opts: {
|
||||
id?: string;
|
||||
type?: 'passport' | 'visa' | 'healthCheck' | 'work';
|
||||
index?: number;
|
||||
}) {
|
||||
dialog({
|
||||
color: 'negative',
|
||||
|
|
@ -476,20 +477,20 @@ async function deleteEmployeeById(opts: {
|
|||
persistent: true,
|
||||
message: t('dialog.message.confirmDelete'),
|
||||
action: async () => {
|
||||
if (opts.type === 'passport') {
|
||||
await employeeFormStore.deletePassport();
|
||||
if (opts.type === 'passport' && opts.index !== undefined) {
|
||||
await employeeFormStore.deletePassport(opts.index);
|
||||
}
|
||||
|
||||
if (opts.type === 'visa') {
|
||||
await employeeFormStore.deleteVisa();
|
||||
if (opts.type === 'visa' && opts.index !== undefined) {
|
||||
await employeeFormStore.deleteVisa(opts.index);
|
||||
}
|
||||
|
||||
if (opts.type === 'healthCheck') {
|
||||
await employeeFormStore.deleteHealthCheck();
|
||||
if (opts.type === 'healthCheck' && opts.index !== undefined) {
|
||||
await employeeFormStore.deleteHealthCheck(opts.index);
|
||||
}
|
||||
|
||||
if (opts.type === 'work') {
|
||||
await employeeFormStore.deleteWorkHistory();
|
||||
if (opts.type === 'work' && opts.index !== undefined) {
|
||||
await employeeFormStore.deleteWorkHistory(opts.index);
|
||||
} else {
|
||||
if (!!opts.id) {
|
||||
const result = await employeeStore.deleteById(opts.id);
|
||||
|
|
@ -4962,8 +4963,7 @@ const emptyCreateDialog = ref(false);
|
|||
icon-only
|
||||
@click.stop="
|
||||
() => {
|
||||
employeeFormState.currentIndexPassport = index;
|
||||
deleteEmployeeById({ type: 'passport' });
|
||||
deleteEmployeeById({ type: 'passport', index });
|
||||
}
|
||||
"
|
||||
type="button"
|
||||
|
|
@ -5081,8 +5081,7 @@ const emptyCreateDialog = ref(false);
|
|||
icon-only
|
||||
@click.stop="
|
||||
() => {
|
||||
employeeFormState.currentIndexVisa = index;
|
||||
deleteEmployeeById({ type: 'visa' });
|
||||
deleteEmployeeById({ type: 'visa', index });
|
||||
}
|
||||
"
|
||||
type="button"
|
||||
|
|
|
|||
|
|
@ -896,52 +896,38 @@ export const useEmployeeForm = defineStore('form-employee', () => {
|
|||
await assignFormDataEmployee(currentFromDataEmployee.value.id);
|
||||
}
|
||||
|
||||
async function deletePassport() {
|
||||
async function deletePassport(index: number) {
|
||||
const res = await employeeStore.delMeta({
|
||||
parentId: currentFromDataEmployee.value.id || '',
|
||||
group: 'passport',
|
||||
metaId:
|
||||
currentFromDataEmployee.value.employeePassport?.[
|
||||
state.value.currentIndexPassport
|
||||
].id || '',
|
||||
metaId: currentFromDataEmployee.value.employeePassport?.[index].id || '',
|
||||
});
|
||||
|
||||
if (res) {
|
||||
currentFromDataEmployee.value.employeePassport?.splice(
|
||||
state.value.currentIndexPassport,
|
||||
1,
|
||||
);
|
||||
currentFromDataEmployee.value.employeePassport?.splice(index, 1);
|
||||
await assignFormDataEmployee(currentFromDataEmployee.value.id);
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteVisa() {
|
||||
async function deleteVisa(index: number) {
|
||||
const res = await employeeStore.delMeta({
|
||||
parentId: currentFromDataEmployee.value.id || '',
|
||||
group: 'visa',
|
||||
metaId:
|
||||
currentFromDataEmployee.value.employeeVisa?.[
|
||||
state.value.currentIndexVisa
|
||||
].id || '',
|
||||
metaId: currentFromDataEmployee.value.employeeVisa?.[index].id || '',
|
||||
});
|
||||
|
||||
if (res) {
|
||||
currentFromDataEmployee.value.employeeVisa?.splice(
|
||||
state.value.currentIndexVisa,
|
||||
1,
|
||||
);
|
||||
currentFromDataEmployee.value.employeeVisa?.splice(index, 1);
|
||||
await assignFormDataEmployee(currentFromDataEmployee.value.id);
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteWorkHistory() {
|
||||
async function deleteWorkHistory(index: number) {
|
||||
if (!currentFromDataEmployee.value.employeeWork) return;
|
||||
|
||||
const res = await employeeStore.deleteByIdWork({
|
||||
employeeId: currentFromDataEmployee.value.id || '',
|
||||
workId:
|
||||
currentFromDataEmployee.value.employeeWork[state.value.currentIndex]
|
||||
?.id,
|
||||
workId: currentFromDataEmployee.value.employeeWork[index]?.id,
|
||||
});
|
||||
|
||||
if (res) {
|
||||
|
|
@ -949,21 +935,16 @@ export const useEmployeeForm = defineStore('form-employee', () => {
|
|||
}
|
||||
}
|
||||
|
||||
async function deleteHealthCheck() {
|
||||
async function deleteHealthCheck(index: number) {
|
||||
if (!currentFromDataEmployee.value.employeeCheckup) return;
|
||||
|
||||
const res = await employeeStore.deleteByIdCheckUp({
|
||||
employeeId: currentFromDataEmployee.value.id || '',
|
||||
checkUpId:
|
||||
currentFromDataEmployee.value.employeeCheckup[state.value.currentIndex]
|
||||
?.id,
|
||||
checkUpId: currentFromDataEmployee.value.employeeCheckup[index]?.id,
|
||||
});
|
||||
|
||||
if (res) {
|
||||
currentFromDataEmployee.value.employeeCheckup.splice(
|
||||
state.value.currentIndex,
|
||||
1,
|
||||
);
|
||||
currentFromDataEmployee.value.employeeCheckup.splice(index, 1);
|
||||
}
|
||||
await assignFormDataEmployee(currentFromDataEmployee.value.id);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue