king
2020-12-01 b3852c89968e9d5d6a3b9a4998d869bfbbfd1842
src/tabviews/zshare/mutilform/index.jsx
@@ -66,6 +66,7 @@
    let formlist = []
    let encrypts = []
    let intercepts = []
    let _inputfields = []
    if (action.groups.length > 0) {
      action.groups.forEach(group => {
@@ -85,29 +86,32 @@
      formlist = action.fields
    }
    let _inputfields = formlist.filter(item => (item.type === 'text' || item.type === 'number') && item.field) // 用于过滤下拉菜单关联表单
    let linkFields = {} // 关联菜单
    let supItemVal = {} // 上级菜单初始值
    let deForms = []    // 需要动态获取下拉菜单的表单
    formlist.forEach(item => {
      if (item.type === 'text' || item.type === 'number') {                // 用于过滤下拉菜单关联表单
        _inputfields.push(item.field)
      } else if (item.type === 'textarea' && item.encryption === 'true') { // 加密字段
        encrypts.push(item.field)
      } else if (item.type === 'link') {
        linkFields[item.linkField] = linkFields[item.linkField] || []
        linkFields[item.linkField].push(item.field)
      }
      if (item.interception === 'true') {                                  // 字符截取字段
        intercepts.push(item.field)
      }
    })
    formlist = formlist.map(item => {
      if (item.type === 'title') return item
      // 加密字段
      if (item.type === 'textarea' && item.encryption === 'true') {
        encrypts.push(item.field)
      }
      // 字符截取字段
      if (item.interception === 'true') {
        intercepts.push(item.field)
      }
      // 数据自动填充
      let _readin = item.readin !== 'false'
      if (item.type === 'linkMain' || item.type === 'funcvar') {
        _readin = false
      }
      // 用于受控值的表单,隐藏时传默认值(未使用?)
      item.initVal = typeof(item.initval) === 'object' ? fromJS(item.initval).toJS() : item.initval
      let _fieldlen = item.fieldlength || 50
      if (item.type === 'textarea' || item.type === 'fileupload' || item.type === 'multiselect') {
@@ -122,8 +126,7 @@
      writein[item.field] = item.writein !== 'false'
      fieldlen[item.field] = _fieldlen
      if (item.type === 'select' || item.type === 'link' || item.type === 'multiselect' || item.type === 'radio' || item.type === 'checkbox') {
        if (item.setAll === 'true' && (item.type === 'select' || item.type === 'link' || item.type === 'radio')) {
      if (item.setAll === 'true' && (item.type === 'select' || item.type === 'link' || item.type === 'radio')) { // 添加空值
          item.options.unshift({
            key: Utils.getuuid(),
            Value: '',
@@ -131,20 +134,14 @@
          })
        }
        // 保存初始列表,用于联动菜单控制
        item.oriOptions = fromJS(item.options).toJS()
      item.oriOptions = item.options ? fromJS(item.options).toJS() : null // 保存初始列表,用于联动菜单控制
        // 下级表单控制-字段写入
        if (item.type === 'select' || item.type === 'radio') {
          if (item.linkSubField && item.linkSubField.length > 0) {
      if ((item.type === 'select' || item.type === 'radio') && item.linkSubField && item.linkSubField.length > 0) {
            item.linkSubField = item.linkSubField.filter(_item => _inputfields.includes(_item))
          }
          if (item.linkSubField && item.linkSubField.length === 0) {
            item.linkSubField = null
          }
        } else {
          item.linkSubField = null
        }
      }
      let newval = ''
@@ -226,31 +223,30 @@
        item.supvalue = supvals
      }
      if (linkFields[item.field]) {
        item.linkFields = linkFields[item.field]
      }
      supItemVal[item.field] = item.initval
      if (['select', 'link', 'multiselect', 'radio', 'checkbox', 'checkcard'].includes(item.type) && item.resourceType === '1') {
        deForms.push(item)
      }
      return item
    })
    formlist = formlist.map(item => {
      if (item.type === 'link') {
        let supItem = formlist.filter(form => form.field === item.linkField)[0]
        // 关联显示列中的字段值,通过该值过滤下拉选项
        if (!supItem && data && data.hasOwnProperty(item.linkField)) {
          supItem = {initval: data[item.linkField]}
        }
        if (!supItem) {
          notification.warning({
            top: 92,
            message: '未查询到表单《' + item.label + '》关联字段!',
            duration: 5
          })
          item.supInitVal = ''
        } else {
          item.supInitVal = supItem.initval
          item.options = item.oriOptions.filter(option => option.ParentID === supItem.initval)
        }
        if (supItemVal[item.linkField]) {
          item.supInitVal = supItemVal[item.linkField]
        } else if (data && data.hasOwnProperty(item.linkField)) {
          item.supInitVal = data[item.linkField]
      }
        item.options = item.oriOptions.filter(option => option.ParentID === item.supInitVal)
      }
      return item
    })
@@ -281,19 +277,16 @@
      this.setState({
        loaded: true
      })
      this.improveActionForm()
      this.improveActionForm(deForms)
    })
  }
  /**
   * @description 获取下拉表单选项信息
   */
  improveActionForm = () => {
  improveActionForm = (deForms) => {
    const { BID, menuType } = this.props
    const { formlist } = this.state
    // 需要动态获取下拉菜单的表单
    let deForms = formlist.filter(item => ['select', 'link', 'multiselect', 'radio', 'checkbox', 'checkcard'].includes(item.type) && item.resourceType === '1' && (item.type === 'link' || item.hidden !== 'true'))
    if (deForms.length === 0) {
      return
@@ -445,11 +438,7 @@
      this.setState({
        formlist: _formlist.map(item => {
          if (item.type === 'link') {
            if (item.supInitVal) {
              item.options = item.oriOptions.filter(option => option.ParentID === item.supInitVal)
            } else {
              item.options = item.oriOptions
            }
          } else if (['select', 'multiselect', 'radio', 'checkbox', 'checkcard'].includes(item.type)) {
            item.options = item.oriOptions
          }
@@ -542,11 +531,7 @@
      this.setState({
        formlist: _formlist.map(item => {
          if (item.type === 'link') {
            if (item.supInitVal) {
              item.options = item.oriOptions.filter(option => option.ParentID === item.supInitVal)
            } else {
              item.options = item.oriOptions
            }
          } else if (['select', 'multiselect', 'radio', 'checkbox', 'checkcard'].includes(item.type)) {
            item.options = item.oriOptions
          }
@@ -1291,7 +1276,6 @@
              return item
            })
          }
          resolve(search)
        } else {
          reject(err)