| | |
| | | action: PropTypes.object, // 按钮信息、表单列表 |
| | | dict: PropTypes.object, // 字典项 |
| | | data: PropTypes.any, // 表格数据 |
| | | BData: PropTypes.any, // 主表数据 |
| | | configMap: PropTypes.object, // 按钮及下拉表单配置信息集 |
| | | inputSubmit: PropTypes.func // input回车提交 |
| | | } |
| | |
| | | } |
| | | |
| | | componentDidMount () { |
| | | const { data } = this.props |
| | | const { data, BData } = this.props |
| | | let action = JSON.parse(JSON.stringify(this.props.action)) |
| | | |
| | | let datatype = {} |
| | |
| | | } |
| | | } |
| | | |
| | | 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] |
| | | } |
| | | |
| | |
| | | duration: 10 |
| | | }) |
| | | } |
| | | |
| | | |
| | | this.setState({ |
| | | readtype: readtype, |
| | | datatype: datatype, |
| | |
| | | }) |
| | | } |
| | | |
| | | resetform = (formlist, supfields, index) => { |
| | | resetform = (formlist, supfields, index, fieldsvalue) => { |
| | | index++ |
| | | let subfields = [] |
| | | |
| | |
| | | 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) |
| | | } |
| | |
| | | }) |
| | | |
| | | 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) |
| | | } |
| | | } |
| | | |
| | |
| | | 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) |
| | | } |
| | |
| | | |
| | | 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() |
| | | } 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 + '!') |
| | | } |
| | | } |
| | | // 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 |
| | |
| | | } |
| | | |
| | | 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}> |
| | |
| | | let max = (item.max || item.max === 0) ? item.max : Infinity |
| | | let _initval = item.initval |
| | | let precision = (item.decimal || item.decimal === 0) ? item.decimal : null |
| | | let rules = [] |
| | | if ((item.min || item.min === 0) || (item.max || item.max === 0)) { |
| | | rules.push({ |
| | | validator: (rule, value, callback) => {this.handleInputNumber(rule, value, callback, item)} |
| | | }) |
| | | } |
| | | |
| | | |
| | | fields.push( |
| | | <Col span={24 / cols} key={index}> |
| | | <Form.Item label={item.label}> |
| | |
| | | { |
| | | required: item.required === 'true', |
| | | message: this.props.dict['form.required.input'] + item.label + '!' |
| | | }, |
| | | ...rules |
| | | } |
| | | ] |
| | | })( |
| | | 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> |
| | |
| | | if (item.linkSubField && item.linkSubField.length > 0) { // 存在关联字段,数据存储 |
| | | hasSubField = true |
| | | } |
| | | |
| | | |
| | | fields.push( |
| | | <Col span={24 / cols} key={index}> |
| | | <Form.Item label={item.label}> |
| | |
| | | </Form.Item> |
| | | </Col> |
| | | ) |
| | | } else if (item.type === 'funcvar') { |
| | | } else if (item.type === 'linkMain') { |
| | | fields.push( |
| | | <Col span={24 / cols} key={index}> |
| | | <Form.Item label={item.label}> |
| | | {getFieldDecorator(item.field, { |
| | | initialValue: item.linkfield || '', |
| | | 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 |
| | |
| | | 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 = '' |
| | |
| | | }) |
| | | } else if (this.state.datatype[key] === 'fileupload') { |
| | | let vals = [] |
| | | |
| | | if (values[key].length > 0) { |
| | | |
| | | if (values[key] && values[key].length > 0) { |
| | | values[key].forEach(_val => { |
| | | if (_val.origin && _val.url) { |
| | | vals.push(_val.url) |