| | |
| | | import React, {Component} from 'react' |
| | | import PropTypes from 'prop-types' |
| | | import { Form, Row, Col, Input, Select, Icon, Radio, notification } from 'antd' |
| | | // import moment from 'moment' |
| | | import EditTable from '../editable' |
| | | import './index.scss' |
| | | |
| | | const { TextArea } = Input |
| | | const matchReg = { |
| | | text: [{ |
| | | value: 'like', |
| | | text: 'like' |
| | | }, { |
| | | value: 'not like', |
| | | text: 'not like' |
| | | }, { |
| | | value: '=', |
| | | text: '=' |
| | | }], |
| | | select: [{ |
| | | value: '=', |
| | | text: '=' |
| | | }, { |
| | | value: 'like', |
| | | text: 'like' |
| | | }, { |
| | | value: 'not like', |
| | | text: 'not like' |
| | | }], |
| | | date: [{ |
| | | value: '>=', |
| | | text: '>=' |
| | | }, { |
| | | value: '<=', |
| | | text: '<=' |
| | | }, { |
| | | value: '>', |
| | | text: '>' |
| | | }, { |
| | | value: '<', |
| | | text: '<' |
| | | }, { |
| | | value: '=', |
| | | text: '=' |
| | | }], |
| | | daterange: [{ |
| | | value: 'between', |
| | | text: 'between' |
| | | }] |
| | | } |
| | | |
| | | class MainSearch extends Component { |
| | | static propTpyes = { |
| | |
| | | openTypeChange = (key, value) => { |
| | | if (key === 'type') { |
| | | let _options = ['label', 'field', 'initval', 'type', 'match'] |
| | | if (value === 'select' && this.state.resourceType === '0') { |
| | | _options = [..._options, ...['resourceType', 'setAll', 'options', 'display']] |
| | | } else if (value === 'select' && this.state.resourceType === '1') { |
| | | _options = [..._options, ...['resourceType', 'setAll', 'dataSource', 'valueField', 'valueText', 'orderBy', 'orderType', 'display']] |
| | | } else if (value === 'link' && this.state.resourceType === '0') { |
| | | _options = [..._options, ...['resourceType', 'setAll', 'options', 'linkField', 'display']] |
| | | } else if (value === 'link' && this.state.resourceType === '1') { |
| | | _options = [..._options, ...['resourceType', 'setAll', 'dataSource', 'linkField', 'valueField', 'valueText', 'orderBy', 'orderType', 'display']] |
| | | if (value === 'select' || value === 'link') { // 切换类型为选择或关联时,来源默认为自定义 |
| | | _options = [..._options, 'resourceType', 'setAll', 'options', 'display'] |
| | | } |
| | | |
| | | if (value === 'link') { |
| | | _options = [..._options, 'linkField'] |
| | | } |
| | | |
| | | this.setState({ |
| | | openType: value, |
| | | resourceType: '0', |
| | | formlist: this.state.formlist.map(form => { |
| | | form.hidden = !_options.includes(form.key) |
| | | if (form.key === 'initval') { |
| | |
| | | form.initVal = '' |
| | | form.hidden = true |
| | | } |
| | | |
| | | if (form.key === 'match') { |
| | | if (value === 'text') { |
| | | form.options = matchReg.text |
| | | } else if (value === 'select' || value === 'link') { |
| | | form.options = matchReg.select |
| | | } else if (value === 'date' || value === 'datemonth') { |
| | | form.options = matchReg.date |
| | | } else if (value === 'dateweek' || value === 'daterange') { |
| | | form.options = matchReg.daterange |
| | | } |
| | | form.hidden = true |
| | | } |
| | | return form |
| | | }) |
| | | }, () => { |
| | | this.setState({ |
| | | formlist: this.state.formlist.map(form => { |
| | | if (form.key === 'initval') { |
| | | form.hidden = false |
| | | } |
| | | if (form.key === 'match') { |
| | | form.initVal = form.options[0].value |
| | | form.hidden = false |
| | | } |
| | | return form |
| | |
| | | } |
| | | |
| | | onChange = (e, key) => { |
| | | const { openType } = this.state |
| | | let value = e.target.value |
| | | if (key === 'resourceType') { |
| | | let _options = ['label', 'field', 'initval', 'type', 'match', 'resourceType', 'setAll'] |
| | | if (this.state.openType === 'select' && value === '0') { |
| | | _options = [..._options, ...['options', 'display']] |
| | | } else if (this.state.openType === 'select' && value === '1') { |
| | | _options = [..._options, ...['dataSource', 'valueField', 'valueText', 'orderBy', 'orderType', 'display']] |
| | | } else if (this.state.openType === 'link' && value === '0') { |
| | | _options = [..._options, ...['options', 'linkField', 'display']] |
| | | } else if (this.state.openType === 'link' && value === '1') { |
| | | _options = [..._options, ...['dataSource', 'linkField', 'valueField', 'valueText', 'orderBy', 'orderType', 'display']] |
| | | let _options = ['label', 'field', 'initval', 'type', 'match', 'resourceType', 'setAll', 'display'] |
| | | if (value === '0') { |
| | | _options = [..._options, 'options'] |
| | | } else if (value === '1') { |
| | | _options = [..._options, 'dataSource', 'valueField', 'valueText', 'orderBy', 'orderType'] |
| | | } |
| | | |
| | | if (openType === 'link') { |
| | | _options = [..._options, 'linkField'] |
| | | } |
| | | |
| | | this.setState({ |
| | |
| | | if (!formlist) return |
| | | let type = formlist.filter(cell => cell.key === 'type')[0].initVal |
| | | let resourceType = formlist.filter(cell => cell.key === 'resourceType')[0].initVal |
| | | let _options = ['label', 'field', 'initval', 'type', 'match'] |
| | | if (type === 'select' && resourceType === '0') { |
| | | _options = [..._options, ...['resourceType', 'setAll', 'options', 'display']] |
| | | } else if (type === 'select' && resourceType === '1') { |
| | | _options = [..._options, ...['resourceType', 'setAll', 'dataSource', 'valueField', 'valueText', 'orderBy', 'orderType', 'display']] |
| | | } else if (type === 'link' && resourceType === '0') { |
| | | _options = [..._options, ...['resourceType', 'setAll', 'options', 'linkField', 'display']] |
| | | } else if (type === 'link' && resourceType === '1') { |
| | | _options = [..._options, ...['resourceType', 'setAll', 'dataSource', 'linkField', 'valueField', 'valueText', 'orderBy', 'orderType', 'display']] |
| | | let _options = ['label', 'field', 'initval', 'type', 'match'] // 默认显示项 |
| | | if ((type === 'select' || type === 'link') && resourceType === '0') { // 选择类型、自定义资源 |
| | | _options = [..._options, 'resourceType', 'setAll', 'options', 'display'] |
| | | } else if ((type === 'select' || type === 'link') && resourceType === '1') { // 选择类型、数据源 |
| | | _options = [..._options, 'resourceType', 'setAll', 'dataSource', 'valueField', 'valueText', 'orderBy', 'orderType', 'display'] |
| | | } |
| | | |
| | | if (type === 'link') { // 关联类型、增加关联字段 |
| | | _options = [..._options, 'linkField'] |
| | | } |
| | | |
| | | this.setState({ |
| | |
| | | form.options = this.state.dateoptions[type] |
| | | form.type = 'select' |
| | | } |
| | | if (form.key === 'match') { |
| | | if (type === 'text') { |
| | | form.options = matchReg.text |
| | | } else if (type === 'select' || type === 'link') { |
| | | form.options = matchReg.select |
| | | } else if (type === 'date' || type === 'datemonth') { |
| | | form.options = matchReg.date |
| | | } else if (type === 'dateweek' || type === 'daterange') { |
| | | form.options = matchReg.daterange |
| | | } |
| | | } |
| | | form.hidden = !_options.includes(form.key) |
| | | return form |
| | | }) |