king
2020-11-10 5df578ff69f6b02e821d59a8883bc75d78695a62
src/tabviews/custom/components/card/table-card/index.jsx
@@ -1,7 +1,7 @@
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { is, fromJS } from 'immutable'
import { Spin, notification, Col, Empty } from 'antd'
import { Spin, notification, Col, Empty, Pagination } from 'antd'
import asyncComponent from '@/utils/asyncComponent'
import Api from '@/api'
@@ -24,6 +24,9 @@
  state = {
    config: null,              // 图表配置信息
    loading: false,            // 数据加载状态
    preIndex: 0,               // 开始索引
    pageIndex: 1,              // 页码
    total: 0,                  // 总数
    sync: false,               // 是否统一请求数据
    data: null,                // 数据
    title: '',                 // 标题
@@ -46,6 +49,12 @@
    let showHeader = false
    if (_config.wrap.title || _config.search.length > 0) {
      showHeader = true
    }
    if (_config.setting.laypage) {
      _config.wrap.contentHeight = _config.wrap.height - (showHeader ? 85 : 40)
    } else {
      _config.wrap.contentHeight = _config.wrap.height - (showHeader ? 45 : 0)
    }
    _config.columns.forEach(item => {
@@ -121,12 +130,16 @@
    if (syncId && syncId !== config.uuid) return
    this.setState({
      pageIndex: 1
    }, () => {
    this.loadData()
    })
  }
  async loadData () {
    const { mainSearch, BID, menuType, dataManager } = this.props
    const { config, arr_field } = this.state
    const { config, arr_field, pageIndex } = this.state
    let searches = []
    if (mainSearch && mainSearch.length > 0) { // 主表搜索条件
@@ -143,12 +156,19 @@
    })
    let _orderBy = config.setting.order || ''
    let param = UtilsDM.getQueryDataParams(config.setting, arr_field, searches, _orderBy, 1, 1, BID, menuType, dataManager)
    let param = UtilsDM.getQueryDataParams(config.setting, arr_field, searches, _orderBy, pageIndex, config.setting.pageSize, BID, menuType, dataManager)
    let result = await Api.genericInterface(param)
    if (result.status) {
      let _preIndex = 0
      if (config.setting.laypage) {
        _preIndex = config.setting.pageSize * (pageIndex - 1)
      }
      this.setState({
        data: result.data,
        total: result.total,
        preIndex: _preIndex,
        loading: false
      })
    } else {
@@ -175,6 +195,14 @@
        }
      }
    }
  }
  changePageIndex = (page) => {
    this.setState({
      pageIndex: page
    }, () => {
      this.loadData()
    })
  }
  getLines = (data, seq) => {
@@ -219,7 +247,7 @@
  }
  render() {
    const { config, loading, data, title, showHeader } = this.state
    const { config, loading, data, title, showHeader, pageIndex, preIndex, total } = this.state
    return (
      <div className="custom-table-card-box" style={{...config.style, height: config.wrap.height}}>
@@ -233,10 +261,13 @@
          <span className="table-title">{title}</span>
          {/* <searchLine /> */}
        </div> : null}
        {data && data.length > 0 ? <div className="card-row-list" style={{height: config.wrap.height - (showHeader ? 45 : 0)}}>
          {data.map((item, index) => this.getLines(item, index + 1))}
        {data && data.length > 0 ? <div className="card-row-list" style={{height: config.wrap.contentHeight}}>
          {data.map((item, index) => this.getLines(item, preIndex + index + 1))}
        </div> : null}
        {data && data.length === 0 ? <Empty description={false}/> : null}
        {data && data.length === 0 ? <div className="card-row-list" style={{height: config.wrap.contentHeight}}>
          <Empty description={false}/>
        </div> : null}
        {config.setting.laypage ? <Pagination size="small" current={pageIndex} total={total} onChange={this.changePageIndex} /> : null}
      </div>
    )
  }