zhangwencui
42 分钟以前 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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<script lang="ts" setup>
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { HrmSalaryPaymentApi } from '#/api/hrm/salary/payment';
 
import { ref } from 'vue';
 
import { Page, useVbenModal } from '#/packages/effects/common-ui/src';
import { downloadFileFromBlobPart } from '#/packages/utils/src';
 
import { message, Tag, DatePicker } from 'ant-design-vue';
 
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
import {
  exportSalaryPayment,
  generateSalaryPayment,
  getSalaryPaymentPage,
  paySalary,
} from '#/api/hrm/salary/payment';
import { $t } from '#/locales';
 
import { useGridColumns, useGridFormSchema } from './data';
import DetailModal from './modules/detail.vue';
 
const [DetailModalComp, detailModalApi] = useVbenModal({
  connectedComponent: DetailModal,
  destroyOnClose: true,
});
 
// 生成台账弹窗
const generateVisible = ref(false);
const generatePeriod = ref<string>();
const generateLoading = ref(false);
 
/** 刷新表格 */
function handleRefresh() {
  gridApi.query();
}
 
/** 打开生成台账弹窗 */
function openGenerateModal() {
  generatePeriod.value = undefined;
  generateVisible.value = true;
}
 
/** 生成发放台账 */
async function handleGenerate() {
  if (!generatePeriod.value) {
    message.warning('请选择发放周期');
    return;
  }
  generateLoading.value = true;
  try {
    await generateSalaryPayment(generatePeriod.value);
    message.success('生成发放台账成功');
    generateVisible.value = false;
    handleRefresh();
  } finally {
    generateLoading.value = false;
  }
}
 
/** 查看明细 */
function handleViewDetail(row: HrmSalaryPaymentApi.SalaryPayment) {
  detailModalApi.setData({ paymentId: row.id, period: row.period, status: row.status }).open();
}
 
/** 发放薪资 */
async function handlePay(row: HrmSalaryPaymentApi.SalaryPayment) {
  await paySalary(row.id!);
  message.success('发放成功');
  handleRefresh();
}
 
/** 导出薪资发放 */
async function handleExport() {
  const data = await exportSalaryPayment(await gridApi.formApi.getValues());
  downloadFileFromBlobPart({ fileName: '薪资发放台账.xls', source: data });
}
 
const [Grid, gridApi] = useVbenVxeGrid({
  formOptions: {
    schema: useGridFormSchema(),
  },
  gridOptions: {
    columns: useGridColumns(),
    height: 'auto',
    keepSource: true,
    proxyConfig: {
      ajax: {
        query: async ({ page }, formValues) =>
          await getSalaryPaymentPage({
            pageNo: page.currentPage,
            pageSize: page.pageSize,
            ...formValues,
          }),
      },
    },
    rowConfig: {
      keyField: 'id',
      isHover: true,
    },
    toolbarConfig: {
      refresh: true,
      search: true,
    },
  } as VxeTableGridOptions<HrmSalaryPaymentApi.SalaryPayment>,
});
</script>
 
<template>
  <Page auto-content-height>
    <DetailModalComp @success="handleRefresh" />
 
    <!-- 生成台账弹窗 -->
    <Modal
      v-model:open="generateVisible"
      title="生成发放台账"
      width="400px"
      :maskClosable="false"
    >
      <Form layout="vertical">
        <FormItem label="发放周期" required>
          <DatePicker
            v-model:value="generatePeriod"
            picker="month"
            format="YYYY-MM"
            valueFormat="YYYY-MM"
            placeholder="请选择发放周期"
            style="width: 100%"
          />
        </FormItem>
      </Form>
      <template #footer>
        <a-button @click="generateVisible = false">取消</a-button>
        <a-button type="primary" :loading="generateLoading" @click="handleGenerate">
          确定
        </a-button>
      </template>
    </Modal>
 
    <Grid table-title="薪资发放台账">
      <template #toolbar-tools>
        <TableAction
          :actions="[
            {
              label: '生成台账',
              type: 'primary',
              icon: ACTION_ICON.ADD,
              auth: ['hrm:salary-payment:generate'],
              onClick: openGenerateModal,
            },
            {
              label: $t('ui.actionTitle.export'),
              type: 'primary',
              icon: ACTION_ICON.DOWNLOAD,
              auth: ['hrm:salary-payment:export'],
              onClick: handleExport,
            },
          ]"
        />
      </template>
      <template #status="{ row }">
        <Tag :color="row.status === 0 ? 'warning' : 'success'">
          {{ row.status === 0 ? '待发放' : '已发放' }}
        </Tag>
      </template>
      <template #actions="{ row }">
        <TableAction
          :actions="[
            {
              label: '查看明细',
              type: 'link',
              onClick: handleViewDetail.bind(null, row),
            },
            {
              label: '发放',
              type: 'link',
              icon: ACTION_ICON.EDIT,
              auth: ['hrm:salary-payment:pay'],
              ifShow: row.status === 0,
              popConfirm: {
                title: '确认发放该周期的薪资吗?',
                confirm: handlePay.bind(null, row),
              },
            },
          ]"
        />
      </template>
    </Grid>
  </Page>
</template>