king
2020-11-12 7facbed508592e842f9bca085cf0ffaebcbfc571
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: '',                 // 标题
@@ -31,7 +34,7 @@
  }
  UNSAFE_componentWillMount () {
    const { data } = this.props
    const { data, initdata } = this.props
    let _config = fromJS(this.props.config).toJS()
    let _cols = new Map()
@@ -41,11 +44,20 @@
    if (_config.setting.sync === 'true' && data) {
      _data = data[_config.dataName] || []
      _sync = false
    } else if (_config.setting.sync === 'true' && initdata) {
      _data = initdata || []
      _sync = false
    }
    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 => {
@@ -71,10 +83,6 @@
    }, () => {
      if (_config.setting.sync !== 'true' && _config.setting.onload === 'true') {
        this.loadData()
      } else if (_sync && !_data) {
        this.setState({
          loading: true
        })
      }
    })
  }
@@ -106,7 +114,7 @@
        _data = nextProps.data[config.dataName] || []
      }
      this.setState({sync: false, loading: false, data: _data})
      this.setState({sync: false, data: _data})
    } else if (!is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) {
      if (config.setting.syncRefresh === 'true') {
        this.setState({}, () => {
@@ -121,12 +129,16 @@
    if (syncId && syncId !== config.uuid) return
    this.loadData()
    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 +155,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 +194,14 @@
        }
      }
    }
  }
  changePageIndex = (page) => {
    this.setState({
      pageIndex: page
    }, () => {
      this.loadData()
    })
  }
  getLines = (data, seq) => {
@@ -219,7 +246,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 +260,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>
    )
  }