index.tsx
7.45 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
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
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
268
269
270
271
272
import ButtonConfirm from '@/components/ButtomConfirm';
import EllipsisDiv from '@/components/Div/EllipsisDiv';
import AddInvoiceDrawerForm from '@/pages/Invoice/Invoice/components/AddInvoiceDrawerForm';
import BankImportModal from '@/pages/Invoice/Invoice/components/BankImportModal';
import InvoiceVerificationModal from '@/pages/Invoice/Invoice/components/InvoiceVerificationModal';
import InvoiceWriteOffModal from '@/pages/Invoice/Invoice/components/invoiceWriteOffModal';
import { INVOICE_COLUMNS } from '@/pages/Invoice/constant';
import { INVOCING_STATUS, PAYEE_OPTIONS } from '@/pages/Order/constant';
import {
postServiceInvoiceDeleteInvoice,
postServiceInvoiceGetWriteOffRecord,
postServiceInvoiceQueryInvoice,
} from '@/services';
import { enumValueToLabel, formatDateTime } from '@/utils';
import { formatDate } from '@/utils/time';
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 [bankImportModalVisible, setBankImportModalVisible] = useState(false);
const [invoiceVerificationVisible, setInvoiceVerificationVisible] =
useState(false);
const [invoiceId, setInvoiceId] = useState(undefined);
const reloadInvoiceTable = () => {
invoiceActionRef.current?.reload();
};
const getTableCellText = (target: any) => {
if (!target) {
return '';
}
if (target.props) {
return target.props.text;
}
return target;
};
/**
* 加载发票列表表格的各个列格式
*/
const invoicecColumnsInit = () => {
let columns = INVOICE_COLUMNS.map((item) => {
let newItem = { ...item };
let dataIndex = item.dataIndex;
let dataType = item.valueType;
newItem.render = (text, record) => {
let textValue = record[dataIndex];
if (dataType === 'dateRange' || 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 '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: 160,
render: (text, record) => {
let btns = [];
if (!record.writeOffId) {
btns.push(
<InvoiceWriteOffModal
getData={() => {
return {
invoices: [record],
};
}}
key="writeOff"
triggerButton={
<Button size={'small'} type="link">
核销
</Button>
}
readOnly={false}
/>,
);
}
if (record.writeOffId) {
btns.push(
<InvoiceWriteOffModal
getData={async () => {
const res = await postServiceInvoiceGetWriteOffRecord({
data: { id: record.writeOffId },
});
const data = res.data;
return {
invoiceWriteOffId: data.id,
invoices: data.invoiceDtos,
bankStatements: data.bankStatementDtos,
};
}}
key="writeOff"
triggerButton={<Button type="link">核销记录</Button>}
readOnly={true}
/>,
);
}
if (record.paths?.includes('queryInvoiceDetails')) {
btns.push(
<Button
className="p-0"
key="view"
type="link"
onClick={() => {
setInvoiceVerificationVisible(true);
setInvoiceId(record.id);
}}
>
查看
</Button>,
);
}
if (record.paths?.includes('deleteInvoice')) {
btns.push(
<ButtonConfirm
key="delete"
className="p-0"
title={
'确认删除发票号码为[ ' + record.invoiceNumber + ' ]的发票吗?'
}
text="删除"
onConfirm={async () => {
let res = await postServiceInvoiceDeleteInvoice({
data: { invoiceId: record.invoiceId },
});
if (res) {
message.success(res.message);
reloadInvoiceTable();
}
}}
/>,
);
}
return btns;
},
});
return columns;
};
return (
<div className="invoice-index">
<ProTable
columns={invoicecColumnsInit()}
actionRef={invoiceActionRef}
cardBordered
pagination={{
pageSize: 10,
}}
request={async (params) => {
const res = await postServiceInvoiceQueryInvoice({
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={() => [
<AddInvoiceDrawerForm
onClose={() => {
invoiceActionRef.current?.reload();
}}
key="add"
></AddInvoiceDrawerForm>,
<InvoiceWriteOffModal
readOnly={false}
getData={() => ({})}
key="writeOff"
triggerButton={<Button type="primary">核销</Button>}
/>,
]}
/>
{bankImportModalVisible ? (
<BankImportModal
setVisible={setBankImportModalVisible}
onClose={() => {
setBankImportModalVisible(false);
invoiceActionRef.current?.reload();
}}
></BankImportModal>
) : (
''
)}
{invoiceVerificationVisible ? (
<InvoiceVerificationModal
setVisible={setInvoiceVerificationVisible}
invoiceId={invoiceId}
onClose={() => {
invoiceActionRef.current?.reload();
}}
></InvoiceVerificationModal>
) : (
''
)}
</div>
);
};
export default InvoiceRecord;