king
2020-12-15 bc5ec1017fd8a140ec5c30ea9e8ea839d5bf1bda
src/tabviews/custom/components/card/data-card/index.jsx
@@ -29,6 +29,8 @@
    config: null,              // 图表配置信息
    pageIndex: 1,              // 页码
    activeKey: '',             // 选中卡
    selectKeys: [],            // 多选时选中卡片
    selectedData: [],          // 选中数据,用于工具栏按钮
    loading: false,            // 数据加载状态
    sync: false,               // 是否统一请求数据
    card: null,                // 卡片设置
@@ -166,6 +168,8 @@
    if (config.setting.supModule && !BID) { // BID 不存在时,不做查询
      this.setState({
        activeKey: '',
        selectKeys: [],
        selectedData: [],
        pageIndex: 1,
        data: [],
        total: 0,
@@ -195,6 +199,8 @@
    if (result.status) {
      this.setState({
        activeKey: '',
        selectKeys: [],
        selectedData: [],
        data: result.data.map((item, index) => {
          item.key = index
          item.$$uuid = item[config.setting.primaryKey] || ''
@@ -264,17 +270,48 @@
  }
  
  changeCard = (index, item) => {
    const { config } = this.state
    const { config, selectKeys, selectedData, activeKey } = this.state
    if (config.wrap.switch !== 'true') return
    if (!config.wrap.cardType) return
    let _selectKeys = []
    let _selectedData = []
    let _activeKey = ''
    let _item = item
    if (config.wrap.cardType === 'checkbox') {
      if (activeKey === index) {
        _selectKeys = selectKeys.filter(key => key !== index)
        _selectedData = selectedData.filter(cell => cell.key !== index)
        _activeKey = _selectKeys.slice(-1)[0]
        _item = selectedData.slice(-1)[0] || ''
      } else if (selectKeys.indexOf(index) > -1) {
        _selectKeys = selectKeys.filter(key => key !== index)
        _selectedData = selectedData.filter(cell => cell.key !== index)
        _activeKey = activeKey
        _item = selectedData.filter(cell => cell.key === activeKey)[0] || ''
      } else {
        _selectKeys = [...selectKeys, index]
        _selectedData = [...selectedData, item]
        _activeKey = index
      }
    } else {
      if (activeKey === index) return
      _selectedData = [item]
      _activeKey = index
    }
    this.setState({
      activeKey: index
      activeKey: _activeKey,
      selectKeys: _selectKeys,
      selectedData: _selectedData
    })
    MKEmitter.emit('resetSelectLine', config.uuid, (_item ? _item.$$uuid : ''), _item)
  }
  render() {
    const { config, loading, data, pageIndex, total, card, activeKey, BID, BData, selectedData } = this.state
    const { config, loading, data, pageIndex, total, card, activeKey, BID, BData, selectedData, selectKeys } = this.state
    let _total = config.setting.pageSize * pageIndex
    let switchable = false
@@ -306,7 +343,7 @@
          {switchable ? <div className={'prev-page ' + (pageIndex === 1 ? 'disabled' : '')} onClick={this.prevPage}><div><div><img src={preImg} alt=""/></div></div></div> : null}
          {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)}}>
              <Col className={activeKey === index ? 'active' : (selectKeys.indexOf(index) > -1 ? 'selected' : '')} key={index} span={card.setting.width} onClick={() => {this.changeCard(index, item)}}>
                <CardItem card={card} cards={config} data={item} updateStatus={this.updateStatus}/>
              </Col>
            ))}