云
2026-10-25 8299116e84cd704e28dac09d284d3fc33adca511
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<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>