Modal

列表搜索弹窗

import React, { PureComponent } from "react";
import { Form, Row, Col, Input, Button, Modal, Table } from "antd";

const FormItem = Form.Item;

@Form.create()
export default class MatchModal extends PureComponent {
  state = {};

  static defaultProps = {
    dataSource: [],
    onSearch() {}
  };

  filterData = {};

  handleSearch = e => {
    e.preventDefault();
    const {
      onSearch,
      form: { getFieldsValue }
    } = this.props;
    const fieldsValue = getFieldsValue();
    onSearch(fieldsValue);
  };

  handleReset = () => {
    const {
      form: { resetFields }
    } = this.props;
    resetFields();
  };

  handleTableChange = ({ current, pageSize }) => {
    const { onSearch } = this.props;
    onSearch({ ...this.filterData, pageNumber: current, pageSize });
  };

  render() {
    const {
      dataSource,
      loading,
      pagination,
      form: { getFieldDecorator },
      ...restProps
    } = this.props;

    const columns = [
      {
        title: "年份",
        dataIndex: "title",
        render: (text, record) => text
      }
    ];

    const tableProps = {
      columns,
      dataSource,
      loading,
      pagination: false,
      onChange: this.handleTableChange
    };

    return (
      <Modal {...restProps}>
        <Form onSubmit={this.handleSearch}>
          <Row gutter={24}>
            <Col span={8}>
              <FormItem label="赛事年份">
                {getFieldDecorator("title")(
                  <Input placeholder="请输入赛事年份" />
                )}
              </FormItem>
            </Col>
            <Col span={8}>
              <FormItem label="赛事名称">
                {getFieldDecorator("title")(
                  <Input placeholder="请输入赛事名称" />
                )}
              </FormItem>
            </Col>
            <Col span={8}>
              <FormItem>
                <Button type="primary" htmlType="submit">
                  查询
                </Button>
                <Button style={{ marginLeft: 8 }} onClick={this.handleReset}>
                  重置
                </Button>
              </FormItem>
            </Col>
          </Row>
          <Row>
            <Col>
              <FormItem>
                <Table {...tableProps} />
              </FormItem>
            </Col>
          </Row>
        </Form>
      </Modal>
    );
  }
}
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
上次更新: 9/23/2019, 10:45:38 AM