AddBankStatementModal.tsx
3.83 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
import { postServiceBankStatementQueryBankStatement } from '@/services';
import { ModalForm, ProCard, ProTable } from '@ant-design/pro-components';
import { Button, Divider, Flex, Form, Tag } from 'antd';
import React from 'react';
export default ({ getRows, onFinish }) => {
const [form] = Form.useForm();
const [selectedRows, setSelectedRows] = React.useState<any[]>([]);
const columns = [
{
title: '编号',
hideInSearch: true,
dataIndex: 'id',
},
{
title: '编号',
hideInTable: true,
dataIndex: 'id',
},
{
title: '流水号',
hideInSearch: true,
dataIndex: 'serialNumber',
},
{
title: '流水号',
hideInTable: true,
dataIndex: 'serialNumber',
},
{
title: '收款时间',
dataIndex: 'collectionDatetime',
hideInSearch: true,
valueType: 'date',
},
{
title: '收款方',
hideInSearch: true,
dataIndex: 'payeeText',
},
{
title: '付款方',
hideInSearch: true,
dataIndex: 'payer',
},
{
title: '金额',
dataIndex: 'amount',
hideInSearch: true,
valueType: 'money',
},
{
title: '操作',
valueType: 'option',
width: 200,
render: (text, record) => [
<a
key="selected"
onClick={() => {
let selectedRowsCopy;
if (!selectedRows || !Array.isArray(selectedRows)) {
selectedRowsCopy = []; // 初始化为一个空数组
} else {
selectedRowsCopy = selectedRows;
}
if (!selectedRows?.map((item) => item.id).includes(record.id)) {
setSelectedRows([...selectedRowsCopy, record]);
} else {
setSelectedRows(
selectedRowsCopy.filter((item) => item.id !== record.id),
);
}
}}
>
{selectedRows?.map((item) => item.id).includes(record.id)
? '取消选中'
: '选中'}
</a>,
],
},
];
return (
<ModalForm
title="添加银行流水"
trigger={<Button type="primary">添加</Button>}
form={form}
autoFocusFirstInput
modalProps={{
destroyOnClose: true,
onCancel: () => console.log('run'),
}}
onOpenChange={(visible) => {
if (visible) {
setSelectedRows(getRows());
}
}}
layout={'horizontal'}
width={1500}
submitTimeout={2000}
onFinish={async (values) => {
onFinish(selectedRows);
console.log(values);
return true;
}}
>
<Divider orientation="left" plain>
已选中(合计:¥
{selectedRows?.reduce((acc, cur) => acc + cur.amount, 0)}元)
</Divider>
<ProCard className="mb-[16px]" bordered style={{}}>
<Flex wrap="wrap" gap="small">
{selectedRows?.map((item, i) => {
return (
<Tag
key={i + ''}
closable={true}
style={{ userSelect: 'none' }}
color="blue"
onClose={(e) => {
e.preventDefault(); //需要加上这句代码,不然删除tag时,当前tag的下一个tag会被设置ant-tag-hidden
}}
>
<span>{item.serialNumber}</span>
</Tag>
);
})}
</Flex>
</ProCard>
<ProTable
columns={columns}
request={async (params) => {
const res = await postServiceBankStatementQueryBankStatement({
data: {
...params,
writeOffIdIsNull: true,
},
});
return res.data;
}}
options={false}
rowKey="id"
headerTitle="添加银行流水"
/>
</ModalForm>
);
};