From 21167ece56edd628e6f6546d1d642947cc3a048f Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期一, 12 八月 2024 22:17:33 +0800 Subject: [PATCH] 2024-08-12 --- src/components/normalform/modalform/index.jsx | 82 ++++++++++++++++++++++++++++++---------- 1 files changed, 61 insertions(+), 21 deletions(-) diff --git a/src/components/normalform/modalform/index.jsx b/src/components/normalform/modalform/index.jsx index 8a7599f..544716e 100644 --- a/src/components/normalform/modalform/index.jsx +++ b/src/components/normalform/modalform/index.jsx @@ -7,7 +7,6 @@ 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' @@ -33,6 +32,7 @@ state = { formlist: [], // 琛ㄥ崟椤� + formId: '' } record = {} @@ -41,6 +41,15 @@ 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) { // 澶氬眰琛ㄥ崟鎺у埗 @@ -57,6 +66,7 @@ if (item.options) { item.oriOptions = fromJS(item.options).toJS() } + item.$formId = formId if (item.type === 'text') { let _rules = [{ @@ -122,6 +132,9 @@ let cell = fieldMap.get(item.field) + cell.$ctrls = cell.$ctrls || [] + cell.$ctrls.push(key) + if (cell.hidden) return if (cell.skip && supItem.forbid) { // 涓婄骇琛ㄥ崟绂佺敤鏃讹紝姝よ〃鍗曚笉鍙楁帶鍒� @@ -152,10 +165,14 @@ formlist = formlist.map(cell => { let item = fieldMap.get(cell.field) + if (item.$ctrls && item.$ctrls.length === 1) { + delete item.$ctrls + } + 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 @@ -163,7 +180,7 @@ this.record = record - this.setState({ formlist }) + this.setState({ formlist, formId }) } checkNumber = (rule, value, callback, item) => { @@ -220,6 +237,32 @@ m.hidden = !cell.values.includes(val) } + if (!m.hidden && m.$ctrls) { + m.$ctrls.forEach(n => { + if (n === current.field || m.hidden) return + + let oth = map.get(n) + let _val = this.record[n] + + if (_val && JSON.stringify(_val) === '[]') { + _val = '' + } + + let p = oth.controlFields.filter(q => q.field === m.field)[0] + + if (oth.hidden || (p.notNull && !_val)) { + m.hidden = true + } else if (oth.type === 'checkbox' || oth.type === 'multiselect') { + let _vals = [...(_val || []), ...p.values] + if (_vals.length === new Set(_vals).size) { + m.hidden = true + } + } else if (!p.values.includes(_val)) { + m.hidden = true + } + }) + } + if (m.hidden) { m.initval = this.record[m.field] } @@ -243,30 +286,27 @@ 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 + }) }) - }) + } } } @@ -389,7 +429,7 @@ } return ( - <Form {...formItemLayout} className="normal-form-field"> + <Form {...formItemLayout} className="normal-form-field" id={this.state.formId}> <Row gutter={24}>{this.getFields()}</Row> </Form> ) -- Gitblit v1.8.0