Blame view

src/pages/Invoice/InvoiceVerification/index.tsx 7.26 KB
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
import ButtonConfirm from '@/components/ButtomConfirm';
import EllipsisDiv from '@/components/Div/EllipsisDiv';
import { RESPONSE_CODE } from '@/constants/enum';
import BankImportModal from '@/pages/Invoice/InvoiceVerification/components/BankImportModal';
import InvoiceRecordDetailModal from '@/pages/Invoice/InvoiceVerification/components/InvoiceRecordDetailModal';
import InvoiceVerificationModal from '@/pages/Invoice/InvoiceVerification/components/InvoiceVerificationModal';
import {
  BANK_STATEMENT_COLUMNS,
  INVOICE_STATUS,
} from '@/pages/Invoice/constant';
import { INVOCING_STATUS, PAYEE_OPTIONS } from '@/pages/Order/constant';
import {
  postServiceBankStatementDeleteBankStatement,
  postServiceBankStatementEditBankStatement,
  postServiceBankStatementQueryBankStatement,
} from '@/services';
import { enumValueToLabel, formatDateTime } from '@/utils';
import { formatDate } from '@/utils/time';
import { PlusOutlined } from '@ant-design/icons';
import { ActionType, ProTable } from '@ant-design/pro-components';
import { Button, message } from 'antd';
import { useRef, useState } from 'react';

const InvoiceRecord = () => {
  const invoiceActionRef = useRef<ActionType>();
  const bankActionRef = useRef<ActionType>();
  const [bankImportModalVisible, setBankImportModalVisible] = useState(false);
  const [invoiceVerificationVisible, setInvoiceVerificationVisible] =
    useState(false);
  const [invoiceId] = useState(undefined);
  const [invoiceRecordDetailVisible, setInvoiceRecordDetailVisible] =
    useState(false);
  const [invoiceRecord] = useState({});

  const reloadBankStatementTable = () => {
    bankActionRef.current?.reload();
  };

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

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

    return target;
  };

  const bankStatemetColumnsInit = () => {
    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') {
          if (textValue === null || textValue === undefined) {
            textValue = '';
          } else {
            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',
120
      width: 80,
121
122
      render: (text, record, _, action) => {
        let btns = [];
123
        if (record.paths?.includes('editBankStatement')) {
124
125
126
127
128
129
130
131
132
133
134
135
          btns.push(
            <a
              key="editable"
              onClick={() => {
                action?.startEditable?.(record.id);
              }}
            >
              编辑
            </a>,
          );
        }
136
        if (record.paths?.includes('deleteBankStatement')) {
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
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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
          btns.push(
            <ButtonConfirm
              key="delete"
              className="p-0"
              title={'是否删除该银行流水记录?'}
              text="删除"
              onConfirm={async () => {
                let res = await postServiceBankStatementDeleteBankStatement({
                  data: { id: record.id },
                });
                if (res.result === RESPONSE_CODE.SUCCESS) {
                  message.success(res.message);
                  reloadBankStatementTable();
                }
              }}
            />,
          );
        }
        return btns;
      },
    });

    return columns;
  };

  return (
    <div className="invoice-index">
      <ProTable
        columns={bankStatemetColumnsInit()}
        actionRef={bankActionRef}
        cardBordered
        pagination={{
          pageSize: 10,
        }}
        editable={{
          type: 'multiple',
          onSave: async (rowKey, data) => {
            await postServiceBankStatementEditBankStatement({ data: data });
          },
          actionRender: (row, config, defaultDom) => [
            defaultDom.save,
            defaultDom.cancel,
          ],
        }}
        request={async (params) => {
          const res = await postServiceBankStatementQueryBankStatement({
            data: { ...params },
          });
          if (res) {
            return {
              data: res?.data?.data || [],
              total: res?.data?.total || 0,
            };
          }
        }}
        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={{}}
        dateFormatter="string"
        headerTitle="银行流水列表"
        scroll={{ x: 1400, y: 360 }}
        toolBarRender={() => [
          <Button
            key="button"
            icon={<PlusOutlined />}
            onClick={() => {
              setBankImportModalVisible(true);
            }}
            type="primary"
          >
            导入
          </Button>,
        ]}
      />

      {bankImportModalVisible ? (
        <BankImportModal
          setVisible={setBankImportModalVisible}
          onClose={() => {
            setBankImportModalVisible(false);
            invoiceActionRef.current?.reload();
            bankActionRef.current?.reload();
          }}
        ></BankImportModal>
      ) : (
        ''
      )}

      {invoiceVerificationVisible ? (
        <InvoiceVerificationModal
          setVisible={setInvoiceVerificationVisible}
          invoiceId={invoiceId}
          onClose={() => {
            invoiceActionRef.current?.reload();
            bankActionRef.current?.reload();
          }}
        ></InvoiceVerificationModal>
      ) : (
        ''
      )}
      {invoiceRecordDetailVisible ? (
        <InvoiceRecordDetailModal
          key="detail"
          id={invoiceRecord.id}
          setVisible={setInvoiceRecordDetailVisible}
        />
      ) : (
        ''
      )}
    </div>
  );
};

export default InvoiceRecord;