Blame view

src/pages/Invoice/components/InvoiceVerificationModal.tsx 9.15 KB
zhongnanhuang authored
1
import ButtonConfirm from '@/components/ButtomConfirm';
zhongnanhuang authored
2
import EllipsisDiv from '@/components/Div/EllipsisDiv';
zhongnanhuang authored
3
import { RESPONSE_CODE } from '@/constants/enum';
zhongnanhuang authored
4
import { INVOCING_STATUS, PAYEE_OPTIONS } from '@/pages/Order/constant';
zhongnanhuang authored
5
6
7
8
import {
  postServiceInvoiceCancelInvoiceAndBankStatement,
  postServiceInvoiceQueryInvoiceDetail,
} from '@/services';
zhongnanhuang authored
9
10
11
import { enumValueToLabel, formatDateTime } from '@/utils';
import { formatDate } from '@/utils/time';
import { PlusOutlined } from '@ant-design/icons';
zhongnanhuang authored
12
13
14
15
16
17
import {
  ActionType,
  ModalForm,
  ProCard,
  ProTable,
} from '@ant-design/pro-components';
zhongnanhuang authored
18
19
20
21
22
23
24
import {
  Button,
  Descriptions,
  DescriptionsProps,
  Divider,
  Flex,
  Form,
zhongnanhuang authored
25
  message,
zhongnanhuang authored
26
} from 'antd';
zhongnanhuang authored
27
import { useEffect, useRef, useState } from 'react';
zhongnanhuang authored
28
29
30
31
32
33
34
35
36
37
import { BANK_STATEMENT_COLUMNS, INVOICE_STATUS } from '../constant';
import '../index.less';
import BankChooseModal from './BankChooseModal';

