| | |
| | | state = { |
| | | datatype: null, |
| | | readtype: null, |
| | | formlist: [] |
| | | groups: null, |
| | | formlist: [], |
| | | record: {} |
| | | } |
| | | |
| | | componentDidMount () { |
| | |
| | | }) |
| | | } |
| | | |
| | | resetform = (formlist, supfields, index, fieldsvalue) => { |
| | | resetform = (groups, supfields, index, fieldsvalue) => { |
| | | index++ |
| | | let subfields = [] |
| | | |
| | | supfields.forEach(supfield => { |
| | | formlist = formlist.map(item => { |
| | | 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 : '' |
| | | groups = groups.map(group => { |
| | | group.sublist = group.sublist.map(item => { |
| | | 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 : '' |
| | | |
| | | fieldsvalue[item.field] = item.initval |
| | | |
| | | subfields.push(item) |
| | | } |
| | | return item |
| | | }) |
| | | return group |
| | | }) |
| | | }) |
| | | |
| | | if (subfields.length === 0 || index > 6) { |
| | | return {groups: groups, fieldsvalue: fieldsvalue} |
| | | } else { |
| | | return this.resetform(groups, subfields, index, fieldsvalue) |
| | | } |
| | | } |
| | | |
| | | selectChange = (_field, value, option) => { |
| | | const { record } = this.state |
| | | let groups = JSON.parse(JSON.stringify(this.state.groups)) |
| | | |
| | | let subfields = [] |
| | | let fieldsvalue = {} |
| | | let _record = {} |
| | | groups = groups.map(group => { |
| | | group.sublist = group.sublist.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 : '' |
| | | |
| | | fieldsvalue[item.field] = item.initval |
| | | |
| | | subfields.push(item) |
| | | } |
| | | return item |
| | | }) |
| | | }) |
| | | |
| | | if (subfields.length === 0 || index > 6) { |
| | | this.props.form.setFieldsValue(fieldsvalue) |
| | | return formlist |
| | | } else { |
| | | return this.resetform(formlist, subfields, index, fieldsvalue) |
| | | } |
| | | } |
| | | |
| | | 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 : '' |
| | | |
| | | fieldsvalue[item.field] = item.initval |
| | | |
| | | subfields.push(item) |
| | | } |
| | | return item |
| | | return group |
| | | }) |
| | | |
| | | // 表单切换时,更新关联字段 |
| | | 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] |
| | | if (this.props.form.getFieldValue(subfield) !== undefined) { |
| | | fieldsvalue[subfield] = _data[subfield] |
| | | } else { |
| | | _record[subfield] = _data[subfield] |
| | | } |
| | | }) |
| | | this.props.form.setFieldsValue(fieldVal) |
| | | } |
| | | |
| | | if (subfields.length === 0) return |
| | | if (subfields.length === 0) { |
| | | if (Object.keys(fieldsvalue).length > 0) { |
| | | this.props.form.setFieldsValue(fieldsvalue) |
| | | } |
| | | if (Object.keys(_record).length > 0) { |
| | | this.setState({ |
| | | record: {...record, ..._record} |
| | | }) |
| | | } |
| | | } else { |
| | | let result = this.resetform(groups, subfields, 0, fieldsvalue) |
| | | |
| | | formlist = this.resetform(formlist, subfields, 0, fieldsvalue) |
| | | if (Object.keys(result.fieldsvalue).length > 0) { |
| | | this.props.form.setFieldsValue(fieldsvalue) |
| | | } |
| | | |
| | | this.setState({ |
| | | formlist: formlist |
| | | }) |
| | | let _param = { |
| | | groups: result.groups |
| | | } |
| | | |
| | | if (Object.keys(_record).length > 0) { |
| | | _param.record = {...record, ..._record} |
| | | } |
| | | |
| | | this.setState(_param) |
| | | } |
| | | } |
| | | |
| | | getFields(formlist) { |
| | |
| | | } |
| | | |
| | | handleConfirm = () => { |
| | | const { record } = this.state |
| | | // 表单提交时检查输入值是否正确 |
| | | return new Promise((resolve, reject) => { |
| | | this.props.form.validateFieldsAndScroll((err, values) => { |
| | |
| | | value: '' |
| | | }) |
| | | } else if (item.hidden === 'true') { |
| | | let _val = item.initval |
| | | if (record.hasOwnProperty(item.field)) { |
| | | _val = record[item.field] |
| | | } |
| | | search.push({ |
| | | type: this.state.datatype[item.field], |
| | | readonly: this.state.readtype[item.field], |
| | | key: item.field, |
| | | value: item.initval |
| | | value: _val |
| | | }) |
| | | } |
| | | }) |
| | |
| | | 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 { |
| | | } else if (this.state.datatype[key] === 'text') { |
| | | search.push({ |
| | | type: this.state.datatype[key], |
| | | readonly: this.state.readtype[key], |
| | |
| | | value: values[key].replace(/(^\s*|\s*$)/ig, '') |
| | | // value: values[key].replace(/[\x00-\xff]+/ig, '') |
| | | }) |
| | | } else { |
| | | search.push({ |
| | | type: this.state.datatype[key], |
| | | readonly: this.state.readtype[key], |
| | | key: key, |
| | | value: values[key] |
| | | }) |
| | | } |
| | | }) |
| | | resolve(search) |