| | |
| | | import React, {Component} from 'react' |
| | | import PropTypes from 'prop-types' |
| | | import { Form, Row, Col, Input, Button, Select, DatePicker } from 'antd' |
| | | import { Form, Row, Col, Input, Button, Select, DatePicker, notification } from 'antd' |
| | | import moment from 'moment' |
| | | import './index.scss' |
| | | |
| | |
| | | } |
| | | |
| | | UNSAFE_componentWillMount () { |
| | | let searchlist = JSON.parse(JSON.stringify(this.props.searchlist)) |
| | | let match = {} |
| | | let style = {} |
| | | let _list = [] |
| | | let fieldMap = new Map() |
| | | |
| | | this.props.searchlist.forEach(item => { |
| | | searchlist.forEach(item => { |
| | | if (fieldMap.has(item.field)) { |
| | | item.field = item.field + '@tail@' |
| | | } |
| | |
| | | match[item.field] = item.match |
| | | style[item.field] = item.type |
| | | |
| | | if (item.type === 'select' || item.type === 'link') { |
| | | item.oriOptions = JSON.parse(JSON.stringify(item.options)) |
| | | } |
| | | |
| | | _list.push(item) |
| | | }) |
| | | |
| | | let error = false |
| | | |
| | | _list = _list.map(item => { |
| | | if (item.type === 'link') { |
| | | let supItem = _list.filter(form => form.field === item.linkField)[0] |
| | | |
| | | if (!supItem) { |
| | | error = true |
| | | } else { |
| | | item.options = item.oriOptions.filter(option => option.parentId === supItem.initval) |
| | | } |
| | | } |
| | | |
| | | return item |
| | | }) |
| | | |
| | | if (error) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '关联菜单设置错误!', |
| | | duration: 10 |
| | | }) |
| | | } |
| | | |
| | | this.setState({ |
| | | match: match, |
| | | style: style, |
| | | searchlist: _list |
| | | }) |
| | | } |
| | | |
| | | UNSAFE_componentWillReceiveProps() { |
| | | let searchlist = JSON.parse(JSON.stringify(this.props.searchlist)) |
| | | let _list = [] |
| | | let fieldMap = new Map() |
| | | |
| | | searchlist.forEach(item => { |
| | | if (fieldMap.has(item.field)) { |
| | | item.field = item.field + '@tail@' |
| | | } |
| | | fieldMap.set(item.field, true) |
| | | |
| | | if (item.type === 'select' || item.type === 'link') { |
| | | item.oriOptions = JSON.parse(JSON.stringify(item.options)) |
| | | } |
| | | |
| | | _list.push(item) |
| | | }) |
| | | |
| | | _list = _list.map(item => { |
| | | if (item.type === 'link') { |
| | | let supItem = _list.filter(form => form.field === item.linkField)[0] |
| | | |
| | | if (supItem) { |
| | | item.options = item.oriOptions.filter(option => option.parentId === supItem.initval) |
| | | } |
| | | } |
| | | |
| | | return item |
| | | }) |
| | | |
| | | this.setState({ |
| | | searchlist: _list |
| | | }) |
| | | } |
| | | |
| | | resetform = (formlist, supfields, index) => { |
| | | index++ |
| | | let subfields = [] |
| | | |
| | | supfields.forEach(supfield => { |
| | | formlist = formlist.map(item => { |
| | | if (item.type === 'link' && item.linkField === supfield.field) { |
| | | item.options = item.oriOptions.filter(option => option.parentId === supfield.initval) |
| | | item.initval = item.options[0] ? item.options[0].Value : '' |
| | | item.hiden = true |
| | | |
| | | subfields.push(item) |
| | | } |
| | | return item |
| | | }) |
| | | }) |
| | | |
| | | if (subfields.length === 0 || index > 6) { |
| | | return formlist |
| | | } else { |
| | | return this.resetform(formlist, subfields, index) |
| | | } |
| | | } |
| | | |
| | | selectChange = (_field, value) => { |
| | | let formlist = JSON.parse(JSON.stringify(this.state.searchlist)) |
| | | |
| | | let subfields = [] |
| | | formlist = formlist.map(item => { |
| | | if (item.type === 'link' && item.linkField === _field.field) { |
| | | item.options = item.oriOptions.filter(option => option.parentId === value) |
| | | item.initval = item.options[0] ? item.options[0].Value : '' |
| | | item.hiden = true |
| | | |
| | | subfields.push(item) |
| | | } |
| | | return item |
| | | }) |
| | | |
| | | if (subfields.length === 0) { |
| | | this.searchChange() |
| | | return |
| | | } |
| | | |
| | | formlist = this.resetform(formlist, subfields, 0) |
| | | |
| | | this.setState({ |
| | | searchlist: formlist |
| | | }, () => { |
| | | this.setState({ |
| | | searchlist: formlist.map(item => { |
| | | item.hiden = false |
| | | return item |
| | | }) |
| | | }, () => { |
| | | this.searchChange() |
| | | }) |
| | | }) |
| | | } |
| | | |
| | |
| | | {getFieldDecorator(item.field, {initialValue: item.initval })( |
| | | <Select |
| | | showSearch |
| | | onChange={this.searchChange} |
| | | // onChange={this.searchChange} |
| | | onChange={(value) => {this.selectChange(item, value)}} |
| | | filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0} |
| | | > |
| | | {item.options.map(option => |