Blame view

src/pages/Invoice/ReissueRecord/index.tsx 7.91 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
27
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>();
  const { getInvoiceFlushStatus } = 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
130
      width: 100,
      width: 180,
131
132
      hideInSearch: true,
    },
133
134
135
136
137
138
139
    {
      title: '发票号码',
      dataIndex: 'invoiceNumber',
      hideInTable: true,
    },
    {
      title: '申请人',
140
      dataIndex: 'createByNameLike',
141
142
143
144
      hideInTable: true,
    },
    {
      title: '重开原因',
145
      dataIndex: 'notesLike',
146
147
148
149
      hideInTable: true,
    },
    {
      title: '申请时间',
150
      valueType: 'dateTimeRange',
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
      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 () => {
172
        const res = await postServiceConstInvoiceReissueRecordStatus();
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
        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);
      },
    },
    {
      title: '财务负责人',
      dataIndex: 'financeManager',
      ellipsis: true,
      hideInTable: true,
    },
    {
      title: '冲红时间',
197
      valueType: 'dateTimeRange',
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
      hideInTable: true,
      search: {
        transform: (value) => {
          if (value) {
            return {
              flushDatetimeGe: value[0],
              flushDatetimeLe: value[1],
            };
          }
        },
      },
    },

    {
      title: '操作',
      valueType: 'option',
      key: 'option',
215
216
217
218
219
220
221
222
      render: (text, record) => {
        console.log(text);
        return [
          record.paths?.includes('audit') && (
            <Audit
              key={'audit'}
              recordIds={[record.id]}
              onClose={() => {
223
                actionRef.current?.reload();
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
              }}
            />
          ),
          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();
                }
              }}
            />
          ),
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
          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();
                }
              }}
            />
          ),
261
262
        ];
      },
263
264
265
    },
  ];
  return (
266
    <ProTable
267
268
269
270
271
272
273
274
275
276
277
278
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
      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={{
        // 由于配置了 transform,提交的参数与定义的不同这里需要转化一下
        syncToUrl: (values, type) => {
          if (type === 'get') {
            return {
              ...values,
              created_at: [values.startTime, values.endTime],
            };
          }
          return values;
        },
      }}
      pagination={{
        pageSize: 5,
        onChange: (page) => console.log(page),
      }}
      dateFormatter="string"
      headerTitle="高级表格"
327
      scroll={{ x: 'max-content' }}
328
329
330
    />
  );
};