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: {
|
async function deleteEmployeeById(opts: {
|
||||||
id?: string;
|
id?: string;
|
||||||
type?: 'passport' | 'visa' | 'healthCheck' | 'work';
|
type?: 'passport' | 'visa' | 'healthCheck' | 'work';
|
||||||
|
index?: number;
|
||||||
}) {
|
}) {
|
||||||
dialog({
|
dialog({
|
||||||
color: 'negative',
|
color: 'negative',
|
||||||
|
|
@ -476,20 +477,20 @@ async function deleteEmployeeById(opts: {
|
||||||
persistent: true,
|
persistent: true,
|
||||||
message: t('dialog.message.confirmDelete'),
|
message: t('dialog.message.confirmDelete'),
|
||||||
action: async () => {
|
action: async () => {
|
||||||
if (opts.type === 'passport') {
|
if (opts.type === 'passport' && opts.index !== undefined) {
|
||||||
await employeeFormStore.deletePassport();
|
await employeeFormStore.deletePassport(opts.index);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opts.type === 'visa') {
|
if (opts.type === 'visa' && opts.index !== undefined) {
|
||||||
await employeeFormStore.deleteVisa();
|
await employeeFormStore.deleteVisa(opts.index);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opts.type === 'healthCheck') {
|
if (opts.type === 'healthCheck' && opts.index !== undefined) {
|
||||||
await employeeFormStore.deleteHealthCheck();
|
await employeeFormStore.deleteHealthCheck(opts.index);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opts.type === 'work') {
|
if (opts.type === 'work' && opts.index !== undefined) {
|
||||||
await employeeFormStore.deleteWorkHistory();
|
await employeeFormStore.deleteWorkHistory(opts.index);
|
||||||
} else {
|
} else {
|
||||||
if (!!opts.id) {
|
if (!!opts.id) {
|
||||||
const result = await employeeStore.deleteById(opts.id);
|
const result = await employeeStore.deleteById(opts.id);
|
||||||
|
|
@ -4962,8 +4963,7 @@ const emptyCreateDialog = ref(false);
|
||||||
icon-only
|
icon-only
|
||||||
@click.stop="
|
@click.stop="
|
||||||
() => {
|
() => {
|
||||||
employeeFormState.currentIndexPassport = index;
|
deleteEmployeeById({ type: 'passport', index });
|
||||||
deleteEmployeeById({ type: 'passport' });
|
|
||||||
}
|
}
|
||||||
"
|
"
|
||||||
type="button"
|
type="button"
|
||||||
|
|
@ -5081,8 +5081,7 @@ const emptyCreateDialog = ref(false);
|
||||||
icon-only
|
icon-only
|
||||||
@click.stop="
|
@click.stop="
|
||||||
() => {
|
() => {
|
||||||
employeeFormState.currentIndexVisa = index;
|
deleteEmployeeById({ type: 'visa', index });
|
||||||
deleteEmployeeById({ type: 'visa' });
|
|
||||||
}
|
}
|
||||||
"
|
"
|
||||||
type="button"
|
type="button"
|
||||||
|
|
|
||||||
|
|
@ -896,52 +896,38 @@ export const useEmployeeForm = defineStore('form-employee', () => {
|
||||||
await assignFormDataEmployee(currentFromDataEmployee.value.id);
|
await assignFormDataEmployee(currentFromDataEmployee.value.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function deletePassport() {
|
async function deletePassport(index: number) {
|
||||||
const res = await employeeStore.delMeta({
|
const res = await employeeStore.delMeta({
|
||||||
parentId: currentFromDataEmployee.value.id || '',
|
parentId: currentFromDataEmployee.value.id || '',
|
||||||
group: 'passport',
|
group: 'passport',
|
||||||
metaId:
|
metaId: currentFromDataEmployee.value.employeePassport?.[index].id || '',
|
||||||
currentFromDataEmployee.value.employeePassport?.[
|
|
||||||
state.value.currentIndexPassport
|
|
||||||
].id || '',
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (res) {
|
if (res) {
|
||||||
currentFromDataEmployee.value.employeePassport?.splice(
|
currentFromDataEmployee.value.employeePassport?.splice(index, 1);
|
||||||
state.value.currentIndexPassport,
|
|
||||||
1,
|
|
||||||
);
|
|
||||||
await assignFormDataEmployee(currentFromDataEmployee.value.id);
|
await assignFormDataEmployee(currentFromDataEmployee.value.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function deleteVisa() {
|
async function deleteVisa(index: number) {
|
||||||
const res = await employeeStore.delMeta({
|
const res = await employeeStore.delMeta({
|
||||||
parentId: currentFromDataEmployee.value.id || '',
|
parentId: currentFromDataEmployee.value.id || '',
|
||||||
group: 'visa',
|
group: 'visa',
|
||||||
metaId:
|
metaId: currentFromDataEmployee.value.employeeVisa?.[index].id || '',
|
||||||
currentFromDataEmployee.value.employeeVisa?.[
|
|
||||||
state.value.currentIndexVisa
|
|
||||||
].id || '',
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (res) {
|
if (res) {
|
||||||
currentFromDataEmployee.value.employeeVisa?.splice(
|
currentFromDataEmployee.value.employeeVisa?.splice(index, 1);
|
||||||
state.value.currentIndexVisa,
|
|
||||||
1,
|
|
||||||
);
|
|
||||||
await assignFormDataEmployee(currentFromDataEmployee.value.id);
|
await assignFormDataEmployee(currentFromDataEmployee.value.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function deleteWorkHistory() {
|
async function deleteWorkHistory(index: number) {
|
||||||
if (!currentFromDataEmployee.value.employeeWork) return;
|
if (!currentFromDataEmployee.value.employeeWork) return;
|
||||||
|
|
||||||
const res = await employeeStore.deleteByIdWork({
|
const res = await employeeStore.deleteByIdWork({
|
||||||
employeeId: currentFromDataEmployee.value.id || '',
|
employeeId: currentFromDataEmployee.value.id || '',
|
||||||
workId:
|
workId: currentFromDataEmployee.value.employeeWork[index]?.id,
|
||||||
currentFromDataEmployee.value.employeeWork[state.value.currentIndex]
|
|
||||||
?.id,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (res) {
|
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;
|
if (!currentFromDataEmployee.value.employeeCheckup) return;
|
||||||
|
|
||||||
const res = await employeeStore.deleteByIdCheckUp({
|
const res = await employeeStore.deleteByIdCheckUp({
|
||||||
employeeId: currentFromDataEmployee.value.id || '',
|
employeeId: currentFromDataEmployee.value.id || '',
|
||||||
checkUpId:
|
checkUpId: currentFromDataEmployee.value.employeeCheckup[index]?.id,
|
||||||
currentFromDataEmployee.value.employeeCheckup[state.value.currentIndex]
|
|
||||||
?.id,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (res) {
|
if (res) {
|
||||||
currentFromDataEmployee.value.employeeCheckup.splice(
|
currentFromDataEmployee.value.employeeCheckup.splice(index, 1);
|
||||||
state.value.currentIndex,
|
|
||||||
1,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
await assignFormDataEmployee(currentFromDataEmployee.value.id);
|
await assignFormDataEmployee(currentFromDataEmployee.value.id);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue