king
2021-01-26 68f84129b685aa9539ac38ca1cf1f164c4d58074
src/tabviews/subtable/index.jsx
@@ -70,21 +70,19 @@
   * @description 上级菜单id变化时,刷新数据
   */
  UNSAFE_componentWillReceiveProps(nextProps) {
    if (this.state.config && this.props.Tab.supMenu && !is(fromJS(this.props.BID), fromJS(nextProps.BID))) {
    const { config, setting } = this.state
    if (config && setting && this.props.Tab.supMenu && !is(fromJS(this.props.BID), fromJS(nextProps.BID))) {
      MKEmitter.emit('resetTable', this.props.MenuID + this.props.Tab.uuid) // 列表重置
      this.setState({
        pageIndex: 1
      }, () => {
        if (this.state.setting) {
          this.loadmaindata()
        }
        this.loadData()
      })
    } else if (!this.props.Tab.supMenu && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) {
      if (this.state.setting) {
        this.setState({}, () => {
          this.loadmaindata()
        })
      }
    } else if (setting && !this.props.Tab.supMenu && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) {
      this.setState({}, () => {
        this.loadData()
      })
    }
  }
@@ -266,11 +264,10 @@
      let valid = true // 搜索条件必填验证
      let hasReqFields = false
      config.search.forEach(field => {
        if (field.required === 'true' && !field.initval) {
        if (field.required !== 'true') return
        hasReqFields = true
        if (!field.initval) {
          valid = false
        }
        if (field.required === 'true') {
          hasReqFields = true
        }
      })
@@ -327,7 +324,7 @@
        hasReqFields
      }, () => {
        if (config.setting.onload !== 'false' && (!Tab.supMenu || BID || Tab.isTreeNode) && valid) { // 初始化可加载
          this.loadmaindata()
          this.loadData()
        }
      })
    } else {
@@ -347,17 +344,20 @@
  
  loadData = () => {
    const { mainSearch, BID } = this.props
    const { setting, search, loadCustomApi } = this.state
    const { setting, search, loadCustomApi, hasReqFields } = this.state
    let searches = fromJS(search).toJS()
    if (mainSearch && mainSearch.length > 0) { // 主表搜索条件
      searches = [...mainSearch, ...searches]
    }
    let requireFields = searches.filter(item => item.required && (!item.value || item.value.length === 0))
    let prex = this.props.Tab && this.props.Tab.label ? this.props.Tab.label + '-' : ''
    let requireFields = []
    if (hasReqFields) {
      requireFields = searches.filter(item => item.required && (!item.value || item.value.length === 0))
    }
    if (requireFields.length > 0) {
      let prex = this.props.Tab && this.props.Tab.label ? this.props.Tab.label + '-' : ''
      let labels = requireFields.map(item => item.label)
      labels = Array.from(new Set(labels))
@@ -374,6 +374,7 @@
        statFValue: [],
        total: 0
      })
      this.handleTableId()
      return
    } else if (window.GLOB.systemType === 'production' && setting.interType === 'custom' && !setting.proInterface) {
      notification.warning({
@@ -384,12 +385,17 @@
      return
    }
    this.setState({
      selectedData: []
    })
    this.handleTableId()
    if (setting.interType === 'custom' && loadCustomApi) {
      if (setting.execTime === 'once') {
        this.setState({loadCustomApi: false})
      }
      this.loadOutResource()
      this.loadOutResource(searches)
      if (setting.execType === 'async') {
        this.loadmaindata()
      }
@@ -398,10 +404,11 @@
    }
  }
  loadOutResource = () => {
    const { setting, search, BID } = this.state
  loadOutResource = (searches) => {
    const { BID } = this.props
    const { setting } = this.state
    let param = UtilsDM.getPrevQueryParams(setting, search, BID, this.props.menuType)
    let param = UtilsDM.getPrevQueryParams(setting, searches, BID, this.props.menuType)
    if (setting.execType === 'sync') {
      this.setState({
@@ -464,7 +471,7 @@
        let error = '未知的返回结果!'
        if (typeof(res) === 'string') {
          error = res
          error = res.replace(/'/ig, '"')
        }
        let _result = {
@@ -569,8 +576,8 @@
      
      param = UtilsDM.getCallBackQueryParams(setting, sql, errSql)
      if (this.state.BID) {
        param.BID = this.state.BID
      if (this.props.BID) {
        param.BID = this.props.BID
      }
      if (this.props.menuType === 'HS') { // 函数 sPC_TableData_InUpDe 云端验证
@@ -579,8 +586,8 @@
    } else {
      param.func = 's_ex_result_back'
      param.s_ex_result = [...lineMap.values()].map((item, index) => ({
        MenuID: this.state.config.MenuID,
        MenuName: this.state.config.MenuName,
        MenuID: this.props.MenuID,
        MenuName: this.props.Tab.label,
        TableName: item.table,
        LongText: window.btoa(window.encodeURIComponent(`${item.insert}  ${item.selects.join(` union all `)}`)),
        Sort: index + 1
@@ -629,39 +636,12 @@
      searches = [...mainSearch, ...searches]
    }
    let requireFields = search.filter(item => item.required && (!item.value || item.value.length === 0))
    let prex = this.props.Tab && this.props.Tab.label ? this.props.Tab.label + '-' : ''
    if (requireFields.length > 0) {
      let labels = requireFields.map(item => item.label)
      labels = Array.from(new Set(labels))
      notification.warning({
        top: 92,
        message: prex + this.state.dict['form.required.input'] + labels.join('、') + ' !',
        duration: 3
      })
      return
    }
    if (this.props.Tab.supMenu && !BID) { // 主表ID不存在时,不查询子表
      this.setState({
        data: [],
        selectedData: [],
        statFValue: [],
        total: 0
      })
      return
    }
    this.setState({
      loading: true
    })
    let _orderBy = orderBy || setting.order
    let param = UtilsDM.getQueryDataParams(setting, arr_field, searches, _orderBy, pageIndex, pageSize, BID, this.props.menuType)
    this.handleTableId()
    if (param.func === 'sPC_Get_TableData') {
      param.menuname = this.props.Tab.label || ''
@@ -836,7 +816,7 @@
      pageIndex: 1,
      search: searches,
    }, () => {
      this.loadmaindata()
      this.loadData()
    })
  }
@@ -857,7 +837,7 @@
      pageSize: pagination.pageSize,
      orderBy: (sorter.field && sorter.order) ? `${sorter.field} ${sorter.order}` : ''
    }, () => {
      this.loadmaindata()
      this.loadData()
    })
  }
@@ -870,11 +850,11 @@
      this.setState({
        pageIndex: 1
      }, () => {
        this.loadmaindata()
        this.loadData()
      })
    } else {
      MKEmitter.emit('resetTable', this.props.MenuID + this.props.Tab.uuid, 'false') // 列表重置
      this.loadmaindata()
      this.loadData()
    }
  }