SelectCorrespondenceUnits.tsx
4.3 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
import React, { useState, useEffect, memo } from "react";
import { Modal, Table, Select, Input, message, Spin, Button, Divider } from "antd";
import Column from "antd/lib/table/Column";
import { RecordStateEnum } from "@/pages/finance/entitys";
import usePagination from "@/hooks/usePagination";
import { getCompAccountApi } from "@/pages/finance/TradeCompany/api";
import { useStore } from "../index";
import { debounce } from "lodash";
interface Props {
onNext?: () => void;
}
function SelectModal({ onNext }: Props) {
const {
visible,
selected,
setVisible,
companyParams,
comBussinessList,
comBussinessLoading,
setDisabled,
selectData,
setSelectData,
} = useStore();
const [delay, setDelay] = useState<boolean>(true);
const {
list: compList,
loading,
paginationConfig,
setParams,
innerParams,
} = usePagination<TradeCompany.ComList>(
getCompAccountApi,
{
compCategory: companyParams.compCategory,
excludeDealerId: companyParams.dealerId,
recordState: RecordStateEnum["已备案"],
},
{ delay }
);
useEffect(() => {
if (companyParams.dealerId !== -1) {
setDelay(false);
setParams({ compCategory: companyParams.compCategory, excludeDealerId: companyParams.dealerId }, true);
}
}, [companyParams]);
const fetchListByName = debounce((value) => {
setParams({ ...innerParams, keywords: value }, true);
}, 500);
function searchType(compTypes: number) {
setParams({ compTypes }, true);
}
return (
<>
<div style={{ display: "flex", flexDirection: "row", marginBottom: 20 }}>
<Input.Search
allowClear
placeholder="搜索单位名称/社会信用代码"
onChange={(e) => fetchListByName(e.target.value || undefined)}
style={{ width: 250, marginRight: 10 }}
/>
<Select
placeholder="搜索业务类型"
showSearch
allowClear
optionFilterProp="children"
loading={comBussinessLoading}
onChange={searchType}
style={{ width: 200 }}
>
{comBussinessList.map((item) => (
<Select.Option key={item.id} value={item.id}>
{item.name}
</Select.Option>
))}
</Select>
</div>
<Table
loading={loading}
dataSource={compList}
pagination={{ ...paginationConfig, showSizeChanger: false }}
rowKey="id"
rowSelection={{
type: "checkbox",
selectedRowKeys: selectData.map((row) => row.id as number),
onSelect: (row: any, _selected: boolean) => {
const index = selectData.findIndex((_row) => _row.id == row.id);
if (_selected) {
selectData.unshift(row);
} else if (index > -1) {
selectData.splice(index, 1);
}
setSelectData([...selectData]);
},
onSelectAll: (selected, selectedRows, changeRows) => {
const changedKeys = changeRows.map((row) => row.id);
let newData = [];
// 全选
if (selected) {
// 过滤掉已选的
newData = selectData.concat(changeRows.filter((row) => !selectData.some((item) => item == row.id)));
} else {
// 全不选 - 去掉已选的
newData = selectData.filter((row) => !changedKeys.find((y) => y === row.id));
}
setSelectData(newData);
},
}}
>
<Column title="账户名称" dataIndex="compName" />
<Column title="业务类型" dataIndex="compTypeName" />
<Column title="社会信用代码" dataIndex="creditCode" width="15%" />
</Table>
<div style={{ width: "100%", textAlign: "center", marginTop: 30 }}>
<Button type="primary" style={{ marginBottom: 10 }} onClick={() => history.back()}>
返回列表
</Button>
{!!selectData.length && (
<>
<Divider type="vertical" />
<Button
type="primary"
style={{ marginBottom: 10 }}
onClick={() => {
onNext && onNext();
}}
>
下一步
</Button>
</>
)}
</div>
</>
);
}
export default memo(SelectModal);