export default ({ invoiceId, setVisible, onClose }) => {
  const [form] = Form.useForm<{ id: string }>();
  const [bankChooseModalVisible, setBankChooseModalVisible] = useState(false);
  const [invoiceInfo, setInvoiceInfo] = useState({});
  const [relationOrderIds, setRelationOrderIds] = useState([]);
  const [relationBankStatements, setRelationBankStatements] = useState([]);
zhongnanhuang authored
38
  const actionRef = useRef<ActionType>();
zhongnanhuang authored
39
40
41
42
43
44

  const loadInvoiceData = async () => {
    let res = await postServiceInvoiceQueryInvoiceDetail({
      data: { invoiceId: invoiceId },
    });
    if (res && res.data) {
zhongnanhuang authored
45
      setInvoiceInfo(res.data);
zhongnanhuang authored
46
      setRelationOrderIds(res.data.mainOrderIds);
zhongnanhuang authored
47
48
49
50
51
      setRelationBankStatements(res.data.bankStatementResponseDtos);
    }
  };

  const showRelationOrders = () => {
zhongnanhuang authored
52
    return relationOrderIds?.map((item) => {
zhongnanhuang authored
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
      return (
        <>
          <Button
            className="pl-1 pr-0"
            type="link"
            target="_blank"
            href={'/order?id=' + item}
          >
            {item}
          </Button>
          <Divider type="vertical" />
        </>
      );
    });
  };

  const items: DescriptionsProps['items'] = [
    {
      key: '1',
      label: '发票号码',
zhongnanhuang authored
73
74
      children: invoiceInfo?.invoiceNumber,
      span: 6,
zhongnanhuang authored
75
76
77
78
    },
    {
      key: '2',
      label: '发票类型',
zhongnanhuang authored
79
      children: enumValueToLabel(invoiceInfo?.invoiceStatus, INVOCING_STATUS),
zhongnanhuang authored
80
81
82
83
84
      span: 6,
    },
    {
      key: '3',
      label: '状态',
zhongnanhuang authored
85
86
      children: enumValueToLabel(invoiceInfo?.status, INVOICE_STATUS),
      span: 4,
zhongnanhuang authored
87
88
89
90
    },
    {
      key: '4',
      label: '购买方',
zhongnanhuang authored
91
92
      children: invoiceInfo?.purchaser,
      span: 8,
zhongnanhuang authored
93
94
95
96
    },
    {
      key: '5',
      label: '收款单位',
zhongnanhuang authored
97
98
      children: enumValueToLabel(invoiceInfo?.payee, PAYEE_OPTIONS),
      span: 12,
zhongnanhuang authored
99
100
101
102
    },
    {
      key: '6',
      label: '联系人',
zhongnanhuang authored
103
104
      children: invoiceInfo?.contacts,
      span: 4,
zhongnanhuang authored
105
106
107
108
    },
    {
      key: '7',
      label: '销售',
zhongnanhuang authored
109
110
      children: invoiceInfo?.sale,
      span: 8,
zhongnanhuang authored
111
    },
zhongnanhuang authored
112
zhongnanhuang authored
113
114
115
    {
      key: '9',
      label: '开票日期',
zhongnanhuang authored
116
117
      children: formatDate(invoiceInfo?.invoicingTime),
      span: 12,
zhongnanhuang authored
118
119
120
121
    },
    {
      key: '10',
      label: '收款时间',
zhongnanhuang authored
122
123
124
125
126
127
128
129
      children: formatDate(invoiceInfo?.collectionTime),
      span: 4,
    },
    {
      key: '8',
      label: '金额',
      children: invoiceInfo?.money,
      span: 10,
zhongnanhuang authored
130
131
132
133
    },
    {
      key: '11',
      label: '备注',
zhongnanhuang authored
134
      children: invoiceInfo?.notes,
zhongnanhuang authored
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
      span: 24,
    },
  ];

  const getTableCellText = (target: any) => {
    if (!target) {
      return '';
    }

    if (target.props) {
      return target.props.text;
    }

    return target;
  };

  /**
   * 加载银行流水列表表格的各个列格式
   */
  const bankStatementColumnsInit = () => {
    let columns = BANK_STATEMENT_COLUMNS.map((item) => {
      let newItem = { ...item };
      let dataIndex = item.dataIndex;
      let dataType = item.valueType;

      newItem.render = (text, record) => {
        let textValue = record[dataIndex];

        if (dataType === 'date') {
          textValue = formatDate(textValue);
        }

        if (dataType === 'dateTime') {
          textValue = formatDateTime(textValue);
        }

        if (dataType === 'money') {
          textValue = '¥' + textValue;
        }

        switch (dataIndex) {
          case 'invoiceStatus':
            return (
              <EllipsisDiv
                text={enumValueToLabel(
                  getTableCellText(textValue),
                  INVOCING_STATUS,
                )}
              />
            );

          case 'status':
            return (
              <EllipsisDiv
                text={enumValueToLabel(
                  getTableCellText(textValue),
                  INVOICE_STATUS,
                )}
              />
            );

          case 'payee':
            return (
              <EllipsisDiv
                text={enumValueToLabel(
                  getTableCellText(textValue),
                  PAYEE_OPTIONS,
                )}
              />
            );

          default:
            return <EllipsisDiv text={getTableCellText(textValue)} />;
        }
      };

      return newItem;
    });

    columns.push({
      title: '操作',
      valueType: 'option',
      key: 'option',
      fixed: 'right',
      width: 70,
zhongnanhuang authored
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
      render: (text, record) => {
        let optBtns = [];
        if (invoiceInfo?.status === 'VERIFIED') {
          return [];
        }

        optBtns.push(
          <ButtonConfirm
            key="delete"
            className="p-0"
            title={'确认删除此项吗?'}
            text="删除"
            onConfirm={async () => {
              let res = await postServiceInvoiceCancelInvoiceAndBankStatement({
                data: {
                  invoiceId: invoiceId,
                  cancelId: [record.id],
                },
              });
              if (res.result === RESPONSE_CODE.SUCCESS) {
                message.success(res.message);
                loadInvoiceData();
              }
            }}
          />,
        );
        return optBtns;
      },
zhongnanhuang authored
248
249
250
251
252
253
254
255
256
257
258
259
260
261
    });

    return columns;
  };

  useEffect(() => {
    loadInvoiceData();
  }, []);

  return (
    <>
      <ModalForm<{
        id: string;
      }>
zhongnanhuang authored
262
        className="invoice-detail"
zhongnanhuang authored
263
264
265
266
267
268
269
        open
        width="80%"
        title="发票详情"
        form={form}
        autoFocusFirstInput
        modalProps={{
          okText: '确定',
zhongnanhuang authored
270
          cancelText: '返回',
zhongnanhuang authored
271
272
273
          destroyOnClose: true,
          onCancel: () => {
            setVisible(false);
zhongnanhuang authored
274
            onClose();
zhongnanhuang authored
275
276
          },
        }}
zhongnanhuang authored
277
278
279
280
281
        submitter={{
          render: (props, defaultDoms) => {
            return [defaultDoms[0]];
          },
        }}
zhongnanhuang authored
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
        onFinish={async () => {
          onClose();
        }}
        onOpenChange={setVisible}
      >
        <Divider orientation="left" plain>
          发票信息
        </Divider>

        <Descriptions
          bordered
          column={24}
          size="small"
          title=""
          items={items}
        />

        <Divider orientation="left" plain>
          订单号
        </Divider>

        <ProCard bordered style={{}}>
          <Flex>
            <div>{showRelationOrders()}</div>
          </Flex>
        </ProCard>

        <Divider plain></Divider>
zhongnanhuang authored
311
312
        <ProTable
          columns={bankStatementColumnsInit()}
zhongnanhuang authored
313
          actionRef={actionRef}
zhongnanhuang authored
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
          cardBordered
          pagination={{
            pageSize: 10,
          }}
          dataSource={relationBankStatements}
          columnsState={{
            persistenceKey: 'pro-table-singe-demos',
            persistenceType: 'localStorage',
            defaultValue: {
              option: { fixed: 'right', disable: true },
            },
            onChange(value) {
              console.log('value: ', value);
            },
          }}
          rowKey="id"
          search={false}
          options={{
            setting: {
              listsHeight: 400,
            },
            reload: false,
          }}
          form={{
            // 由于配置了 transform,提交的参与与定义的不同这里需要转化一下
            syncToUrl: (values, type) => {
              if (type === 'get') {
                return {
                  ...values,
                  created_at: [values.startTime, values.endTime],
                };
              }
              return values;
            },
          }}
          dateFormatter="string"
          headerTitle="银行流水"
          scroll={{ x: 1400, y: 360 }}
          toolBarRender={() => [
            <Button
              key="button"
              icon={<PlusOutlined />}
              onClick={() => {
                setBankChooseModalVisible(true);
              }}
              hidden={invoiceInfo?.status === 'VERIFIED'}
              type="primary"
            >
              添加
            </Button>,
          ]}
        />
zhongnanhuang authored
366
367
368
369
370
371
372
373
374
      </ModalForm>

      {bankChooseModalVisible ? (
        <BankChooseModal
          setVisible={setBankChooseModalVisible}
          invoiceId={invoiceId}
          onClose={() => {
            setBankChooseModalVisible(false);
            loadInvoiceData();
zhongnanhuang authored
375
            actionRef.current?.reload();
zhongnanhuang authored
376
377
378
379
380
381
382
383
          }}
        ></BankChooseModal>
      ) : (
        ''
      )}
    </>
  );
};