| | |
| | | import asyncComponent from '@/utils/asyncComponent' |
| | | import MKEInput from './mkInput' |
| | | import MKNumberInput from './mkNumberInput' |
| | | import MKEmitter from '@/utils/events.js' |
| | | import MKSelect from './mkSelect' |
| | | import './index.scss' |
| | | |
| | |
| | | |
| | | state = { |
| | | formlist: [], // 表单项 |
| | | formId: '' |
| | | } |
| | | |
| | | record = {} |
| | |
| | | let record = {} |
| | | let controlFields = {} |
| | | let fieldMap = new Map() |
| | | let formId = (() => { |
| | | let uuid = [] |
| | | let _options = '0123456789abcdefghigklmnopqrstuv' |
| | | for (let i = 0; i < 19; i++) { |
| | | uuid.push(_options.substr(Math.floor(Math.random() * 0x20), 1)) |
| | | } |
| | | uuid = uuid.join('') |
| | | return uuid |
| | | })() |
| | | |
| | | let formlist = this.props.formlist.filter(item => { |
| | | if (item.controlFields) { // 多层表单控制 |
| | |
| | | if (item.options) { |
| | | item.oriOptions = fromJS(item.options).toJS() |
| | | } |
| | | item.$formId = formId |
| | | |
| | | if (item.type === 'text') { |
| | | let _rules = [{ |
| | |
| | | if (item.linkField) { |
| | | let supInitVal = fieldMap.get(item.linkField).initval || '' |
| | | |
| | | item.options = item.oriOptions.filter(option => option.ParentID === supInitVal) |
| | | item.options = item.oriOptions.filter(option => option.ParentID === supInitVal || option.ParentID === '') |
| | | } |
| | | |
| | | return item |
| | |
| | | |
| | | this.record = record |
| | | |
| | | this.setState({ formlist }) |
| | | this.setState({ formlist, formId }) |
| | | } |
| | | |
| | | checkNumber = (rule, value, callback, item) => { |
| | |
| | | if (item && item.linkField) { |
| | | let supInitVal = this.record[item.linkField] || '' |
| | | |
| | | item.options = item.oriOptions.filter(option => option.ParentID === supInitVal) |
| | | item.options = item.oriOptions.filter(option => option.ParentID === supInitVal || option.ParentID === '') |
| | | } |
| | | |
| | | return item || cell |
| | | }) |
| | | }) |
| | | } else if (item.reset_source) { |
| | | let map = new Map() |
| | | this.state.formlist.forEach(cell => { |
| | | if (!cell.field) return |
| | | map.set(cell.field, cell) |
| | | }) |
| | | |
| | | item.callback(map, this.record, MKEmitter) |
| | | |
| | | this.setState({ |
| | | formlist: this.state.formlist.map(cell => { |
| | | if (!cell.field) return cell |
| | | |
| | | let item = map.get(cell.field) |
| | | |
| | | return item || cell |
| | | let reOptions = item.callback(this.record) |
| | | |
| | | if (reOptions) { |
| | | this.setState({ |
| | | formlist: this.state.formlist.map(cell => { |
| | | if (!cell.field || !reOptions[cell.field]) return cell |
| | | |
| | | cell.options = reOptions[cell.field] |
| | | cell.timestamp = new Date().getTime() |
| | | |
| | | return cell |
| | | }) |
| | | }) |
| | | }) |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | if (item.hidden || item.forbid) return |
| | | |
| | | let content = null |
| | | let label = item.tooltip ? <Tooltip placement="topLeft" title={item.tooltip}><QuestionCircleOutlined className="mk-form-tip" />{item.label}</Tooltip> : item.label |
| | | let label = item.label |
| | | if (item.tooltip) { |
| | | if (item.toolWidth) { |
| | | label = <Tooltip placement="topLeft" overlayStyle={{maxWidth: item.toolWidth}} title={<div onClick={(e) => e.stopPropagation()}>{item.tooltip}</div>}><QuestionCircleOutlined className="mk-form-tip" />{item.label}</Tooltip> |
| | | } else { |
| | | label = <Tooltip placement="topLeft" title={<div onClick={(e) => e.stopPropagation()}>{item.tooltip}</div>}><QuestionCircleOutlined className="mk-form-tip" />{item.label}</Tooltip> |
| | | } |
| | | } |
| | | |
| | | if (item.type === 'text') { |
| | | content = (<MKEInput config={item} onChange={(val, defer) => !defer && this.recordChange({[item.field]: val}, item)} onSubmit={this.props.inputSubmit} />) |
| | |
| | | } |
| | | |
| | | return ( |
| | | <Form {...formItemLayout} className="normal-form-field"> |
| | | <Form {...formItemLayout} className="normal-form-field" id={this.state.formId}> |
| | | <Row gutter={24}>{this.getFields()}</Row> |
| | | </Form> |
| | | ) |