king
2024-01-05 148f6930874cb0a07bd7279e4b39fa708bd720eb
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
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { Form, Row, Col, Select, Button, Input, Transfer } from 'antd'
 
import './index.scss'
 
class ColsCtrlForm extends Component {
  static propTpyes = {
    columns: PropTypes.array,
    markChange: PropTypes.func
  }
 
  state = {
    targetKeys: [],
    editItem: null
  }
 
  edit = (item) => {
    this.setState({editItem: item, targetKeys: item.cols})
 
    this.props.form.setFieldsValue({
      field: item.field,
      match: item.match,
      contrastValue: item.contrastValue,
      cols: item.cols
    })
  }
 
  handleConfirm = () => {
    const { editItem } = this.state
 
    // 表单提交时检查输入值是否正确
    this.props.form.validateFieldsAndScroll((err, values) => {
      if (!err) {
        if (editItem) {
          values.uuid = editItem.uuid
        }
 
        this.props.markChange(values)
 
        this.setState({targetKeys: null}, () => {
          this.setState({editItem: null, targetKeys: []})
        })
      }
    })
  }
 
  handleCancel = () => {
    this.setState({targetKeys: null}, () => {
      this.setState({editItem: null, targetKeys: []})
    })
  }
 
  handleChange = (newTargetKeys) => {
    this.setState({targetKeys: newTargetKeys})
  }
 
  render() {
    const { columns, searches } = this.props
    const { getFieldDecorator } = this.props.form
    const { targetKeys, editItem } = this.state
 
    return (
      <Form className="normal-table-cols-form">
        <Row gutter={24}>
          <Col span={6}>
            <Form.Item label="字段">
              {getFieldDecorator('field', {
                initialValue: [],
                rules: [
                  {
                    required: true,
                    message: '请选择字段!'
                  }
                ]
              })(
                <Select mode="multiple">
                  {searches.map((item, i) => (<Select.Option key={i} value={item.value}> {item.label} </Select.Option>))}
                </Select>
              )}
            </Form.Item>
          </Col>
          <Col span={6}>
            <Form.Item label="对比方式">
              {getFieldDecorator('match', {
                initialValue: '=',
                rules: [
                  {
                    required: true,
                    message: '请选择对比方式!'
                  }
                ]
              })(
                <Select>
                  <Select.Option value="="> = </Select.Option>
                  <Select.Option value="!="> != </Select.Option>
                  <Select.Option value=">"> &gt; </Select.Option>
                  <Select.Option value="<"> &lt; </Select.Option>
                </Select>
              )}
            </Form.Item>
          </Col>
          <Col span={6}>
            <Form.Item label="对比值">
              {getFieldDecorator('contrastValue', {
                initialValue: ''
              })(<Input placeholder="" autoComplete="off" />)}
            </Form.Item>
          </Col>
          <Col span={6} style={{padding: '5px 0px 0px 30px'}}>
            <Button onClick={this.handleConfirm} type="primary" className="mk-green">
              {editItem ? '保存' : '添加'}
            </Button>
            {editItem ? <Button style={{marginLeft: '15px'}} onClick={this.handleCancel}>
              取消
            </Button> : null}
          </Col>
          {targetKeys ? <Col span={18} style={{clear: 'left'}}>
            <Form.Item label="显示列">
              {getFieldDecorator('cols', {
                initialValue: [],
                rules: [
                  {
                    required: true,
                    message: '请选择显示列!'
                  }
                ]
              })(
                <Transfer
                  targetKeys={targetKeys}
                  dataSource={columns}
                  render={item => item.title}
                  onChange={this.handleChange}
                />
              )}
            </Form.Item>
          </Col> : null}
        </Row>
      </Form>
    )
  }
}
 
export default Form.create()(ColsCtrlForm)