gaoluyang
2 天以前 b64a0deae5b5d33f9e20671a68936b27f0b9b00b
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<script lang="ts" setup>
import type { HrmEmployeeSocialSecurityApi } from '#/api/hrm/salary/employee-social-security';
import type { HrmSocialSecuritySchemeApi } from '#/api/hrm/salary/social-security-scheme';
 
import { computed, ref } from 'vue';
 
import { useVbenModal } from '#/packages/effects/common-ui/src';
 
import { message, Form, FormItem, Select, InputNumber, DatePicker, RadioGroup, Textarea } from 'ant-design-vue';
 
import {
  createEmployeeSocialSecurity,
  getEmployeeSocialSecurity,
  updateEmployeeSocialSecurity,
} from '#/api/hrm/salary/employee-social-security';
import { $t } from '#/locales';
 
const emit = defineEmits(['success']);
const formType = ref<'create' | 'update'>('create');
const userId = ref<number>();
const schemeList = ref<HrmSocialSecuritySchemeApi.SocialSecurityScheme[]>([]);
 
const formState = ref<HrmEmployeeSocialSecurityApi.EmployeeSocialSecurity>({
  userId: undefined,
  socialSecuritySchemeId: undefined,
  socialSecurityBase: 0,
  housingFundBase: 0,
  effectiveDate: undefined,
  status: 0,
  remark: '',
});
 
const getTitle = computed(() =>
  formType.value === 'update' ? '修改社保公积金档案' : '新增社保公积金档案',
);
 
const rules = {
  socialSecuritySchemeId: [{ required: true, message: '请选择社保方案' }],
  socialSecurityBase: [{ required: true, message: '请输入社保基数' }],
  housingFundBase: [{ required: true, message: '请输入公积金基数' }],
  effectiveDate: [{ required: true, message: '请选择生效日期' }],
};
 
const [Modal, modalApi] = useVbenModal({
  async onConfirm() {
    try {
      const data = { ...formState.value, userId: userId.value };
      if (formState.value.id) {
        await updateEmployeeSocialSecurity(data);
      } else {
        await createEmployeeSocialSecurity(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: 'create' | 'update';
      id?: number;
      userId?: number;
      schemeList?: HrmSocialSecuritySchemeApi.SocialSecurityScheme[];
    }>();
    formType.value = data.formType;
    userId.value = data.userId;
    schemeList.value = data.schemeList || [];
 
    // 重置表单
    formState.value = {
      userId: data.userId,
      socialSecuritySchemeId: undefined,
      socialSecurityBase: 0,
      housingFundBase: 0,
      effectiveDate: undefined,
      status: 0,
      remark: '',
    };
 
    if (data?.id) {
      modalApi.lock();
      try {
        const detail = await getEmployeeSocialSecurity(data.id);
        formState.value = detail;
      } finally {
        modalApi.unlock();
      }
    }
  },
});
</script>
 
<template>
  <Modal :title="getTitle" class="w-[700px]">
    <Form
      :model="formState"
      :rules="rules"
      :label-col="{ style: { width: '100px' } }"
      layout="horizontal"
    >
      <FormItem label="社保方案" name="socialSecuritySchemeId">
        <Select
          v-model:value="formState.socialSecuritySchemeId"
          :options="schemeList.map(s => ({ label: s.name, value: s.id }))"
          placeholder="请选择社保公积金方案"
        />
      </FormItem>
 
      <FormItem label="社保基数" name="socialSecurityBase">
        <InputNumber
          v-model:value="formState.socialSecurityBase"
          :min="0"
          :precision="2"
          style="width: 100%"
          placeholder="请输入社保基数"
        />
      </FormItem>
 
      <FormItem label="公积金基数" name="housingFundBase">
        <InputNumber
          v-model:value="formState.housingFundBase"
          :min="0"
          :precision="2"
          style="width: 100%"
          placeholder="请输入公积金基数"
        />
      </FormItem>
 
      <FormItem label="生效日期" name="effectiveDate">
        <DatePicker
          v-model:value="formState.effectiveDate"
          value-format="YYYY-MM-DD"
          style="width: 100%"
          placeholder="请选择生效日期"
        />
      </FormItem>
 
      <FormItem label="状态" name="status">
        <RadioGroup
          v-model:value="formState.status"
          :options="[
            { label: '启用', value: 0 },
            { label: '禁用', value: 1 },
          ]"
        />
      </FormItem>
 
      <FormItem label="备注">
        <Textarea
          v-model:value="formState.remark"
          :rows="2"
          placeholder="请输入备注"
        />
      </FormItem>
    </Form>
  </Modal>
</template>