From 75623dd039b742dbb44fb4c6b4af563404ed9c7f Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期一, 03 二月 2020 16:06:04 +0800 Subject: [PATCH] 2020-02-03 --- src/tabviews/tableshare/mutilform/index.jsx | 223 +++++++++++++++++++++++++++++++++++++++++++++++++------ 1 files changed, 198 insertions(+), 25 deletions(-) diff --git a/src/tabviews/tableshare/mutilform/index.jsx b/src/tabviews/tableshare/mutilform/index.jsx index ca13bc6..b56eea3 100644 --- a/src/tabviews/tableshare/mutilform/index.jsx +++ b/src/tabviews/tableshare/mutilform/index.jsx @@ -2,16 +2,20 @@ import PropTypes from 'prop-types' import { Form, Row, Col, Input, InputNumber, Select, DatePicker, notification } from 'antd' import moment from 'moment' +import { formRule } from '@/utils/option.js' import Utils from '@/utils/utils.js' +import FileUpload from '../fileupload' import './index.scss' const {MonthPicker} = DatePicker +const { TextArea } = Input class MainSearch extends Component { static propTpyes = { action: PropTypes.object, // 鎸夐挳淇℃伅銆佽〃鍗曞垪琛� dict: PropTypes.object, // 瀛楀吀椤� data: PropTypes.any, // 琛ㄦ牸鏁版嵁 + BData: PropTypes.any, // 涓昏〃鏁版嵁 configMap: PropTypes.object, // 鎸夐挳鍙婁笅鎷夎〃鍗曢厤缃俊鎭泦 inputSubmit: PropTypes.func // input鍥炶溅鎻愪氦 } @@ -23,7 +27,7 @@ } componentDidMount () { - const { data } = this.props + const { data, BData } = this.props let action = JSON.parse(JSON.stringify(this.props.action)) let datatype = {} @@ -56,8 +60,10 @@ }) } + let _inputfields = formlist.filter(item => item.type === 'text' || item.type === 'number') // 鐢ㄤ簬杩囨护涓嬫媺鑿滃崟鍏宠仈琛ㄥ崟 + formlist = formlist.map(item => { - if (item.type === 'select' || item.type === 'link') { + if (item.type === 'select' || item.type === 'link' || item.type === 'multiselect') { if (item.setAll === 'true') { item.options.unshift({ key: Utils.getuuid(), @@ -71,9 +77,16 @@ } item.oriOptions = JSON.parse(JSON.stringify(item.options)) + + if (item.linkSubField && item.linkSubField.length > 0) { + let _fields = _inputfields.map(_item => _item.field) + item.linkSubField = item.linkSubField.filter(_item => _fields.includes(_item)) + } } - if (!/^date/.test(item.type) && this.props.data && this.props.data.hasOwnProperty(item.field)) { + if (item.type === 'linkMain' && BData && BData.hasOwnProperty(item.field)) { + item.initval = BData[item.field] + } else if (!/^date/.test(item.type) && this.props.data && this.props.data.hasOwnProperty(item.field)) { item.initval = this.props.data[item.field] } @@ -107,7 +120,7 @@ duration: 10 }) } - + this.setState({ readtype: readtype, datatype: datatype, @@ -129,7 +142,7 @@ }) } - resetform = (formlist, supfields, index) => { + resetform = (formlist, supfields, index, fieldsvalue) => { index++ let subfields = [] @@ -138,7 +151,8 @@ 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 + + fieldsvalue[item.field] = item.initval subfields.push(item) } @@ -147,41 +161,58 @@ }) if (subfields.length === 0 || index > 6) { + this.props.form.setFieldsValue(fieldsvalue) return formlist } else { - return this.resetform(formlist, subfields, index) + return this.resetform(formlist, subfields, index, fieldsvalue) } } - selectChange = (_field, value) => { + selectChange = (_field, value, option) => { let formlist = JSON.parse(JSON.stringify(this.state.formlist)) let subfields = [] + let fieldsvalue = {} 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 + + fieldsvalue[item.field] = item.initval subfields.push(item) } return item }) + + // 琛ㄥ崟鍒囨崲鏃讹紝鏇存柊鍏宠仈瀛楁 + if (_field.type === 'select' && _field.linkSubField && _field.linkSubField.length > 0 && option.props.data) { + let _data = option.props.data + let fieldVal = {} + _field.linkSubField.forEach(subfield => { + fieldVal[subfield] = _data[subfield] + }) + this.props.form.setFieldsValue(fieldVal) + } if (subfields.length === 0) return - formlist = this.resetform(formlist, subfields, 0) + formlist = this.resetform(formlist, subfields, 0, fieldsvalue) + this.setState({ formlist: formlist - }, () => { - this.setState({ - formlist: formlist.map(item => { - item.hiden = false - return item - }) - }) }) } + + // handleInputNumber = (rule, value, callback, item) => { + // if (item.required === 'true' && (!value && value !== 0)) { + // callback(this.props.dict['form.required.input'] + item.label + '!') + // } else if ((item.min || item.min === 0) && (value || value === 0) && value < item.min) { + // callback(item.label + '鏈�灏忓�间负' + item.min + '!') + // } else if ((item.max || item.max === 0) && (value || value === 0) && value > item.max) { + // callback(item.label + '鏈�澶у�间负' + item.max + '!') + // } + // } getFields() { const { getFieldDecorator } = this.props.form @@ -196,8 +227,8 @@ } this.state.formlist.forEach((item, index) => { - if ((!item.field && item.type !== 'title') || item.hiden) return - + if ((!item.field && item.type !== 'title') || item.hidden === 'true') return + if (item.type === 'title') { fields.push( <Col span={24} key={index}> @@ -214,6 +245,10 @@ { required: item.required === 'true', message: this.props.dict['form.required.input'] + item.label + '!' + }, + { + max: formRule.input.max, + message: formRule.input.message } ] })(<Input placeholder="" autoComplete="off" disabled={item.readonly === 'true'} onPressEnter={this.handleSubmit} />)} @@ -225,7 +260,7 @@ let max = (item.max || item.max === 0) ? item.max : Infinity let _initval = item.initval let precision = (item.decimal || item.decimal === 0) ? item.decimal : null - + fields.push( <Col span={24 / cols} key={index}> <Form.Item label={item.label}> @@ -239,13 +274,18 @@ ] })( precision === null ? - <InputNumber initialValue={_initval} min={min} max={max} disabled={item.readonly === 'true'} onPressEnter={this.handleSubmit} /> : - <InputNumber initialValue={_initval} min={min} max={max} precision={precision} disabled={item.readonly === 'true'} onPressEnter={this.handleSubmit} /> + <InputNumber min={min} max={max} disabled={item.readonly === 'true'} onPressEnter={this.handleSubmit} /> : + <InputNumber min={min} max={max} precision={precision} disabled={item.readonly === 'true'} onPressEnter={this.handleSubmit} /> )} </Form.Item> </Col> ) } else if (item.type === 'select' || item.type === 'link') { // 涓嬫媺鎼滅储 + let hasSubField = false + if (item.linkSubField && item.linkSubField.length > 0) { // 瀛樺湪鍏宠仈瀛楁锛屾暟鎹瓨鍌� + hasSubField = true + } + fields.push( <Col span={24 / cols} key={index}> <Form.Item label={item.label}> @@ -261,11 +301,10 @@ <Select showSearch filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0} - onChange={(value) => {this.selectChange(item, value)}} - // getPopupContainer={() => document.getElementById('form-box')} + onChange={(value, option) => {this.selectChange(item, value, option)}} > {item.options.map(option => - <Select.Option id={option.key} title={option.Text} key={option.key} value={option.Value}>{option.Text}</Select.Option> + <Select.Option id={option.key} data={hasSubField ? option : ''} title={option.Text} key={option.key} value={option.Value}>{option.Text}</Select.Option> )} </Select> )} @@ -372,6 +411,93 @@ </Form.Item> </Col> ) + } else if (item.type === 'fileupload') { + let filelist = this.props.data ? this.props.data[item.field] : item.initval + if (filelist) { + try { + filelist = filelist.split(',').map((url, index) => { + return { + uid: `${index}`, + name: url.slice(url.lastIndexOf('/') + 1), + status: 'done', + url: url, + origin: true + } + }) + } catch { + filelist = [] + } + } + + fields.push( + <Col span={24 / cols} key={index}> + <Form.Item label={item.label}> + {getFieldDecorator(item.field, { + initialValue: filelist, + rules: [ + { + required: item.required === 'true', + message: this.props.dict['form.required.select'] + item.label + '!' + } + ] + })( + <FileUpload /> + )} + </Form.Item> + </Col> + ) + } else if (item.type === 'linkMain') { + fields.push( + <Col span={24 / cols} key={index}> + <Form.Item label={item.label}> + {getFieldDecorator(item.field, { + initialValue: item.initval, + rules: [ + { + required: item.required === 'true', + message: this.props.dict['form.required.input'] + item.label + '!' + } + ] + })(<Input placeholder="" autoComplete="off" disabled={item.readonly === 'true'} />)} + </Form.Item> + </Col> + ) + } else if (item.type === 'funcvar') { + // fields.push( + // <Col span={24 / cols} key={index}> + // <Form.Item label={item.label}> + // {getFieldDecorator(item.field, { + // initialValue: item.linkfield || '', + // })(<Input placeholder="" autoComplete="off" disabled={item.readonly === 'true'} />)} + // </Form.Item> + // </Col> + // ) + } else if (item.type === 'textarea') { + let _labelcol = cols !== 3 ? 8 / cols : 3 + let _wrapcol = cols !== 3 ? 16 + (cols - 1) * 4 : 21 + let _style = {} + if (cols === 2) { + _style.paddingLeft = '7px' + } + fields.push( + <Col span={24} key={index} className="textarea-row" style={{..._style}}> + <Form.Item label={item.label} labelCol={{xs: { span: 24 }, sm: { span: _labelcol }}} wrapperCol={ {xs: { span: 24 }, sm: { span: _wrapcol }} }> + {getFieldDecorator(item.field, { + initialValue: item.initval || '', + rules: [ + { + required: item.required === 'true', + message: this.props.dict['form.required.input'] + item.label + '!' + }, + { + max: formRule.textarea.max, + message: formRule.textarea.message + } + ] + })(<TextArea autosize={{ minRows: 2, maxRows: 6 }} disabled={item.readonly === 'true'} />)} + </Form.Item> + </Col> + ) } }) @@ -384,6 +510,27 @@ this.props.form.validateFieldsAndScroll((err, values) => { if (!err) { let search = [] + // 闅愯棌琛ㄥ崟 + this.state.formlist.forEach(item => { + if (!item.field) return + + if (item.type === 'funcvar') { + search.push({ + type: 'funcvar', + readonly: 'true', + key: item.field, + value: '' + }) + } else if (item.hidden === 'true') { + search.push({ + type: this.state.datatype[item.field], + readonly: this.state.readtype[item.field], + key: item.field, + value: item.initval + }) + } + }) + Object.keys(values).forEach(key => { if (this.state.datatype[key] === 'datetime') { let _value = '' @@ -432,6 +579,32 @@ key: key, value: values[key] ? values[key].join(',') : '' }) + } else if (this.state.datatype[key] === 'fileupload') { + let vals = [] + + if (values[key] && values[key].length > 0) { + values[key].forEach(_val => { + if (_val.origin && _val.url) { + vals.push(_val.url) + } else if (!_val.origin && _val.status === 'done' && _val.response) { + vals.push(Utils.getrealurl(_val.response)) + } + }) + } + + search.push({ + type: this.state.datatype[key], + readonly: this.state.readtype[key], + key: key, + value: vals.join(',') + }) + } else if (this.state.datatype[key] === 'funcvar') { + search.push({ + type: this.state.datatype[key], + readonly: this.state.readtype[key], + key: key, + value: values[key] + }) } else { search.push({ type: this.state.datatype[key], -- Gitblit v1.8.0