Blame view

src/pages/Invoice/InvoiceRecord/components/InvoiceVerificationModal.tsx 9.22 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';
28
import { BANK_STATEMENT_COLUMNS, INVOICE_STATUS } from '../../constant';
zhongnanhuang authored
29
30
31
32
33
34
35
36
37
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);
曾国涛 authored
47
48
      console.log('bs:' + res.data.bankStatementDtos);
      setRelationBankStatements(res.data.bankStatementDtos);
zhongnanhuang authored
49
50
51
52
    }
  };

  const showRelationOrders = () => {
zhongnanhuang authored
53
    return relationOrderIds?.map((item) => {
zhongnanhuang authored
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
      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
74
75
      children: invoiceInfo?.invoiceNumber,
      span: 6,
zhongnanhuang authored
76
77
78
79
    },
    {
      key: '2',
      label: '发票类型',
zhongnanhuang authored
80
      children: enumValueToLabel(invoiceInfo?.invoiceStatus, INVOCING_STATUS),
zhongnanhuang authored
81
82
83
84
85
      span: 6,
    },
    {
      key: '3',
      label: '状态',
zhongnanhuang authored
86
87
      children: enumValueToLabel(invoiceInfo?.status, INVOICE_STATUS),
      span: 4,
zhongnanhuang authored
88
89
90
91
    },
    {
      key: '4',
      label: '购买方',
zhongnanhuang authored
92
93
      children: invoiceInfo?.purchaser,
      span: 8,
zhongnanhuang authored
94
95
96
97
    },
    {
      key: '5',
      label: '收款单位',
zhongnanhuang authored
98
99
      children: enumValueToLabel(invoiceInfo?.payee, PAYEE_OPTIONS),
      span: 12,
zhongnanhuang authored
100
101
102
103
    },
    {
      key: '6',
      label: '联系人',
zhongnanhuang authored
104
105
      children: invoiceInfo?.contacts,
      span: 4,
zhongnanhuang authored
106
107
108
109
    },
    {
      key: '7',
      label: '销售',
zhongnanhuang authored
110
111
      children: invoiceInfo?.sale,
      span: 8,
zhongnanhuang authored
112
    },
zhongnanhuang authored
113
zhongnanhuang authored
114
115
116
    {
      key: '9',
      label: '开票日期',
zhongnanhuang authored
117
118
      children: formatDate(invoiceInfo?.invoicingTime),
      span: 12,
zhongnanhuang authored
119
120
121
122
    },
    {
      key: '10',
      label: '收款时间',
zhongnanhuang authored
123
124
125
126
127
128
129
130
      children: formatDate(invoiceInfo?.collectionTime),
      span: 4,
    },
    {
      key: '8',
      label: '金额',
      children: invoiceInfo?.money,
      span: 10,
zhongnanhuang authored
131
132
133
134
    },
    {
      key: '11',
      label: '备注',
zhongnanhuang authored
135
      children: invoiceInfo?.notes,
zhongnanhuang authored
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
      span: 24,
    },
  ];

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

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

    return target;
  };

  /**
曾国涛 authored
153
   * 加载表格的各个列格式
zhongnanhuang authored
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
220
   */
  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
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
248
      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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
    });

    return columns;
  };

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

  return (
    <>
      <ModalForm<{
        id: string;
      }>
zhongnanhuang authored
263
        className="invoice-detail"
zhongnanhuang authored
264
265
266
267
268
269
270
        open
        width="80%"
        title="发票详情"
        form={form}
        autoFocusFirstInput
        modalProps={{
          okText: '确定',
zhongnanhuang authored
271
          cancelText: '返回',
zhongnanhuang authored
272
273
274
          destroyOnClose: true,
          onCancel: () => {
            setVisible(false);
zhongnanhuang authored
275
            onClose();
zhongnanhuang authored
276
277
          },
        }}
zhongnanhuang authored
278
279
280
281
282
        submitter={{
          render: (props, defaultDoms) => {
            return [defaultDoms[0]];
          },
        }}
zhongnanhuang authored
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
        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
312
313
        <ProTable
          columns={bankStatementColumnsInit()}
zhongnanhuang authored
314
          actionRef={actionRef}
zhongnanhuang authored
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
366
          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
367
368
369
370
      </ModalForm>

      {bankChooseModalVisible ? (
        <BankChooseModal
曾国涛 authored
371
          loadInvoiceData={loadInvoiceData}
zhongnanhuang authored
372
373
374
375
376
          setVisible={setBankChooseModalVisible}
          invoiceId={invoiceId}
          onClose={() => {
            setBankChooseModalVisible(false);
            loadInvoiceData();
zhongnanhuang authored
377
            actionRef.current?.reload();
zhongnanhuang authored
378
379
380
381
382
383
384
385
          }}
        ></BankChooseModal>
      ) : (
        ''
      )}
    </>
  );
};