king
2024-07-02 c0e1a2f76bb28ab71e54d30ac2dda945fa1e4a7e
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 = [{
@@ -155,7 +165,7 @@
      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 +173,7 @@
    this.record = record
    this.setState({ formlist })
    this.setState({ formlist, formId })
  }
  checkNumber = (rule, value, callback, item) => {
@@ -243,30 +253,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
          })
        })
      })
      }
    }
  }
@@ -280,7 +287,14 @@
      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} />)
@@ -382,7 +396,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>
    )