<script lang="ts" setup>
|
import type { ApplicantOption, FormType } from '../data';
|
import type { HrmRegularizeApi } from '#/api/hrm/regularize';
|
|
import { computed, ref } from 'vue';
|
|
import { useVbenModal } from '#/packages/effects/common-ui/src';
|
|
import { message } from 'ant-design-vue';
|
|
import { useVbenForm } from '#/adapter/form';
|
import {
|
createRegularize,
|
getRegularize,
|
updateRegularize,
|
} from '#/api/hrm/regularize';
|
import { $t } from '#/locales';
|
|
import { useFormSchema } from '../data';
|
|
const emit = defineEmits(['success']);
|
const formType = ref<FormType>('create');
|
|
const isDetail = computed(() => formType.value === 'detail');
|
const getTitle = computed(() => {
|
if (formType.value === 'detail') {
|
return '查看转正申请';
|
}
|
return formType.value === 'update' ? '修改转正申请' : '新增转正申请';
|
});
|
|
const [Form, formApi] = useVbenForm({
|
commonConfig: {
|
componentProps: {
|
class: 'w-full',
|
},
|
formItemClass: 'col-span-1',
|
labelWidth: 100,
|
},
|
wrapperClass: 'grid-cols-2',
|
layout: 'horizontal',
|
schema: [],
|
showDefaultActions: false,
|
});
|
|
/** 选择申请人后,自动带入其部门、岗位与当前用工性质 */
|
async function handleApplicantChange(option?: ApplicantOption) {
|
if (!option) {
|
return;
|
}
|
const patch: Record<string, number> = {};
|
if (option.deptId !== undefined && option.deptId !== null) {
|
patch.deptId = option.deptId;
|
}
|
if (option.postId !== undefined && option.postId !== null) {
|
patch.postId = option.postId;
|
}
|
if (
|
option.employmentType !== undefined &&
|
option.employmentType !== null
|
) {
|
patch.employmentType = option.employmentType;
|
}
|
await formApi.setValues(patch);
|
}
|
|
const [Modal, modalApi] = useVbenModal({
|
async onConfirm() {
|
if (isDetail.value) {
|
await modalApi.close();
|
return;
|
}
|
const { valid } = await formApi.validate();
|
if (!valid) {
|
return;
|
}
|
modalApi.lock();
|
const data = (await formApi.getValues()) as HrmRegularizeApi.RegularizeApplication;
|
try {
|
if (data.id) {
|
await updateRegularize(data);
|
} else {
|
await createRegularize(data);
|
}
|
await modalApi.close();
|
emit('success');
|
message.success($t('ui.actionMessage.operationSuccess'));
|
} finally {
|
modalApi.unlock();
|
}
|
},
|
async onOpenChange(isOpen: boolean) {
|
if (!isOpen) {
|
return;
|
}
|
const data = modalApi.getData<{ formType: FormType; id?: number }>();
|
formType.value = data.formType;
|
formApi.setState({
|
schema: useFormSchema(data.formType, handleApplicantChange),
|
});
|
formApi.setDisabled(data.formType === 'detail');
|
modalApi.setState({ showConfirmButton: data.formType !== 'detail' });
|
if (!data?.id) {
|
return;
|
}
|
modalApi.lock();
|
try {
|
const detail = await getRegularize(data.id);
|
await formApi.setValues(detail);
|
} finally {
|
modalApi.unlock();
|
}
|
},
|
});
|
</script>
|
|
<template>
|
<Modal :title="getTitle" class="w-[600px]">
|
<Form class="mx-4" />
|
</Modal>
|
</template>
|