king
2023-02-17 8137ac074ce6370e4b46295e7acf9c7870ef82d2
src/tabviews/custom/components/table/normal-table/index.jsx
@@ -45,6 +45,8 @@
    statFValue: []        // 合计值
  }
  loaded = false
  /**
   * @description 初始化处理
   * 1、 initdata 为打印时使用的数据集
@@ -52,7 +54,6 @@
  UNSAFE_componentWillMount () {
    const { data, initdata } = this.props
    let _config = fromJS(this.props.config).toJS()
    let _cols = new Map()
    let _data = null
    let _sync = _config.setting.sync === 'true'
@@ -78,21 +79,22 @@
    let setting = {..._config.setting, ..._config.wrap}
    if (setting.selected !== 'always' && setting.selected !== 'init') {
    if (setting.selected !== 'always' && setting.selected !== 'init' && setting.selected !== 'sign') {
      setting.selected = 'false'
    } else {
      setting.orisel = true
    }
    if (_config.setting.sync === 'true' && data) {
    if (_sync && data) {
      _data = data[_config.dataName] || []
      _sync = false
    } else if (_config.setting.sync === 'true' && initdata) {
    } else if (_sync && initdata) {
      _data = initdata || []
      _sync = false
    }
    if (_data) {
      this.loaded = true
      _data = _data.map((item, index) => {
        item.key = index
        item.$$uuid = item[_config.setting.primaryKey] || ''
@@ -120,7 +122,7 @@
      if (setting.selected !== 'false' && _data && _data.length > 0) {
        setTimeout(() => {
          MKEmitter.emit('mkCheckTopLine', _config.uuid)
          MKEmitter.emit('mkCheckTopLine', _config.uuid, '', setting.selected)
        }, 200)
        if (setting.selected === 'init') {
          setting.selected = 'false'
@@ -128,20 +130,8 @@
      }
    }
    _config.columns.forEach(item => {
      if (item.type !== 'number') return
      _cols.set(item.field, item)
    })
    _config.cols.forEach(column => {
      if (column.type === 'custom') {
        column.elements = column.elements.map(item => {
          if (item.eleType === 'number' && item.field && _cols.has(item.field) && typeof(item.decimal) !== 'number') {
            item.decimal = _cols.get(item.field).decimal || 0
          }
          return item
        })
      } else if (column.type === 'action') {
      if (column.type === 'action') {
        column.operations = column.elements
      }
    })
@@ -201,10 +191,12 @@
      })
      
      MKEmitter.emit('resetSelectLine', config.uuid, '', '') // 广播数据切换
      reset && MKEmitter.emit('resetTable', config.uuid, repage) // 列表重置
      reset && MKEmitter.emit('resetTable', config.uuid, 'true') // 列表重置
      if (setting.$hasSyncModule) {
        MKEmitter.emit('syncBalconyData', config.uuid, [], false)
      }
      this.loaded = true
      return
    }
@@ -234,9 +226,31 @@
    let result = await Api.genericInterface(param)
    if (result.status) {
      this.loaded = true
      if (config.$cache && pageIndex === 1) {
        Api.writeCacheConfig(config.uuid, result.data || '')
      }
      if (repage === 'false' && result.data && result.data.length === 0 && result.total > 0 && pageIndex > 1) {
        let _pageIndex = Math.ceil(result.total / pageSize)
        if (_pageIndex < pageIndex) {
          MKEmitter.emit('resetTable', config.uuid, 'repage', _pageIndex)
          this.setState({
            pageIndex: _pageIndex,
            data: [],
            selectedData: [],
            total: result.total
          }, () => {
            this.loadmaindata()
          })
          return
        }
      }
      if ((setting.selected !== 'false' || (setting.orisel && id)) && result.data && result.data.length > 0) {
        setTimeout(() => {
          MKEmitter.emit('mkCheckTopLine', config.uuid, id)
          MKEmitter.emit('mkCheckTopLine', config.uuid, id, setting.selected)
        }, 200)
        if (setting.selected === 'init') {
          this.setState({setting: {...setting, selected: 'false'}})
@@ -561,6 +575,7 @@
    const { setting } = this.state
    if (!setting.supModule || setting.supModule !== MenuID) return
    if (id !== this.state.BID || id !== '') {
      this.setState({
        pageIndex: 1,
@@ -635,13 +650,15 @@
        if (setting.selected !== 'false' && _data && _data.length > 0) {
          setTimeout(() => {
            MKEmitter.emit('mkCheckTopLine', config.uuid)
            MKEmitter.emit('mkCheckTopLine', config.uuid, '', setting.selected)
          }, 200)
          if (setting.selected === 'init') {
            this.setState({setting: {...setting, selected: 'false'}})
          }
        }
      }
      this.loaded = true
      this.setState({sync: false, data: _data})
    } else if (config.setting.useMSearch && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) {
@@ -656,7 +673,7 @@
  }
  componentDidMount () {
    const { config } = this.state
    const { config, setting } = this.state
    MKEmitter.addListener('reloadData', this.reloadData)
    MKEmitter.addListener('resetSelectLine', this.resetParentParam)
@@ -672,6 +689,35 @@
          this.loadmaindata(true, 'true', '', 'timer')
          this.getStatFieldsValue()
        })
      })
    }
    if (config.$cache && !this.loaded) {
      Api.getLCacheConfig(config.uuid).then(res => {
        if (!res || this.loaded) return
        this.setState({data: res.map((item, index) => {
          item.key = index
          item.$$uuid = item[config.setting.primaryKey] || ''
          item.$$key = '' + item.key + item.$$uuid
          item.$Index = index + 1 + ''
          if (config.absFields) {
            config.absFields.forEach(f => {
              if (!isNaN(item[f])) {
                item[f] = Math.abs(item[f])
              }
            })
          }
          if (setting.controlField) {
            if (setting.controlVal.includes(item[setting.controlField])) {
              item.$disabled = true
            }
          }
          return item
        })})
      })
    }
  }
@@ -713,7 +759,7 @@
              BData={BData}
              columns={config.columns}
              selectedData={selectedData}
            /> : <div style={{height: '25px'}}></div>}
            /> : <div className="mk-action-space" style={{height: '25px'}}></div>}
            <div className="main-table-box">
              <MainTable
                setting={setting}
@@ -742,7 +788,7 @@
            BData={BData}
            columns={config.columns}
            selectedData={selectedData}
          /> : <div style={{height: '15px'}}></div>}
          /> : <div className="mk-action-space" style={{height: '25px'}}></div>}
          <div className={'main-table-box ' + (!actions || actions.length === 0 ? 'no-action' : '')}>
            <MainTable
              setting={setting}