king
2020-12-10 84804b405cb88f659d055b16eb3bd00b813ccb4a
src/tabviews/custom/components/card/prop-card/index.jsx
@@ -21,6 +21,7 @@
  }
  state = {
    BID: '',                   // 上级ID
    config: null,              // 图表配置信息
    loading: false,            // 数据加载状态
    activeKey: '',             // 选中数据
@@ -29,7 +30,7 @@
  }
  UNSAFE_componentWillMount () {
    const { data, initdata } = this.props
    const { data, initdata, BID } = this.props
    let _config = fromJS(this.props.config).toJS()
    let _cols = new Map()
@@ -55,6 +56,10 @@
      _data = {}
    }
    if (_data) {
      _data.$$BID = BID || ''
    }
    _config.columns.forEach(item => {
      _cols.set(item.field, item)
    })
@@ -77,6 +82,7 @@
    this.setState({
      sync: _sync,
      data: _data,
      BID: BID || '',
      config: _config,
      arr_field: _config.columns.map(col => col.field).join(','),
    }, () => {
@@ -88,6 +94,7 @@
  componentDidMount () {
    MKEmitter.addListener('syncRefreshComponentId', this.reload)
    MKEmitter.addListener('resetSelectLine', this.resetParentParam)
  }
  shouldComponentUpdate (nextProps, nextState) {
@@ -99,13 +106,14 @@
      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 = {}
@@ -113,7 +121,12 @@
        _data = nextProps.data[config.dataName]
        if (_data && Array.isArray(_data)) {
          _data = _data[0]
        } else {
          _data = {}
        }
      }
      if (_data) {
        _data.$$BID = BID || ''
      }
      this.setState({sync: false, data: _data})
@@ -126,6 +139,17 @@
    }
  }
  resetParentParam = (MenuID, id) => {
    const { config } = this.state
    if (config.wrap.datatype === 'static' || !config.setting.supModule || config.setting.supModule !== MenuID) return
    if (id !== this.state.BID) {
      this.setState({ BID: id }, () => {
        this.loadData()
      })
    }
  }
  reload = (syncId) => {
    const { config } = this.state
@@ -135,8 +159,22 @@
  }
  async loadData () {
    const { mainSearch, BID, menuType } = this.props
    const { config, arr_field } = this.state
    const { mainSearch, menuType } = this.props
    const { config, arr_field, BID } = this.state
    if (config.wrap.datatype === 'static') {
      this.setState({
        data: {$$BID: BID || ''},
        loading: false
      })
      return
    } else if (config.setting.supModule && !BID) { // BID 不存在时,不做查询
      this.setState({
        data: {$$BID: BID || ''},
        loading: false
      })
      return
    }
    let searches = []
    if (mainSearch && mainSearch.length > 0) { // 主表搜索条件
@@ -148,26 +186,21 @@
      })
    }
    if (config.wrap.datatype === 'static') {
      this.setState({
        loading: false,
        data: {}
      })
      return
    } else {
      this.setState({
        loading: true
      })
    }
    let _orderBy = config.setting.order || ''
    let param = UtilsDM.getQueryDataParams(config.setting, arr_field, searches, _orderBy, 1, 1, BID, menuType)
    let result = await Api.genericInterface(param)
    if (result.status) {
      let _data = result.data && result.data[0] ? result.data[0] : {}
      _data.$$BID = BID || ''
      this.setState({
        activeKey: '',
        data: result.data && result.data[0] ? result.data[0] : {},
        data: _data,
        loading: false
      })
    } else {
@@ -207,7 +240,6 @@
  }
  render() {
    const { BID } = this.props
    const { config, loading, data, activeKey } = this.state
    return (
@@ -221,7 +253,7 @@
        <div className="card-row-list">
          {config.subcards.map((item, index) => (
            <Col className={activeKey === index ? 'active' : ''} key={index} span={item.setting.width || 6} onClick={() => {this.changeCard(index, item)}}>
              <CardItem BID={BID} card={item} cards={config} data={data} updateStatus={this.updateStatus}/>
              <CardItem card={item} cards={config} data={data} updateStatus={this.updateStatus}/>
            </Col>
          ))}
        </div>