From 2cb65d99c9aebf8293cb2838fcfe3e09fb2739ce Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期五, 06 十二月 2019 00:15:12 +0800 Subject: [PATCH] 2019-12-06 --- src/templates/modalconfig/modalform/index.jsx | 101 ++++++++++++++++++++++++++++++-------------------- 1 files changed, 60 insertions(+), 41 deletions(-) diff --git a/src/templates/modalconfig/searchform/index.jsx b/src/templates/modalconfig/modalform/index.jsx similarity index 69% rename from src/templates/modalconfig/searchform/index.jsx rename to src/templates/modalconfig/modalform/index.jsx index f4d2ac1..2583990 100644 --- a/src/templates/modalconfig/searchform/index.jsx +++ b/src/templates/modalconfig/modalform/index.jsx @@ -1,7 +1,6 @@ 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' @@ -17,44 +16,69 @@ 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({ @@ -74,12 +98,6 @@ 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}> @@ -91,7 +109,7 @@ 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> ) @@ -115,7 +133,7 @@ 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> )} @@ -141,7 +159,7 @@ { 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> ) }) } @@ -150,7 +168,6 @@ </Form.Item> </Col> ) - } else if (item.type === 'textarea') { fields.push( <Col span={20} offset={4} key={index}> @@ -175,6 +192,7 @@ ) } }) + return fields } @@ -204,10 +222,7 @@ } if (isvalid) { - resolve({ - type: 'search', - values - }) + resolve(values) } else { notification.warning({ top: 92, @@ -226,21 +241,25 @@ 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 }) -- Gitblit v1.8.0