| | |
| | | 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' |
| | | |
| | |
| | | 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, // 总数 |
| | |
| | | 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 => { |
| | |
| | | }) |
| | | |
| | | 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) => { |
| | |
| | | } |
| | | |
| | | onSelectChange = selectedRowKeys => { |
| | | if (this.props.pickup) return |
| | | |
| | | let index = '' |
| | | if (selectedRowKeys.length > 0) { |
| | | index = selectedRowKeys[selectedRowKeys.length - 1] |
| | |
| | | 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 { |
| | |
| | | _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 |
| | | } |
| | | } |
| | |
| | | |
| | | 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 ( |