king
2020-12-18 106263ec10e60ce6c406e4fd5eb76d195772d0f0
src/tabviews/custom/components/card/table-card/index.jsx
@@ -3,13 +3,15 @@
import { is, fromJS } from 'immutable'
import { Spin, notification, Col, Empty, Pagination } from 'antd'
import asyncComponent from '@/utils/asyncComponent'
import Api from '@/api'
import Utils from '@/utils/utils.js'
import asyncComponent from '@/utils/asyncComponent'
import UtilsDM from '@/utils/utils-datamanage.js'
import MKEmitter from '@/utils/events.js'
import './index.scss'
const CardCellComponent = asyncComponent(() => import('../cardcellList'))
const NormalHeader = asyncComponent(() => import('@/tabviews/custom/components/share/normalheader'))
class TableCard extends Component {
  static propTpyes = {
@@ -18,23 +20,26 @@
    config: PropTypes.object,        // 组件配置信息
    mainSearch: PropTypes.any,       // 外层搜索条件
    menuType: PropTypes.any,         // 菜单类型
    dataManager: PropTypes.any,      // 数据权限
  }
  state = {
    BID: '',                   // 上级ID
    config: null,              // 图表配置信息
    loading: false,            // 数据加载状态
    search: null,              // 搜索条件
    preIndex: 0,               // 开始索引
    pageIndex: 1,              // 页码
    total: 0,                  // 总数
    sync: false,               // 是否统一请求数据
    data: null,                // 数据
    title: '',                 // 标题
    showHeader: false          // 存在标题、搜索
  }
  /**
   * @description 初始化处理
   * 1、 initdata 为打印时使用的数据集
   */
  UNSAFE_componentWillMount () {
    const { data, initdata } = this.props
    const { data, initdata, BID } = this.props
    let _config = fromJS(this.props.config).toJS()
    let _cols = new Map()
@@ -47,6 +52,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
      })
    }
    let showHeader = false
@@ -74,11 +88,11 @@
    })
    this.setState({
      showHeader: showHeader,
      title: _config.wrap.title,
      sync: _sync,
      BID: BID || '',
      data: _data,
      config: _config,
      search: Utils.initMainSearch(_config.search),
      arr_field: _config.columns.map(col => col.field).join(','),
    }, () => {
      if (_config.setting.sync !== 'true' && _config.setting.onload === 'true') {
@@ -89,6 +103,7 @@
  componentDidMount () {
    MKEmitter.addListener('syncRefreshComponentId', this.reload)
    MKEmitter.addListener('resetSelectLine', this.resetParentParam)
  }
  shouldComponentUpdate (nextProps, nextState) {
@@ -100,19 +115,27 @@
      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 = []
      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))) {
@@ -121,6 +144,17 @@
          this.loadData()
        })
      }
    }
  }
  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()
      })
    }
  }
@@ -137,10 +171,19 @@
  }
  async loadData () {
    const { mainSearch, BID, menuType, dataManager } = this.props
    const { config, arr_field, pageIndex } = this.state
    const { mainSearch, menuType } = this.props
    const { config, arr_field, pageIndex, search, BID } = this.state
    let searches = []
    if (config.setting.supModule && !BID) { // BID 不存在时,不做查询
      this.setState({
        data: [],
        total: 0,
        preIndex: 0
      })
      return
    }
    let searches = fromJS(search).toJS()
    if (mainSearch && mainSearch.length > 0) { // 主表搜索条件
      let keys = searches.map(item => item.key)
      mainSearch.forEach(item => {
@@ -155,7 +198,7 @@
    })
    let _orderBy = config.setting.order || ''
    let param = UtilsDM.getQueryDataParams(config.setting, arr_field, searches, _orderBy, pageIndex, config.setting.pageSize, BID, menuType, dataManager)
    let param = UtilsDM.getQueryDataParams(config.setting, arr_field, searches, _orderBy, pageIndex, config.setting.pageSize, BID, menuType)
    let result = await Api.genericInterface(param)
    if (result.status) {
@@ -165,7 +208,12 @@
      }
      this.setState({
        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,
        preIndex: _preIndex,
        loading: false
@@ -188,7 +236,7 @@
    if (type === 'refresh' && position === 'grid') {
      this.loadData()
      if (btn && btn.syncComponent && btn.syncComponent[0]) {
        let syncId = btn.syncComponent[btn.syncComponent.length - 1]
        let syncId = btn.syncComponent.slice(-1)[0]
        if (config.uuid !== syncId) {
          MKEmitter.emit('syncRefreshComponentId', syncId)
        }
@@ -205,7 +253,6 @@
  }
  getLines = (data, seq) => {
    const { BID } = this.props
    const { config } = this.state
    let line = []
@@ -236,7 +283,7 @@
      line.push(
        <Col key={index} span={24}>
          <div className="card-item-box" style={item.style}>
            <CardCellComponent BID={BID} seq={seq} data={data} cards={config} cardCell={item} elements={item.elements} updateStatus={this.updateStatus}/>
            <CardCellComponent seq={seq} data={data} cards={config} cardCell={item} elements={item.elements} updateStatus={this.updateStatus}/>
          </div>
        </Col>
      )
@@ -245,21 +292,27 @@
    return line
  }
  refreshSearch = (list) => {
    this.setState({
      search: list,
      pageIndex: 1
    }, () => {
      this.loadData()
    })
  }
  render() {
    const { config, loading, data, title, showHeader, pageIndex, preIndex, total } = this.state
    const { config, loading, data, BID, pageIndex, preIndex, total } = this.state
    return (
      <div className="custom-table-card-box" style={{...config.style, height: config.wrap.height}}>
        {loading ?
          <div className="loading-mask">
            <div className="ant-spin-blur"></div>
            {data ? <div className="ant-spin-blur"></div> : null}
            <Spin />
          </div> : null
        }
        {showHeader ? <div className="table-header" style={config.headerStyle}>
          <span className="table-title">{title}</span>
          {/* <searchLine /> */}
        </div> : null}
        <NormalHeader config={config} BID={BID} menuType={this.props.menuType} refresh={this.refreshSearch} />
        {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}