import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
import { Form, Row, Col, Input, Select, Icon, Radio } from 'antd'
|
import './index.scss'
|
|
const btnIcons = [{
|
MenuID: '',
|
text: 'unset'
|
}, {
|
MenuID: 'plus',
|
text: 'plus'
|
}, {
|
MenuID: 'plus-circle',
|
text: 'plus-circle'
|
}, {
|
MenuID: 'edit',
|
text: 'edit'
|
}, {
|
MenuID: 'form',
|
text: 'form'
|
}, {
|
MenuID: 'close',
|
text: 'close'
|
}, {
|
MenuID: 'close-circle',
|
text: 'close-circle'
|
}, {
|
MenuID: 'delete',
|
text: 'delete'
|
}]
|
|
const btnClasses = [{
|
MenuID: 'default',
|
text: '默认(黑边白底)'
|
}, {
|
MenuID: 'primary',
|
text: '蓝色'
|
}, {
|
MenuID: 'yellow',
|
text: '黄色'
|
}, {
|
MenuID: 'danger',
|
text: '红色'
|
}, {
|
MenuID: 'green',
|
text: '绿色'
|
}, {
|
MenuID: 'dgreen',
|
text: '深绿色'
|
}, {
|
MenuID: 'purple',
|
text: '紫色'
|
}, {
|
MenuID: 'gray',
|
text: '灰色'
|
}]
|
|
class MainSearch extends Component {
|
static propTpyes = {
|
dict: PropTypes.object, // 字典项
|
formlist: PropTypes.any,
|
card: PropTypes.any
|
}
|
|
state = {
|
formlist: null,
|
openType: null,
|
interType: null,
|
expand: false
|
}
|
|
openTypeChange = (key, value) => {
|
if (key === 'OpenType') {
|
let _options = null
|
if (value === 'newpage') {
|
_options = ['label', 'position', 'Ot', 'OpenType', 'pageTemplate', 'icon', 'class']
|
}
|
this.setState({
|
openType: value,
|
expand: value === 'newpage' ? false : this.state.expand,
|
formlist: this.state.formlist.map(item => {
|
if (_options) {
|
item.hidden = !_options.includes(item.key)
|
if (item.key === 'intertype') {
|
item.initVal = 'inner'
|
}
|
item.readonly = ['interface', 'outerFunc', 'callbackFunc'].includes(item.key)
|
}
|
return item
|
})
|
})
|
}
|
}
|
|
onChange = (e, key) => {
|
let value = e.target.value
|
if (key === 'intertype') {
|
this.setState({
|
interType: value,
|
formlist: this.state.formlist.map(item => {
|
if (value === 'inner') {
|
item.readonly = ['interface', 'outerFunc', 'callbackFunc'].includes(item.key)
|
} else {
|
item.readonly = false
|
}
|
return item
|
})
|
})
|
}
|
}
|
|
getFields() {
|
const { getFieldDecorator } = this.props.form
|
const fields = []
|
this.state.formlist.forEach((item, index) => {
|
if (item.hidden) return
|
|
if (item.type === 'text') { // 文本搜索
|
fields.push(
|
<Col span={12} key={index}>
|
<Form.Item label={item.label}>
|
{getFieldDecorator(item.key, {
|
initialValue: item.initVal || '',
|
rules: [
|
{
|
required: item.readonly ? false : !!item.required,
|
message: this.props.dict['form.required.input'] + item.label + '!'
|
}
|
]
|
})(<Input placeholder="" autoComplete="off" disabled={item.readonly} />)}
|
</Form.Item>
|
</Col>
|
)
|
} else if (item.type === 'select') { // 下拉搜索
|
fields.push(
|
<Col span={12} key={index}>
|
<Form.Item label={item.label}>
|
{getFieldDecorator(item.key, {
|
initialValue: item.initVal || '',
|
rules: [
|
{
|
required: !!item.required,
|
message: this.props.dict['form.required.select'] + item.label + '!'
|
}
|
]
|
})(
|
<Select
|
showSearch
|
filterOption={(input, option) => option.props.children[2].toLowerCase().indexOf(input.toLowerCase()) >= 0}
|
onChange={(value) => {this.openTypeChange(item.key, value)}}
|
getPopupContainer={() => document.getElementById('winter')}
|
>
|
{item.options.map(option =>
|
<Select.Option id={option.MenuID} title={option.text} key={option.MenuID} value={option.MenuID}>
|
{item.key === 'icon' && option.MenuID && <Icon type={option.MenuID} />} {option.text}
|
</Select.Option>
|
)}
|
</Select>
|
)}
|
</Form.Item>
|
</Col>
|
)
|
} else if (item.type === 'radio') {
|
fields.push(
|
<Col span={12} key={index}>
|
<Form.Item label={item.label}>
|
{getFieldDecorator(item.key, {
|
initialValue: item.initVal,
|
rules: [
|
{
|
required: !!item.required,
|
message: this.props.dict['form.required.select'] + item.label + '!'
|
}
|
]
|
})(
|
<Radio.Group onChange={(e) => {this.onChange(e, item.key)}}>
|
{
|
item.options.map(option => {
|
return (
|
<Radio key={option.MenuID} value={option.MenuID}>{option.text}</Radio>
|
)
|
})
|
}
|
</Radio.Group>
|
)}
|
</Form.Item>
|
</Col>
|
)
|
}
|
})
|
return fields
|
}
|
|
handleConfirm = () => {
|
// 表单提交时检查输入值是否正确
|
return new Promise((resolve, reject) => {
|
this.props.form.validateFieldsAndScroll((err, values) => {
|
if (!err) {
|
values.id = this.props.card.id
|
values.uuid = this.props.card.uuid
|
if (!this.state.expand) {
|
values.intertype = 'inner'
|
}
|
resolve({
|
type: 'action',
|
values
|
})
|
} else {
|
reject(err)
|
}
|
})
|
})
|
}
|
|
toggle = () => {
|
let expand = !this.state.expand
|
let _options = null
|
if (expand) {
|
_options = ['label', 'position', 'OpenType', 'intertype', 'innerFunc', 'interface', 'outerFunc', 'callbackFunc', 'Ot', 'icon', 'class']
|
} else {
|
_options = ['label', 'position', 'OpenType', 'innerFunc', 'Ot', 'icon', 'class']
|
}
|
if (!expand) {
|
this.setState({
|
expand: !this.state.expand,
|
formlist: this.state.formlist.map(item => {
|
if (item.key === 'intertype') {
|
item.initVal = 'inner'
|
}
|
item.readonly = ['interface', 'outerFunc', 'callbackFunc'].includes(item.key)
|
item.hidden = !_options.includes(item.key)
|
return item
|
})
|
})
|
} else {
|
this.setState({
|
expand: !this.state.expand,
|
formlist: this.state.formlist.map(item => {
|
item.hidden = !_options.includes(item.key)
|
return item
|
})
|
})
|
}
|
}
|
|
UNSAFE_componentWillMount () {
|
let _opentype = this.props.formlist.filter(form => form.key === 'OpenType')[0].initVal
|
let _intertype = this.props.formlist.filter(form => form.key === 'intertype')[0].initVal
|
let _options = null
|
if (_opentype === 'newpage') {
|
_options = ['label', 'Ot', 'OpenType', 'pageTemplate', 'icon', 'class', 'position']
|
} else {
|
if (_intertype === 'outer') {
|
_options = ['label', 'position', 'OpenType', 'intertype', 'innerFunc', 'interface', 'outerFunc', 'callbackFunc', 'Ot', 'icon', 'class']
|
} else {
|
_options = ['label', 'position', 'OpenType', 'innerFunc', 'Ot', 'icon', 'class']
|
}
|
}
|
this.setState({
|
openType: _opentype,
|
interType: _intertype,
|
expand: _intertype === 'outer' ? true : false,
|
formlist: this.props.formlist.map(item => {
|
if (item.key === 'class') {
|
item.options = btnClasses
|
} else if (item.key === 'icon') {
|
item.options = btnIcons
|
}
|
if (_intertype === 'inner') {
|
item.readonly = ['interface', 'outerFunc', 'callbackFunc'].includes(item.key)
|
}
|
item.hidden = !_options.includes(item.key)
|
return item
|
})
|
})
|
}
|
|
render() {
|
const formItemLayout = {
|
labelCol: {
|
xs: { span: 24 },
|
sm: { span: 7 }
|
},
|
wrapperCol: {
|
xs: { span: 24 },
|
sm: { span: 17 }
|
}
|
}
|
return (
|
<Form {...formItemLayout} className="ant-advanced-search-form commontable-action-form" id="winter">
|
<Row gutter={24}>{this.getFields()}</Row>
|
{this.state.openType !== 'newpage' && <Row>
|
<Col span={24} style={{ textAlign: 'right' }}>
|
<span className="superconfig" onClick={this.toggle}>
|
高级设置 <Icon type={this.state.expand ? 'up' : 'down'} />
|
</span>
|
</Col>
|
</Row>}
|
</Form>
|
)
|
}
|
}
|
|
export default Form.create()(MainSearch)
|