File was renamed from src/templates/modalconfig/searchform/index.jsx |
| | |
| | | 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' |
| | | |
| | |
| | | state = { |
| | | openType: null, |
| | | resourceType: null, |
| | | formlist: null |
| | | formlist: null, |
| | | dateoptions: { |
| | | date: [{value: '', text: '空'}, {value: '0', text: '当天'}, {value: 1, text: '前一天'}, {value: 3, text: '前三天'}, {value: 7, text: '前七天'}, {value: 30, text: '前30天'}], |
| | | dateweek: [{value: '', text: '空'}, {value: '0', text: '本周'}, {value: 1, text: '上周'}, {value: 3, text: '前三周'}, {value: 7, text: '前七周'}], |
| | | datemonth: [{value: '', text: '空'}, {value: '0', text: '本月'}, {value: 1, text: '上月'}, {value: 3, text: '前三月'}, {value: 7, text: '前七月'}], |
| | | daterange: [{value: '', text: '空'}, {value: '0', text: '今天'}, {value: 1, text: '昨天'}, {value: 3, text: '前三天'}, {value: 7, text: '前七天'}, {value: 30, text: '前30天'}], |
| | | } |
| | | } |
| | | |
| | | openTypeChange = (key, value) => { |
| | | if (key === 'type') { |
| | | let _options = ['label', 'field', 'initval', 'type'] |
| | | 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'] |
| | | } |
| | | |
| | | 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') { |
| | | if (this.state.dateoptions.hasOwnProperty(value)) { |
| | | form.options = this.state.dateoptions[value] |
| | | form.type = 'select' |
| | | } else { |
| | | form.type = 'text' |
| | | } |
| | | form.initVal = '' |
| | | form.hidden = true |
| | | } |
| | | return form |
| | | }) |
| | | }, () => { |
| | | this.setState({ |
| | | formlist: this.state.formlist.map(form => { |
| | | if (form.key === 'initval') { |
| | | 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', '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']] |
| | | 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 (item.hidden) return |
| | | |
| | | if (item.type === 'text') { // 文本搜索 |
| | | let placeholder = '' |
| | | if (item.key === 'initval' && this.state.openType === 'date') { |
| | | placeholder = '例:' + moment().format('YYYY-MM-DD') |
| | | } else if (item.key === 'initval' && this.state.openType === 'datetime') { |
| | | placeholder = '例:' + moment().format('YYYY-MM-DD HH:mm:ss') |
| | | } |
| | | fields.push( |
| | | <Col span={12} key={index}> |
| | | <Form.Item label={item.label}> |
| | |
| | | message: this.props.dict['form.required.input'] + item.label + '!' |
| | | } |
| | | ] |
| | | })(<Input placeholder={placeholder} autoComplete="off" disabled={item.readonly} />)} |
| | | })(<Input placeholder="" autoComplete="off" disabled={item.readonly} />)} |
| | | </Form.Item> |
| | | </Col> |
| | | ) |
| | |
| | | getPopupContainer={() => document.getElementById('commontable-search-form-box')} |
| | | > |
| | | {item.options.map(option => |
| | | <Select.Option id={option.MenuID} title={option.text} key={option.MenuID} value={option.MenuID}> |
| | | <Select.Option id={option.value} title={option.text} key={option.value} value={option.value}> |
| | | {item.key === 'icon' && <Icon type={option.text} />} {option.text} |
| | | </Select.Option> |
| | | )} |
| | |
| | | { |
| | | item.options.map(option => { |
| | | return ( |
| | | <Radio key={option.MenuID} value={option.MenuID}>{option.text}</Radio> |
| | | <Radio key={option.value} value={option.value}>{option.text}</Radio> |
| | | ) |
| | | }) |
| | | } |
| | |
| | | </Form.Item> |
| | | </Col> |
| | | ) |
| | | |
| | | } else if (item.type === 'textarea') { |
| | | fields.push( |
| | | <Col span={20} offset={4} key={index}> |
| | |
| | | ) |
| | | } |
| | | }) |
| | | |
| | | return fields |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | if (isvalid) { |
| | | resolve({ |
| | | type: 'search', |
| | | values |
| | | }) |
| | | resolve(values) |
| | | } else { |
| | | notification.warning({ |
| | | top: 92, |
| | |
| | | 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'] |
| | | 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'] // 默认显示项 |
| | | if ((type === 'select' || type === 'link') && resourceType === '0') { // 选择类型、自定义资源 |
| | | _options = [..._options, 'resourceType', 'setAll', 'options'] |
| | | } else if ((type === 'select' || type === 'link') && resourceType === '1') { // 选择类型、数据源 |
| | | _options = [..._options, 'resourceType', 'setAll', 'dataSource', 'valueField', 'valueText', 'orderBy', 'orderType'] |
| | | } |
| | | |
| | | if (type === 'link') { // 关联类型、增加关联字段 |
| | | _options = [..._options, 'linkField'] |
| | | } |
| | | |
| | | this.setState({ |
| | | openType: type, |
| | | resourceType: resourceType, |
| | | formlist: formlist.map(form => { |
| | | if (this.state.dateoptions.hasOwnProperty(type) && form.key === 'initval') { |
| | | form.options = this.state.dateoptions[type] |
| | | form.type = 'select' |
| | | } |
| | | form.hidden = !_options.includes(form.key) |
| | | return form |
| | | }) |