king
2020-03-10 c39ea1f23d21b070188abcf5f4dd5bdd7b47c1f9
src/tabviews/commontable/mainTable/index.jsx
@@ -1,6 +1,6 @@
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { is, fromJS } from 'immutable'
// import { is, fromJS } from 'immutable'
import { Table, message, Affix, Button, Typography } from 'antd'
import './index.scss'
@@ -12,7 +12,6 @@
    MenuID: PropTypes.string,      // 菜单Id
    setting: PropTypes.object,     // 表格全局设置:tableType(表格是否可选、单选、多选)、columnfixed(列固定)、actionfixed(按钮固定)
    pickup: PropTypes.any,         // 数据收起
    setsingle: PropTypes.any,      // 设置单选多选
    columns: PropTypes.array,      // 表格列
    data: PropTypes.any,           // 表格数据
    total: PropTypes.number,       // 总数
@@ -26,13 +25,11 @@
    selectedRowKeys: [],  // 表格中选中行
    pageIndex: 1,         // 初始页面索引
    pageSize: 10,         // 每页数据条数
    columns: null,        // 显示列
    selectId: '',
    isSingleSelect: false
    columns: null         // 显示列
  }
  UNSAFE_componentWillMount () {
    const { columns, setting } = this.props
    const { columns } = this.props
    let _columns = []
    
    columns.forEach(item => {
@@ -50,19 +47,8 @@
    })
    this.setState({
      columns: _columns,
      isSingleSelect: setting.tableType === 'radio'
      columns: _columns
    })
  }
  UNSAFE_componentWillReceiveProps(nextProps) {
    if (!is(fromJS(this.props.setsingle), fromJS(nextProps.setsingle))) {
      this.setState({
        isSingleSelect: nextProps.setsingle,
        selectedRowKeys: [],
        selectId: ''
      })
    }
  }
  getContent = (item, record) => {
@@ -247,8 +233,6 @@
  }
  onSelectChange = selectedRowKeys => {
    if (this.props.pickup) return
    let index = ''
    if (selectedRowKeys.length > 0) {
      index = selectedRowKeys[selectedRowKeys.length - 1]
@@ -266,7 +250,7 @@
    let newkeys = JSON.parse(JSON.stringify(this.state.selectedRowKeys))
    let _re = newkeys.includes(index)
    if (this.props.setting.tableType === 'radio' || this.state.isSingleSelect) {
    if (this.props.setting.tableType === 'radio') {
      this.changedata(index)
      this.setState({ selectedRowKeys: [index] })
    } else {
@@ -301,30 +285,25 @@
      _data = data[index] || ''
    }
    this.setState({
      selectId: _id
    })
    this.props.handleTableId('mainTable', _id, _data)
  }
  resetTable = () => {
    this.setState({
      pageIndex: 1,
      selectId: '',
      selectedRowKeys: []
    })
  }
  render() {
    const { setting, pickup } = this.props
    let { selectedRowKeys, isSingleSelect, selectId } = this.state
    let { selectedRowKeys } = this.state
    let rowSelection = null
    if (setting.tableType) {
      rowSelection = {
        selectedRowKeys,
        type: (setting.tableType === 'radio' || isSingleSelect) ? 'radio' : 'checkbox',
        type: (setting.tableType === 'radio') ? 'radio' : 'checkbox',
        onChange: this.onSelectChange
      }
    }
@@ -345,8 +324,8 @@
    let _data = this.props.data ? this.props.data : []
    if (selectId && pickup && isSingleSelect) {
      _data = _data.filter(item => item[setting.primaryKey] === selectId)
    if (pickup) {
      _data = _data.filter((item, index) => selectedRowKeys.includes(index))
    }
    return (