king
2020-12-10 84804b405cb88f659d055b16eb3bd00b813ccb4a
src/tabviews/custom/components/card/data-card/index.jsx
@@ -23,8 +23,9 @@
  }
  state = {
    BID: '',                   // 上级ID
    config: null,              // 图表配置信息
    pageIndex: 1,
    pageIndex: 1,              // 页码
    activeKey: '',             // 选中卡
    loading: false,            // 数据加载状态
    sync: false,               // 是否统一请求数据
@@ -34,7 +35,7 @@
  }
  UNSAFE_componentWillMount () {
    const { data, initdata } = this.props
    const { data, initdata, BID } = this.props
    let _config = fromJS(this.props.config).toJS()
    let _card = _config.subcards[0]
    let _cols = new Map()
@@ -48,6 +49,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
      })
    }
    _config.columns.forEach(item => {
@@ -70,6 +80,7 @@
    this.setState({
      sync: _sync,
      data: _data,
      BID: BID || '',
      config: _config,
      card: _card,
      arr_field: _config.columns.map(col => col.field).join(','),
@@ -82,6 +93,7 @@
  componentDidMount () {
    MKEmitter.addListener('syncRefreshComponentId', this.reload)
    MKEmitter.addListener('resetSelectLine', this.resetParentParam)
  }
  shouldComponentUpdate (nextProps, nextState) {
@@ -89,13 +101,20 @@
  }
  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))) {
@@ -112,6 +131,7 @@
      return
    }
    MKEmitter.removeListener('syncRefreshComponentId', this.reload)
    MKEmitter.removeListener('resetSelectLine', this.resetParentParam)
  }
  reload = (syncId) => {
@@ -126,9 +146,31 @@
    })
  }
  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()
      })
    }
  }
  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({
        activeKey: '',
        pageIndex: 1,
        data: [],
        total: 0,
        loading: false
      })
      return
    }
    let searches = []
    if (mainSearch && mainSearch.length > 0) { // 主表搜索条件
@@ -151,7 +193,12 @@
    if (result.status) {
      this.setState({
        activeKey: '',
        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,
        loading: false
      })
@@ -217,7 +264,6 @@
  }
  render() {
    const { BID } = this.props
    const { config, loading, data, pageIndex, total, card, activeKey } = this.state
    let _total = config.setting.pageSize * pageIndex
@@ -238,7 +284,7 @@
        {data && data.length > 0 ? <div className="card-row-list">
          {data.map((item, index) => (
            <Col className={activeKey === index ? 'active' : ''} key={index} span={card.setting.width || 6} onClick={() => {this.changeCard(index, item)}}>
              <CardItem BID={BID} card={card} cards={config} data={item} updateStatus={this.updateStatus}/>
              <CardItem card={card} cards={config} data={item} updateStatus={this.updateStatus}/>
            </Col>
          ))}
        </div> : null}