Blame view

src/pages/finance/CompanyRelationCreate/components/SelectCorrespondenceUnits.tsx 4.3 KB
38c0cdfa   zhaofeng   往来单位关系设置修改新增、删除
1
  import React, { useState, useEffect, memo } from "react";
fd16749f   zhaofeng   往来单位关系设置
2
  import { Modal, Table, Select, Input, message, Spin, Button, Divider } from "antd";
38c0cdfa   zhaofeng   往来单位关系设置修改新增、删除
3
4
5
6
7
8
  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";
cc26d1fc   张志伟   🎉 重新构建项目,解决项目过大的问题
9
  
fd16749f   zhaofeng   往来单位关系设置
10
11
12
13
14
  interface Props {
    onNext?: () => void;
  }
  
  function SelectModal({ onNext }: Props) {
38c0cdfa   zhaofeng   往来单位关系设置修改新增、删除
15
16
17
18
19
20
21
22
    const {
      visible,
      selected,
      setVisible,
      companyParams,
      comBussinessList,
      comBussinessLoading,
      setDisabled,
fd16749f   zhaofeng   往来单位关系设置
23
24
      selectData,
      setSelectData,
38c0cdfa   zhaofeng   往来单位关系设置修改新增、删除
25
    } = useStore();
38c0cdfa   zhaofeng   往来单位关系设置修改新增、删除
26
  
cc26d1fc   张志伟   🎉 重新构建项目,解决项目过大的问题
27
    const [delay, setDelay] = useState<boolean>(true);
fd16749f   zhaofeng   往来单位关系设置
28
  
38c0cdfa   zhaofeng   往来单位关系设置修改新增、删除
29
30
31
32
33
34
    const {
      list: compList,
      loading,
      paginationConfig,
      setParams,
      innerParams,
9cb5a96a   zhaofeng   关系设置保存
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
    } = 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]);
cc26d1fc   张志伟   🎉 重新构建项目,解决项目过大的问题
51
  
38c0cdfa   zhaofeng   往来单位关系设置修改新增、删除
52
    const fetchListByName = debounce((value) => {
cc26d1fc   张志伟   🎉 重新构建项目,解决项目过大的问题
53
54
55
56
57
58
      setParams({ ...innerParams, keywords: value }, true);
    }, 500);
  
    function searchType(compTypes: number) {
      setParams({ compTypes }, true);
    }
38c0cdfa   zhaofeng   往来单位关系设置修改新增、删除
59
  
cc26d1fc   张志伟   🎉 重新构建项目,解决项目过大的问题
60
    return (
fd16749f   zhaofeng   往来单位关系设置
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
      <>
        <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 }}
38c0cdfa   zhaofeng   往来单位关系设置修改新增、删除
77
          >
fd16749f   zhaofeng   往来单位关系设置
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
            {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>
      </>
cc26d1fc   张志伟   🎉 重新构建项目,解决项目过大的问题
143
144
145
146
    );
  }
  
  export default memo(SelectModal);