Blame view

src/pages/Invoice/ReissueRecord/index.tsx 8.3 KB
1
import ButtonConfirm from '@/components/ButtomConfirm';
2
3
4
import { RESPONSE_CODE } from '@/constants/enum';
import Audit from '@/pages/Invoice/ReissueRecord/components/Audit';
import {
5
  postServiceConstInvoiceReissueRecordStatus,
6
  postServiceInvoiceReissueRecordDelete,
7
  postServiceInvoiceReissueRecordFlush,
8
9
10
11
12
  postServiceInvoiceReissueRecords,
} from '@/services';
import { enumToSelect } from '@/utils';
import { useModel } from '@@/exports';
import type { ActionType, ProColumns } from '@ant-design/pro-components';
13
14
import { ProTable } from '@ant-design/pro-components';
import { message } from 'antd';
15
16
17
18
19
20
21
22
23
24
25
26
import { useRef } from 'react';

export const waitTimePromise = async (time: number = 100) => {
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve(true);
    }, time);
  });
};

export default () => {
  const actionRef = useRef<ActionType>();
27
  const { getInvoiceFlushStatus, getPayees } = useModel('enum');
28
  const columns: ProColumns[] = [
29
30
31
32
33
34
35
36
    {
      dataIndex: 'index',
      valueType: 'indexBorder',
      width: 48,
    },
    {
      title: '重开的发票',
      dataIndex: 'invoiceNumbers',
37
      width: 200,
38
      render: (_, record) => {
39
40
41
42
43
        return (
          <div style={{ whiteSpace: 'pre-wrap', wordBreak: 'break-word' }}>
            {record.invoiceNumbers?.join(',\n')}
          </div>
        );
44
      },
45
      ellipsis: true,
46
47
48
      hideInSearch: true,
    },
    {
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
      title: '收款单位',
      dataIndex: 'payees',
      width: 230,
      render: (_, record) => {
        return (
          <div style={{ whiteSpace: 'pre-wrap', wordBreak: 'break-word' }}>
            {record.payees?.join(',\n')}
          </div>
        );
      },
      ellipsis: true,
      hideInSearch: true,
    },
    {
      title: '联系人',
      dataIndex: 'contacts',
      width: 100,
      render: (_, record) => {
        return (
          <div style={{ whiteSpace: 'pre-wrap', wordBreak: 'break-word' }}>
            {record.contacts?.join(',\n')}
          </div>
        );
      },
      ellipsis: true,
      hideInSearch: true,
    },
    {
77
78
      title: '重开原因',
      dataIndex: 'notes',
79
      valueType: 'textarea',
80
      ellipsis: true,
81
      width: 180,
82
83
84
85
86
      hideInSearch: true,
    },
    {
      title: '申请人',
      dataIndex: 'createByName',
87
      width: 80,
88
89
90
91
92
93
      ellipsis: true,
      hideInSearch: true,
    },
    {
      title: '申请时间',
      dataIndex: 'createTime',
94
      width: 100,
95
96
97
98
99
100
      ellipsis: true,
      hideInSearch: true,
    },
    {
      title: '审核状态',
      dataIndex: 'statusText',
101
      width: 100,
102
103
104
105
106
107
      ellipsis: true,
      hideInSearch: true,
    },
    {
      title: '冲红状态',
      dataIndex: 'flushStatusText',
108
      width: 100,
109
110
111
112
113
114
      ellipsis: true,
      hideInSearch: true,
    },
    {
      title: '财务负责人',
      dataIndex: 'financeManager',
115
      width: 100,
116
117
118
119
120
121
      ellipsis: true,
      hideInSearch: true,
    },
    {
      title: '冲红时间',
      dataIndex: 'flushDatetime',
122
      width: 100,
123
124
125
      ellipsis: true,
      hideInSearch: true,
    },
126
127
128
    {
      title: '审核备注',
      dataIndex: 'auditNotes',
129
      width: 100,
130
131
      hideInSearch: true,
    },
132
133
134
135
136
137
138
    {
      title: '发票号码',
      dataIndex: 'invoiceNumber',
      hideInTable: true,
    },
    {
      title: '申请人',
139
      dataIndex: 'createByNameLike',
140
141
142
143
      hideInTable: true,
    },
    {
      title: '重开原因',
144
      dataIndex: 'notesLike',
145
146
147
148
      hideInTable: true,
    },
    {
      title: '申请时间',
149
      valueType: 'dateTimeRange',
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
      hideInTable: true,
      search: {
        transform: (value) => {
          if (value) {
            return {
              createDatetimeGe: value[0],
              createDatetimeLe: value[1],
            };
          }
        },
      },
    },
    {
      title: '审核状态',
      valueType: 'select',
      key: 'status',
      dataIndex: 'status',
      filters: true,
      onFilter: true,
      hideInTable: true,
      request: async () => {
171
        const res = await postServiceConstInvoiceReissueRecordStatus();
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
        return enumToSelect(res.data);
      },
    },
    {
      title: '冲红状态',
      valueType: 'select',
      key: 'flushStatus',
      dataIndex: 'flushStatus',
      filters: true,
      onFilter: true,
      hideInTable: true,
      request: async () => {
        const res = await getInvoiceFlushStatus();
        return enumToSelect(res);
      },
    },
    {
189
190
191
192
193
194
195
196
197
198
199
200
201
      title: '收款单位',
      valueType: 'select',
      key: 'payee',
      dataIndex: 'payee',
      filters: true,
      onFilter: true,
      hideInTable: true,
      request: async () => {
        const res = await getPayees();
        return enumToSelect(res);
      },
    },
    {
202
203
204
205
206
207
208
      title: '财务负责人',
      dataIndex: 'financeManager',
      ellipsis: true,
      hideInTable: true,
    },
    {
      title: '冲红时间',
209
      valueType: 'dateTimeRange',
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
      hideInTable: true,
      search: {
        transform: (value) => {
          if (value) {
            return {
              flushDatetimeGe: value[0],
              flushDatetimeLe: value[1],
            };
          }
        },
      },
    },

    {
      title: '操作',
      valueType: 'option',
      key: 'option',
227
228
229
230
231
232
233
234
      render: (text, record) => {
        console.log(text);
        return [
          record.paths?.includes('audit') && (
            <Audit
              key={'audit'}
              recordIds={[record.id]}
              onClose={() => {
235
                actionRef.current?.reload();
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
              }}
            />
          ),
          record.paths?.includes('audit') && (
            <ButtonConfirm
              key="delete"
              className="p-0"
              title={'确认删除该记录?'}
              text="删除"
              onConfirm={async () => {
                let res = await postServiceInvoiceReissueRecordDelete({
                  data: { id: record.id },
                });
                if (res) {
                  message.success(res.message);
                  actionRef.current?.reload();
                }
              }}
            />
          ),
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
          record.paths?.includes('flush') && (
            <ButtonConfirm
              key="flush"
              className="p-0"
              title={'确认冲红发票?'}
              text="冲红"
              onConfirm={async () => {
                let res = await postServiceInvoiceReissueRecordFlush({
                  data: { id: record.id },
                });
                if (res) {
                  message.success(res.message);
                  actionRef.current?.reload();
                }
              }}
            />
          ),
273
274
        ];
      },
275
276
277
    },
  ];
  return (
278
    <ProTable
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
      columns={columns}
      actionRef={actionRef}
      cardBordered
      request={async (params) => {
        const res = await postServiceInvoiceReissueRecords({
          data: {
            ...params,
          },
        });
        if (res.result === RESPONSE_CODE.SUCCESS) {
          return {
            data: res?.data?.data,
            total: res?.data?.total || 0,
          };
        }
        return {
          data: [],
          success: false,
        };
      }}
      editable={{
        type: 'multiple',
      }}
      columnsState={{
        persistenceKey: 'pro-table-singe-demos',
        persistenceType: 'localStorage',
        defaultValue: {
          option: { fixed: 'right', disable: true },
        },
        onChange(value) {
          console.log('value: ', value);
        },
      }}
      rowKey="id"
      search={{
        labelWidth: 'auto',
      }}
      options={{
        setting: {
          listsHeight: 400,
        },
      }}
      form={{
        syncToUrl: (values, type) => {
          if (type === 'get') {
            return {
              ...values,
              created_at: [values.startTime, values.endTime],
            };
          }
          return values;
        },
      }}
      pagination={{
333
334
335
336
337
338
        //pageSize: 5, // 默认每页展示条数
        pageSizeOptions: ['5', '10', '20', '50'], // 可选的条数
        showSizeChanger: true, // 启用条数选择器
        /*
            onChange: (page, pageSize) => console.log(`Page: ${page}, PageSize: ${pageSize}`),
*/
339
340
341
      }}
      dateFormatter="string"
      headerTitle="高级表格"
342
      scroll={{ x: 'max-content' }}
343
344
345
    />
  );
};