king
2020-12-10 84804b405cb88f659d055b16eb3bd00b813ccb4a
src/tabviews/custom/components/card/table-card/index.jsx
@@ -21,6 +21,7 @@
  }
  state = {
    BID: '',                   // 上级ID
    config: null,              // 图表配置信息
    loading: false,            // 数据加载状态
    preIndex: 0,               // 开始索引
@@ -37,7 +38,7 @@
   * 1、 initdata 为打印时使用的数据集
   */
  UNSAFE_componentWillMount () {
    const { data, initdata } = this.props
    const { data, initdata, BID } = this.props
    let _config = fromJS(this.props.config).toJS()
    let _cols = new Map()
@@ -50,6 +51,15 @@
    } else if (_config.setting.sync === 'true' && initdata) {
      _data = initdata || []
      _sync = false
    }
    if (_data) {
      _data = _data.map((item, index) => {
        item.key = index
        item.$$uuid = item[_config.setting.primaryKey] || ''
        item.$$BID = BID || ''
        return item
      })
    }
    let showHeader = false
@@ -80,6 +90,7 @@
      showHeader: showHeader,
      title: _config.wrap.title,
      sync: _sync,
      BID: BID || '',
      data: _data,
      config: _config,
      arr_field: _config.columns.map(col => col.field).join(','),
@@ -92,6 +103,7 @@
  componentDidMount () {
    MKEmitter.addListener('syncRefreshComponentId', this.reload)
    MKEmitter.addListener('resetSelectLine', this.resetParentParam)
  }
  shouldComponentUpdate (nextProps, nextState) {
@@ -103,19 +115,27 @@
      return
    }
    MKEmitter.removeListener('syncRefreshComponentId', this.reload)
    MKEmitter.removeListener('resetSelectLine', this.resetParentParam)
  }
  /**
   * @description 图表数据更新,刷新内容
   */
  UNSAFE_componentWillReceiveProps (nextProps) {
    const { sync, config } = this.state
    const { sync, config, BID } = this.state
    if (sync && !is(fromJS(this.props.data), fromJS(nextProps.data))) {
      let _data = []
      if (nextProps.data && nextProps.data[config.dataName]) {
        _data = nextProps.data[config.dataName] || []
      }
      _data = _data.map((item, index) => {
        item.key = index
        item.$$uuid = item[config.setting.primaryKey] || ''
        item.$$BID = BID || ''
        return item
      })
      this.setState({sync: false, data: _data})
    } else if (!is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) {
@@ -124,6 +144,17 @@
          this.loadData()
        })
      }
    }
  }
  resetParentParam = (MenuID, id) => {
    const { config } = this.state
    if (!config.setting.supModule || config.setting.supModule !== MenuID) return
    if (id !== this.state.BID) {
      this.setState({ BID: id }, () => {
        this.loadData()
      })
    }
  }
@@ -140,8 +171,17 @@
  }
  async loadData () {
    const { mainSearch, BID, menuType } = this.props
    const { config, arr_field, pageIndex } = this.state
    const { mainSearch, menuType } = this.props
    const { config, arr_field, pageIndex, BID } = this.state
    if (config.setting.supModule && !BID) { // BID 不存在时,不做查询
      this.setState({
        data: [],
        total: 0,
        preIndex: 0
      })
      return
    }
    let searches = []
    if (mainSearch && mainSearch.length > 0) { // 主表搜索条件
@@ -168,7 +208,12 @@
      }
      this.setState({
        data: result.data,
        data: result.data.map((item, index) => {
          item.key = index
          item.$$uuid = item[config.setting.primaryKey] || ''
          item.$$BID = BID || ''
          return item
        }),
        total: result.total,
        preIndex: _preIndex,
        loading: false
@@ -208,7 +253,6 @@
  }
  getLines = (data, seq) => {
    const { BID } = this.props
    const { config } = this.state
    let line = []
@@ -239,7 +283,7 @@
      line.push(
        <Col key={index} span={24}>
          <div className="card-item-box" style={item.style}>
            <CardCellComponent BID={BID} seq={seq} data={data} cards={config} cardCell={item} elements={item.elements} updateStatus={this.updateStatus}/>
            <CardCellComponent seq={seq} data={data} cards={config} cardCell={item} elements={item.elements} updateStatus={this.updateStatus}/>
          </div>
        </Col>
      )