king
2023-05-09 7b0dbecd1d6155d26ec67be0a47a16264c738c85
src/tabviews/zshare/mutilform/index.jsx
@@ -19,6 +19,7 @@
const MKCheckCard = asyncComponent(() => import('./mkCheckCard'))
const MKSwitch = asyncComponent(() => import('./mkSwitch'))
const MKCheck = asyncComponent(() => import('./mkCheck'))
const MKCheckbox = asyncComponent(() => import('./mkCheckbox'))
const MKRadio = asyncComponent(() => import('./mkRadio'))
const MKDatePicker = asyncComponent(() => import('./mkDatePicker'))
@@ -27,6 +28,7 @@
const MKColor = asyncComponent(() => import('./mkColor'))
const MkFormula = asyncComponent(() => import('./mkFormula'))
const MkCascader = asyncComponent(() => import('./mkCascader'))
const MkVercode = asyncComponent(() => import('./mkVercode'))
const MKEditor = asyncComponent(() => import('@/components/editor'))
class MainSearch extends Component {
@@ -35,17 +37,22 @@
    data: PropTypes.any,         // 表格数据
    BID: PropTypes.any,          // 主表ID
    BData: PropTypes.any,        // 主表数据
    unload: PropTypes.any,       // 下拉菜单不加载数据
    inputSubmit: PropTypes.func  // input回车提交
  }
  state = {
    formlist: [],    // 表单项
    ID: '',
    send_type: '',
    timestamp: '',
    n_id: ''
  }
  record = {}
  componentDidMount () {
    const { action } = this.props
    const { action, unload } = this.props
    let data = {}
    let BData = {}
@@ -98,6 +105,12 @@
        delete item.style.marginRight
      }
      if (item.type === 'split' && item.splitctrl) {
        if (data.hasOwnProperty(item.splitctrl.toLowerCase()) && data[item.splitctrl.toLowerCase()] === '') {
          return false
        }
      }
      if (item.type === 'split' || item.type === 'formula') return true
      if (item.type === 'hint') {
        if (item.field && data[item.field.toLowerCase()]) {
@@ -105,18 +118,20 @@
        }
        delete item.field
        return true
      } else if (item.type === 'date') { // 时间搜索
      } else if (item.type === 'date') {
        item.precision = item.precision || 'day'
      } else if (item.type === 'datetime') {
        item.type = 'date'
        item.precision = 'second'
      }
      if (!item.field || !['text', 'number', 'switch', 'rate', 'select', 'link', 'cascader', 'linkMain', 'funcvar', 'date', 'datemonth', 'radio', 'checkbox', 'checkcard', 'fileupload', 'textarea', 'multiselect', 'brafteditor', 'color'].includes(item.type)) return false
      if (!item.field || !['text', 'number', 'switch', 'check', 'rate', 'select', 'link', 'cascader', 'linkMain', 'funcvar', 'date', 'datemonth', 'radio', 'checkbox', 'checkcard', 'fileupload', 'textarea', 'multiselect', 'brafteditor', 'color', 'vercode'].includes(item.type)) return false
      if (/^\s+$/.test(item.label)) {
        item.style = item.style || {}
        item.style.color = 'transparent'
        item.style.opacity = 0
        item.style.width = 1
        item.style.display = 'inline-block'
      }
      // 数据自动填充
@@ -159,6 +174,23 @@
          })
        }
        item.oriOptions = fromJS(item.options).toJS()
        if (item.empty === 'hidden' && item.oriOptions.length === 0) {
          item.hidden = true
        }
        if (item.type === 'checkcard' && item.readonly && item.unchecked === 'hidden') {
          let selectKeys = item.initval
          if (item.multiple === 'true') {
            selectKeys = selectKeys ? selectKeys.split(',') : []
            item.options = item.options.filter(item => selectKeys.includes(item.$value))
          } else {
            item.options = item.options.filter(item => selectKeys === item.$value)
          }
          item.oriOptions = fromJS(item.options).toJS()
          if (item.options.length === 0) {
            item.hidden = true
          }
        }
      }
      let newval = '$empty'
