import React, { Component } from 'react';
import { Table, } from 'antd';

export default class ConditionDetailPanel extends Component {
    constructor(props) {
        super(props);
        this.state = {
            selectedData: [],
        }
    }
    componentWillReceiveProps(nextprops) {
        if ((nextprops.selectedData !== undefined)&&(this.props.selectedData !== undefined)) {
            if (this.props.selectedData.length !== nextprops.selectedData.length) {
                this.setState({
                    selectedData: nextprops.selectedData
                })
            }
        }
    }
    componentDidMount() {
        // 提供给外部该组件的this
        this.props.onRef ? this.props.onRef(this) : ''
    }
    clearSelectedData = () => {
        this.setState({
            selectedData: []
        })
    }
    render() {
        const rowSelect = {
            onChange: (selectedRowKeys, selectedRows) => {
                this.props.storageData(this.props.tableName, selectedRowKeys);
                 this.setState({ selectedData: selectedRowKeys });
            },
            selectedRowKeys: this.state.selectedData
        };
        return (
                <Table
                    showHeader={false}
                    bordered={true}
                    rowSelection={rowSelect}
                    columns={this.props.title}
                    dataSource={this.props.dataArr}
                    pagination={false}
                    loading={false}
                    rowKey={this.props.id}
                    scroll={this.props.scroll}
                />
        )
    }
}
