import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
import { fromJS } from 'immutable'
|
import { Form, Row, Col, Input, Button } from 'antd'
|
|
import asyncComponent from '@/utils/asyncComponent'
|
import './index.scss'
|
|
const { Search } = Input
|
const MKCheckCard = asyncComponent(() => import('@/tabviews/zshare/mutilform/checkCard'))
|
const MKSelect = asyncComponent(() => import('../mkSelect'))
|
const MKDatePicker = asyncComponent(() => import('../mkDatePicker'))
|
|
class AdvanceSearch extends Component {
|
static propTpyes = {
|
record: PropTypes.object, // 搜索条件值
|
searchlist: PropTypes.array, // 搜索条件列表
|
advanceSubmit: PropTypes.func, // 搜索条件提交
|
handleClose: PropTypes.func // 关闭
|
}
|
|
state = {
|
searchlist: fromJS(this.props.searchlist).toJS()
|
}
|
|
getFields() {
|
const { getFieldDecorator } = this.props.form
|
const { record } = this.props
|
const fields = []
|
|
this.state.searchlist.forEach((item, index) => {
|
if (!item.advanced || item.hidden) return
|
|
const _rules = [
|
{
|
required: item.required,
|
message: item.label + '不可为空!'
|
}
|
]
|
|
let content = null
|
item.initval = record[item.field] || ''
|
|
if (item.type === 'text') {
|
if (item.inputType === 'search') {
|
content = <Search placeholder={item.labelShow === 'false' ? item.label : ''} autoComplete="off" onSearch={this.handleSubmit} enterButton/>
|
} else {
|
content = <Input placeholder={item.labelShow === 'false' ? item.label : ''} autoComplete="off" onPressEnter={this.handleSubmit} />
|
}
|
} else if (item.type === 'select' || item.type === 'link' || item.type === 'multiselect') {
|
content = (<MKSelect config={item}/>)
|
} else if (item.type === 'date' || item.type === 'datemonth' || item.type === 'dateweek' || item.type === 'daterange') {
|
content = (<MKDatePicker config={item}/>)
|
} else if (item.type === 'checkcard') {
|
content = <MKCheckCard card={item}/>
|
}
|
|
if (content) {
|
fields.push(
|
<Col span={item.ratio || 6} key={index}>
|
<Form.Item label={item.labelShow !== 'false' ? item.label : ''}>
|
{getFieldDecorator(item.field, {
|
initialValue: item.initval,
|
rules: _rules
|
})(content)}
|
</Form.Item>
|
</Col>
|
)
|
}
|
})
|
|
return fields
|
}
|
|
handleSubmit = () => {
|
// 回车或点击搜索
|
this.props.form.validateFields((err, values) => {
|
if (err) return
|
|
this.props.advanceSubmit(values)
|
})
|
}
|
|
render() {
|
const formItemLayout = {
|
labelCol: {
|
xs: { span: 24 },
|
sm: { span: 8 }
|
},
|
wrapperCol: {
|
xs: { span: 24 },
|
sm: { span: 16 }
|
}
|
}
|
|
return (
|
<Form {...formItemLayout} className="advance-search">
|
<Row gutter={24}>{this.getFields()}</Row>
|
<div className="advance-button">
|
<Button style={{ marginRight: 8 }} onClick={this.props.handleClose}>
|
关闭
|
</Button>
|
<Button type="primary" onClick={this.handleSubmit}>
|
确定
|
</Button>
|
</div>
|
</Form>
|
)
|
}
|
}
|
|
export default Form.create()(AdvanceSearch)
|