Blame view

src/pages/finance/CompanyRelationCreate/components/Filter.tsx 4.19 KB
fd16749f   zhaofeng   往来单位关系设置
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
  import React from "react";
  import { Button, Col, Popconfirm, Row, Select, Input, message } from "antd";
  import { useStore } from "../index";
  import { CompanyCategoryTypeEnum } from "@/pages/finance/entitys";
  import { debounce } from "lodash";
  import { deleteCompanyRelationApi } from '@/pages/finance/CompanyRelationAuth/api';
  import { history } from 'umi';
  
  const Search = Input.Search;
  const { Option } = Select;
  
  export default function Filter() {
    const {
      setVisible,
      dealerList,
      setCompanyParams,
      dealerLoading,
      disabled,
      setDisabled,
      setSelected,
      companyList,
      comBussinessList,
      selectedRelation,
      submitLoading,
      setSubmitLoading,
      companyParams,
      setLoading,
    } = useStore();
    const searchDealer = (dealerId: number) => {
      setCompanyParams({ ...companyParams, dealerId }, true);
    };
  
    function searchType(compCategory: number) {
      setCompanyParams({ ...companyParams, compCategory }, true);
    }
  
    function searchCompanyType(companyType: number) {
      setCompanyParams({ ...companyParams, companyType }, true);
    }
  
    const fetchListByName = debounce((value) => {
      setCompanyParams({ ...companyParams, keywords: value }, true);
    }, 500);
  
    function onCancel() {
      setDisabled(true);
      setSelected([...companyList]);
    }
  
    function onEdit() {
      setDisabled(false);
    }
  
    // 新增
    function onAdd() {
      history.push("/finance2/companyRelationAuth/create");
    }
    /**
     * @param compId
     */
    async function onDelete() {
      const compIdList = selectedRelation.map((item) => item.compId);
      try {
        const pa = { ...companyParams, compIdList};
        setSubmitLoading(true);
        const { success, result } = await deleteCompanyRelationApi(pa);
        setSubmitLoading(false);
  
        if (!success) {
          return message.error(result);
        } else {
          message.success(result);
          setLoading(true);
        }
      } catch (e) {
        setSubmitLoading(false);
        message.error(e.message);
      }
    }
  
    return (
      <div
        style={{
          display: "flex",
          flexDirection: "row",
          justifyContent: "space-between",
          alignItems: "center",
          marginBottom: 20,
        }}
      >
        <Row style={{ display: "flex", flex: 1 }}>
          <Col span={9}>
            <Select
              placeholder="请选择商家"
              showSearch
              loading={dealerLoading}
              disabled={!disabled}
              optionFilterProp="children"
              onChange={searchDealer}
              value={companyParams.dealerId}
              style={{ width: "80%" }}
            >
              {dealerList.map((dealer) => (
                <Option value={dealer.id} key={dealer.id}>
                  {dealer.name}
                </Option>
              ))}
            </Select>
          </Col>
          <Col span={5}>
            <Search
              allowClear
              disabled={!disabled}
              placeholder="搜索单位名称"
              onChange={(e) => fetchListByName(e.target.value || undefined)}
              style={{ width: 200 }}
            />
          </Col>
          <Col span={3}>
            <Select
              placeholder="搜索单位类别"
              disabled={!disabled}
              onChange={searchType}
              value={companyParams.compCategory}
              style={{ width: 100 }}
            >
              {[1, 2].map((i) => (
                <Option value={i} key={i}>
                  {CompanyCategoryTypeEnum[i]}
                </Option>
              ))}
            </Select>
          </Col>
          <Col>
            <Select placeholder="搜索类型" disabled={!disabled} onChange={searchCompanyType} style={{ width: 150 }}>
              {comBussinessList.map((item) => (
                <Option key={item.id} value={item.id}>
                  {item.name}
                </Option>
              ))}
            </Select>
          </Col>
        </Row>
        <div style={{ display: "flex", flexDirection: "row-reverse" }}>
          <Button type="primary" onClick={onAdd}>
            新增
          </Button>
  
          <Popconfirm title="确定删除?" onConfirm={onDelete}>
            <Button style={{marginRight:10}} hidden={!selectedRelation.length} danger  loading={submitLoading}>
              删除
            </Button>
          </Popconfirm>
        </div>
      </div>
    );
  }