<script lang="ts" setup>
|
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 { useFormSchema } from '../data';
|
|
const emit = defineEmits(['success']);
|
const isEdit = ref(false);
|
const title = computed(() => isEdit.value ? '修改转正申请' : '新增转正申请');
|
const [Form, formApi] = useVbenForm({
|
commonConfig: { componentProps: { class: 'w-full' }, formItemClass: 'col-span-1', labelWidth: 110 },
|
wrapperClass: 'grid-cols-2', layout: 'horizontal', schema: useFormSchema(),
|
showDefaultActions: false,
|
});
|
const [Modal, modalApi] = useVbenModal({
|
async onConfirm() {
|
const { valid } = await formApi.validate();
|
if (!valid) return;
|
modalApi.lock();
|
try {
|
const data = await formApi.getValues() as HrmRegularizeApi.Regularize;
|
if (isEdit.value) await updateRegularize(data);
|
else await createRegularize(data);
|
await modalApi.close();
|
message.success('保存成功');
|
emit('success');
|
} finally { modalApi.unlock(); }
|
},
|
async onOpenChange(open: boolean) {
|
if (!open) return;
|
const { id } = modalApi.getData<{ id?: number }>();
|
isEdit.value = !!id;
|
await formApi.resetForm();
|
if (id) {
|
modalApi.lock();
|
try { await formApi.setValues(await getRegularize(id)); }
|
finally { modalApi.unlock(); }
|
}
|
},
|
});
|
</script>
|
|
<template>
|
<Modal :title="title" class="w-[680px]"><Form class="mx-4" /></Modal>
|
</template>
|