king
2021-04-14 30b6c01972cc74152b733a94edcc0c2a614a2268
src/tabviews/custom/components/table/normal-table/index.jsx
@@ -95,13 +95,21 @@
      }
    })
    let setting = {..._config.setting, ..._config.wrap, style: {}}
    if (setting.color) {
      setting.style.color = setting.color
    }
    if (setting.fontSize) {
      setting.style.fontSize = setting.fontSize
    }
    this.setState({
      BID: BID || '',
      title: _config.wrap.title,
      sync: _sync,
      data: _data,
      config: _config,
      setting: {..._config.setting, ..._config.wrap},
      setting: setting,
      searchlist: _config.search,
      actions: _config.action,
      columns: _config.cols,
@@ -227,19 +235,25 @@
    let result = await Api.genericInterface(param)
    if (result.status) {
      let data = fromJS(this.state.data).toJS()
      let selectedData = fromJS(this.state.selectedData).toJS()
      if (result.data && result.data[0]) {
        let _data = result.data[0]
        let _data = result.data[0] || {}
        _data.$$uuid = _data[setting.primaryKey] || ''
        _data.$$BID = BID || ''
        try {
          data = data.map(item => {
            if (item[setting.primaryKey] === _data[setting.primaryKey]) {
            if (item.$$uuid === _data.$$uuid) {
              _data.key = item.key
              _data.$$uuid = _data[setting.primaryKey] || ''
              _data.$$BID = BID || ''
              return _data
            } else {
              return item
            }
          })
          selectedData = selectedData.map(item => {
            if (_data.$$uuid === item.$$uuid) {
              return _data
            }
            return item
          })
        } catch {
          console.warn('数据查询错误')
@@ -247,7 +261,8 @@
      }
      this.setState({
        data: data,
        data,
        selectedData,
        loading: false
      })
    } else {
@@ -399,39 +414,38 @@
  }
  /**
   * @description 按钮操作完成后(成功或失败),页面刷新,重置页码及选择项
   */
  refreshbyaction = (position, btn) => {
    if (position === 'grid' || position === 'view') {
      this.reloadtable(btn)
    }
  }
  /**
   * @description 导出Excel时,获取页面搜索排序等参数
   */
  getexceloutparam = () => {
  getexceloutparam = (menuId, btnId) => {
    const { mainSearch } = this.props
    const { arr_field, config, orderBy, search, setting} = this.state
    return {
    if (config.uuid !== menuId) return
    let searches = search ? fromJS(search).toJS() : []
    if (mainSearch && mainSearch.length > 0) { // 主表搜索条件
      let keys = searches.map(item => item.key.toLowerCase())
      mainSearch.forEach(item => {
        if (!keys.includes(item.key.toLowerCase())) {
          searches.push(item)
        }
      })
    }
    MKEmitter.emit('execExcelout', config.uuid, btnId, {
      arr_field: arr_field,
      orderBy: orderBy || setting.order,
      search: search,
      search: searches,
      menuName: config.name
    }
    })
  }
  reloadData = (menuId, id, btn) => {
  reloadData = (menuId, id) => {
    const { config } = this.state
    if (config.uuid !== menuId) return
    if (id === 'empty') return
    if (id === 'formtab') { // 表单标签页刷新
      this.reloadtable(btn)
      return
    }
    if (!id) {
      this.reloadtable()
    } else {
@@ -452,6 +466,31 @@
        this.loadmaindata(true, 'true')
        this.getStatFieldsValue()
      })
    }
  }
  /**
   * @description 按钮执行完成后页面刷新
   * @param {*} menuId     // 菜单Id
   * @param {*} position   // 刷新位置
   * @param {*} btn        // 执行的按钮
   */
  refreshByButtonResult = (menuId, position, btn) => {
    const { config, BID } = this.state
    if (config.uuid !== menuId) return
    this.reloadtable(btn)                                                      // 数据刷新
    if (btn.syncComponentId && btn.syncComponentId !== config.uuid && btn.syncComponentId !== config.setting.supModule) {
      MKEmitter.emit('reloadData', btn.syncComponentId)                        // 同级标签刷新
    }
    if (position === 'mainline' && config.setting.supModule) {                 // 主表行刷新
      MKEmitter.emit('reloadData', config.setting.supModule, (BID || 'empty'))
    } else if (position === 'popclose') {                                      // 标签关闭刷新
      config.setting.supModule && MKEmitter.emit('reloadData', config.setting.supModule, (BID || 'empty'))
      btn.$tabId && MKEmitter.emit('refreshPopButton', btn.$tabId)
    }
  }
@@ -487,6 +526,8 @@
  componentDidMount () {
    MKEmitter.addListener('reloadData', this.reloadData)
    MKEmitter.addListener('resetSelectLine', this.resetParentParam)
    MKEmitter.addListener('getexceloutparam', this.getexceloutparam)
    MKEmitter.addListener('refreshByButtonResult', this.refreshByButtonResult)
  }
  /**
@@ -498,13 +539,15 @@
    }
    MKEmitter.removeListener('reloadData', this.reloadData)
    MKEmitter.removeListener('resetSelectLine', this.resetParentParam)
    MKEmitter.removeListener('getexceloutparam', this.getexceloutparam)
    MKEmitter.removeListener('refreshByButtonResult', this.refreshByButtonResult)
  }
  render() {
    const { BID, setting, searchlist, actions, config, columns, selectedData } = this.state
    return (
      <div className="custom-normal-table">
      <div className="custom-normal-table" style={config.style}>
        <NormalHeader config={config}/>
        {searchlist && searchlist.length ?
          <MainSearch BID={BID} searchlist={searchlist} menuType={this.props.menuType} refreshdata={this.refreshbysearch}/> : null
@@ -516,10 +559,8 @@
          BData={this.state.BData}
          columns={config.columns}
          selectedData={selectedData}
          refreshdata={this.refreshbyaction}
          getexceloutparam={this.getexceloutparam}
        />
        <div className="main-table-box">
        <div className={'main-table-box ' + (!actions || actions.length === 0 ? 'no-action' : '')}>
          <MainTable
            setting={setting}
            columns={columns}
@@ -531,7 +572,6 @@
            loading={this.state.loading}
            refreshdata={this.refreshbytable}
            statFValue={this.state.statFValue}
            refreshbyaction={this.refreshbyaction}
            chgSelectData={(selects) => this.setState({selectedData: selects})}
          />
        </div>