@@ -189,7 +221,7 @@
        if (newval === '$empty' && item.initval) {
          newval = moment().subtract(item.initval, 'month').format('YYYY-MM')
        }
      } else if (item.type === 'switch') { // 开关只接收固定值
      } else if (item.type === 'switch' || item.type === 'check') { // 开关勾选框只接收固定值
        if (newval !== '$empty' && (newval === item.closeVal || newval === item.openVal)) {
        } else if (item.initval === true) {
@@ -300,7 +332,7 @@
            })
          } else if (item.regular === 'email') {
            _rules.push({
              pattern: /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/,
              pattern: /^([a-zA-Z0-9._-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/,
              message: item.regularText || '请正确输入邮箱地址'
            })
          }
@@ -349,7 +381,7 @@
            message: formRule.input.formMessage.replace('@max', item.fieldlength)
          }
        ]
      } else if (item.type === 'linkMain') {
      } else if (item.type === 'linkMain' || item.type === 'vercode') {
        item.rules = [
          {
            required: item.required === 'true',
@@ -381,10 +413,13 @@
        let cell = fieldMap.get(item.field)
        if (cell.hidden) return
        // if (cell.hidden) return
        if (supItem.hidden || !item.values.includes(supItem.initval)) {
          cell.hidden = true
          if (cell.empty === 'hidden') {
            cell.$hidden = true
          }
          fieldMap.set(item.field, cell)
        }
@@ -447,17 +482,19 @@
        item.options = item.oriOptions.filter(option => option.ParentID === item.supInitVal || option.value === '')
      }
      if (['select', 'link', 'radio'].includes(item.type) && item.resourceType === '0') { // 选中第一项
        if (typeof(item.initval) === 'string' && item.initval.indexOf('$first') > -1) {
          item.initval = item.options[0] ? item.options[0].value : ''
      if (['select', 'link', 'radio'].includes(item.type)) { // 选中第一项
        if (/^\s*\$first\s*$/.test(item.initval)) {
          item.$first = true
          item.initval = ''
        }
        if (item.resourceType === '0') { // 选中第一项
          if (item.$first) {
            item.initval = item.options[0] ? item.options[0].value : ''
          }
        }
      }
      if (typeof(item.initval) === 'string' && item.initval.indexOf('$first') > -1) {
        record[item.field] = ''
      } else {
        record[item.field] = item.initval
      }
      record[item.field] = item.initval
      if (linkFields[item.field]) {
        item.linkFields = linkFields[item.field]
@@ -505,7 +542,9 @@
    this.record = record
    this.setState({ formlist }, () => {
    this.setState({ formlist, ID: this.props.data ? this.props.data.$$uuid || '' : '' }, () => {
      if (unload) return
      if (action.setting && action.setting.focus && fieldMap.has(action.setting.focus)) {
        setTimeout(() => {
          MKEmitter.emit('mkFC', 'focus', fieldMap.get(action.setting.focus).uuid)
@@ -534,13 +573,17 @@
    let cache = action.setting.cache !== 'false'
    let debug = window.GLOB.debugger === true || (window.debugger === true && options.sysType !== 'cloud')
    let _sql = `Declare @mk_organization nvarchar(512)  select @mk_organization='${sessionStorage.getItem('organization') || ''}'\n`
    let _sql = `Declare @mk_departmentcode nvarchar(512),@mk_organization nvarchar(512),@mk_user_type nvarchar(20)  select @mk_departmentcode='${sessionStorage.getItem('departmentcode') || ''}',@mk_organization='${sessionStorage.getItem('organization') || ''}',@mk_user_type='${sessionStorage.getItem('mk_user_type') || ''}'\n`
    let _sso = _sql
    deForms.forEach(item => {
      if (item.database === 'sso') {
        let sql = _sso + item.base_sql
        _sso = ''
        sql = sql.replace(/@ID@/ig, `'${this.state.ID || ''}'`)
        sql = sql.replace(/@BID@/ig, `'${BID}'`)
        if (debug) {
          console.info(sql)
        }
@@ -548,6 +591,10 @@
      } else {
        let sql = _sql + item.base_sql
        _sql = ''
        sql = sql.replace(/@ID@/ig, `'${this.state.ID || ''}'`)
        sql = sql.replace(/@BID@/ig, `'${BID}'`)
        if (debug) {
          console.info(sql)
        }
@@ -561,8 +608,7 @@
      LText: localItems.join(' union all '),
      obj_name: '',
      arr_field: '',
      table_type: 'Y',
      BID: BID || ''
      table_type: 'Y'
    }
    if (param.LText) {
@@ -596,8 +642,7 @@
      LText: mainItems.join(' union all '),
      obj_name: '',
      arr_field: '',
      table_type: 'Y',
      BID: BID || ''
      table_type: 'Y'
    }
    if (mainparam.LText) {
@@ -650,16 +695,18 @@
  improveSimpleActionForm = (deForms) => {
    let cache = this.props.action.setting.cache !== 'false'
    let debug = window.GLOB.debugger === true || (window.debugger === true && options.sysType !== 'cloud')
    let _sql = `Declare @mk_organization nvarchar(512)  select @mk_organization='${sessionStorage.getItem('organization') || ''}'\n`
    let _sql = `Declare @mk_departmentcode nvarchar(512),@mk_organization nvarchar(512),@mk_user_type nvarchar(20)  select @mk_departmentcode='${sessionStorage.getItem('departmentcode') || ''}',@mk_organization='${sessionStorage.getItem('organization') || ''}',@mk_user_type='${sessionStorage.getItem('mk_user_type') || ''}'\n`
    let deffers = deForms.map((form, index) => {
      let param = {
        func: 'sPC_Get_SelectedList',
        LText: _sql + form.base_sql,
        obj_name: form.field,
        arr_field: form.arr_field,
        BID: this.props.BID || ''
        arr_field: form.arr_field
      }
      param.LText = param.LText.replace(/@ID@/ig, `'${this.state.ID || ''}'`)
      param.LText = param.LText.replace(/@BID@/ig, `'${this.props.BID || ''}'`)
      if (debug) {
        console.info(param.LText)
@@ -712,6 +759,7 @@
      if (['select', 'link', 'radio', 'checkbox', 'checkcard', 'multiselect', 'cascader'].includes(item.type) && result[item.field] && result[item.field].length > 0) {
        let options = []
        let map = new Map()
        let all = false
        result[item.field].forEach(cell => {
          let _cell = { key: Utils.getuuid() , ParentID: ''}
@@ -722,12 +770,26 @@
          if (item.type !== 'checkcard') {
            _cell.value = cell[item.valueField]
            _cell.label = cell[item.valueText] + ''
            if (!_cell.label || map.has(_cell.ParentID + _cell.value)) return
            if (map.has(_cell.ParentID + _cell.value)) return
            if (!_cell.label) {
              if (!all) {
                _cell.label = '全部'
                all = true
              } else {
                return
              }
            }
            
            map.set(_cell.ParentID + _cell.value, 0)
          } else {
            _cell.$value = cell[item.cardValField]
            _cell = {..._cell, ...cell}
            if (item.urlField) {
              _cell.$url = cell[item.urlField] || ''
            } else if (item.colorField) {
              _cell.$color = cell[item.colorField] || ''
            }
            if (map.has(_cell.ParentID + _cell.$value)) return
            
@@ -757,7 +819,7 @@
          item.options = item.oriOptions
        }
        if (['select', 'link', 'radio'].includes(item.type) && typeof(item.initval) === 'string' && item.initval.indexOf('$first') > -1) { // 选中第一项
        if (['select', 'link', 'radio'].includes(item.type) && item.$first) { // 选中第一项
          item.initval = item.options[0] ? item.options[0].value : ''
          this.record[item.field] = item.initval
        }
@@ -775,6 +837,25 @@
            item.subFields.forEach(n => {
              reFieldsVal[n.field] = option[n.field]
            })
          }
        }
        if (item.empty === 'hidden' && item.oriOptions.length > 0 && !item.$hidden) {
          item.hidden = false
        }
        if (item.type === 'checkcard' && item.readonly && item.unchecked === 'hidden') {
          let selectKeys = item.initval
          if (item.multiple === 'true') {
            selectKeys = selectKeys ? selectKeys.split(',') : []
            item.options = item.options.filter(item => selectKeys.includes(item.$value))
          } else {
            item.options = item.options.filter(item => selectKeys === item.$value)
          }
          item.oriOptions = fromJS(item.options).toJS()
          if (item.options.length === 0) {
            item.hidden = true
          } else {
            item.hidden = false
          }
        }
      }
@@ -835,6 +916,10 @@
      current.controlFields.forEach(cell => {
        let m = map.get(cell.field)
        m.hidden = current.hidden || !cell.values.includes(val)
        if (m.empty === 'hidden' && m.oriOptions.length === 0) {
          m.hidden = true
        }
        if (m.hidden) {
          m.initval = this.record[m.field]
@@ -913,6 +998,8 @@
          content = (<MKCheckCard config={item} onChange={(val, other) => this.recordChange({[item.field]: val, ...other}, item)}/>)
        } else if (item.type === 'switch') {
          content = (<MKSwitch config={item} onChange={(val) => this.recordChange({[item.field]: val}, item)}/>)
        } else if (item.type === 'check') {
          content = (<MKCheck config={item} onChange={(val) => this.recordChange({[item.field]: val}, item)}/>)
        } else if (item.type === 'checkbox') {
          content = (<MKCheckbox config={item} onChange={(val) => this.recordChange({[item.field]: val})}/>)
        } else if (item.type === 'radio') {
@@ -927,6 +1014,8 @@
          content = (<MKTextArea config={item} onChange={(val, defer) => !defer && this.recordChange({[item.field]: val})}/>)
        } else if (item.type === 'rate') {
          content = (<Rate count={item.rateCount} disabled={item.readonly} style={{color: item.color || '#fadb14'}} onChange={(val) => this.recordChange({[item.field]: val})} character={item.character ? <MkIcon type={item.character}/> : <StarFilled />} allowHalf={item.allowHalf}/>)
        } else if (item.type === 'vercode') {
          content = (<MkVercode config={item} record={this.record} onSend={(send_type, timestamp, n_id) => this.setState({send_type, timestamp, n_id})} onChange={(val) => this.recordChange({[item.field]: val})} onSubmit={this.props.inputSubmit}/>)
        } else if (item.type === 'brafteditor') {
          content = (<MKEditor config={item} onChange={(val) => this.recordChange({[item.field]: val})}/>)
          label = item.hidelabel !== 'true' ? label : ''
@@ -958,7 +1047,7 @@
  }
  handleConfirm = () => {
    const { formlist } = this.state
    const { formlist, send_type, timestamp, n_id } = this.state
    // 表单提交时检查输入值是否正确
    return new Promise((resolve, reject) => {
@@ -967,7 +1056,7 @@
          reject(err)
          return
        }
        let search = []
        let forms = []
        let record = {...this.record, ...values}
        formlist.forEach(item => {
@@ -1005,16 +1094,44 @@
                _item.value = _item.value.slice(-item.fieldlength)
              }
            }
          } else if (item.type.indexOf('date') > -1) {
            if (item.declareType === 'nvarchar(50)') {
              _item.type = 'text'
            }
          } else if (item.type === 'datemonth') {
            _item.type = 'text'
          } else  if (item.type === 'date') {
            _item.type = item.declareType === 'nvarchar(50)' ? 'text' : 'date'
          } else if (item.type === 'vercode') {
            _item.type = 'text'
            forms.push({
              type: 'text',
              readin: false,
              writein: false,
              fieldlen: 50,
              key: 'mk_timestamp',
              value: timestamp || ''
            })
            forms.push({
              type: 'text',
              readin: false,
              writein: false,
              fieldlen: 50,
              key: 'mk_send_type',
              value: send_type || ''
            })
            forms.push({
              type: 'text',
              readin: false,
              writein: false,
              fieldlen: 50,
              key: 'mk_n_id',
              value: n_id || ''
            })
          }
    
          search.push(_item)
          forms.push(_item)
        })
        resolve(search)
        resolve(forms)
      })
    })
  }