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=">"> > </Select.Option>
|
<Select.Option value="<"> < </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}>
|
<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)
|