zhangwencui
6 分钟以前 f08a81f01bc4a4104dd9ef04e071bb0bd0eb8afe
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
163
164
165
166
167
168
169
170
171
172
173
174
<script lang="ts" setup>
import type { FormType } from './form.vue';
import type { HrmEmployeeSocialSecurityApi } from '#/api/hrm/salary/employee-social-security';
 
import { ref, computed, watch } from 'vue';
 
import { useVbenModal } from '#/packages/effects/common-ui/src';
 
import { message, Table, Tag, Button } from 'ant-design-vue';
 
import { ACTION_ICON, TableAction } from '#/adapter/vxe-table';
import {
  createEmployeeSocialSecurity,
  deleteEmployeeSocialSecurity,
  getEmployeeSocialSecurityListByUser,
  updateEmployeeSocialSecurity,
} from '#/api/hrm/salary/employee-social-security';
import { getSocialSecuritySchemeList } from '#/api/hrm/salary/social-security-scheme';
import { $t } from '#/locales';
 
import SocialSecurityForm from './social-security-form.vue';
 
const props = defineProps<{
  employeeId?: number;
  userId?: number;
  formType?: FormType;
}>();
 
const emit = defineEmits(['refresh']);
 
const list = ref<HrmEmployeeSocialSecurityApi.EmployeeSocialSecurity[]>([]);
const schemeList = ref<any[]>([]);
const loading = ref(false);
 
const [FormModal, formModalApi] = useVbenModal({
  connectedComponent: SocialSecurityForm,
  destroyOnClose: true,
});
 
/** 刷新列表 */
async function handleRefresh() {
  if (!props.userId) return;
  loading.value = true;
  try {
    list.value = await getEmployeeSocialSecurityListByUser(props.userId);
  } finally {
    loading.value = false;
  }
  emit('refresh');
}
 
/** 新增档案 */
function handleCreate() {
  formModalApi.setData({
    formType: 'create',
    userId: props.userId,
    schemeList: schemeList.value,
  }).open();
}
 
/** 编辑档案 */
function handleEdit(row: HrmEmployeeSocialSecurityApi.EmployeeSocialSecurity) {
  formModalApi.setData({
    formType: 'update',
    id: row.id,
    userId: props.userId,
    schemeList: schemeList.value,
  }).open();
}
 
/** 删除档案 */
async function handleDelete(row: HrmEmployeeSocialSecurityApi.EmployeeSocialSecurity) {
  await deleteEmployeeSocialSecurity(row.id!);
  message.success($t('ui.actionMessage.deleteSuccess', ['社保公积金档案']));
  handleRefresh();
}
 
/** 获取方案列表 */
async function getSchemeList() {
  schemeList.value = await getSocialSecuritySchemeList({ status: 0 });
}
 
/** 监听 userId 变化 */
watch(
  () => props.userId,
  (val) => {
    if (val) {
      handleRefresh();
      getSchemeList();
    }
  },
  { immediate: true },
);
 
const columns = [
  { title: '社保方案', dataIndex: 'schemeName', width: 180 },
  { title: '社保基数', dataIndex: 'socialSecurityBase', width: 100 },
  { title: '公积金基数', dataIndex: 'housingFundBase', width: 100 },
  { title: '生效日期', dataIndex: 'effectiveDate', width: 110 },
  {
    title: '状态',
    dataIndex: 'status',
    width: 80,
    key: 'status',
  },
  {
    title: '操作',
    key: 'action',
    width: 150,
    fixed: 'right',
  },
];
 
const isDetail = computed(() => props.formType === 'detail');
</script>
 
<template>
  <div class="social-security-list">
    <FormModal @success="handleRefresh" />
 
    <!-- 工具栏 -->
    <div v-if="!isDetail" class="mb-3">
      <Button type="primary" @click="handleCreate">
        新增社保公积金档案
      </Button>
    </div>
 
    <!-- 表格 -->
    <Table
      :columns="columns"
      :data-source="list"
      :loading="loading"
      :pagination="false"
      size="small"
      row-key="id"
    >
      <template #bodyCell="{ column, record }">
        <template v-if="column.key === 'status'">
          <Tag :color="record.status === 0 ? 'success' : 'default'">
            {{ record.status === 0 ? '启用' : '禁用' }}
          </Tag>
        </template>
        <template v-else-if="column.key === 'action' && !isDetail">
          <TableAction
            :actions="[
              {
                label: $t('common.edit'),
                type: 'link',
                icon: ACTION_ICON.EDIT,
                onClick: handleEdit.bind(null, record),
              },
              {
                label: $t('common.delete'),
                type: 'link',
                danger: true,
                icon: ACTION_ICON.DELETE,
                popConfirm: {
                  title: $t('ui.actionMessage.deleteConfirm', ['社保公积金档案']),
                  confirm: handleDelete.bind(null, record),
                },
              },
            ]"
          />
        </template>
      </template>
    </Table>
  </div>
</template>
 
<style scoped>
.social-security-list {
  padding: 0;
}
</style>