import React, { PureComponent } from 'react';
import { Table, Pagination } from 'antd';


type TableProps = {
    columns: any[],
    tableData: any[],
    [propName: string]: any;
}

type PaginationProps = {
    current: number,
    total: number,
    pageSize: number,
}

type PageProps = {
    pagination: PaginationProps,
    [propName: string]: any;
}

class StandardTable extends PureComponent<{
    tableProps: TableProps;
    paginationProps: PageProps,
}>{

    render() {
        const { tableProps: { columns, tableData, ...restTableProps }, paginationProps: { pagination, ...restPaginationProps } } = this.props;
        const { current, total, pageSize } = pagination
        return (
            <div>
                <Table
                    bordered
                    pagination={false}
                    columns={columns}
                    dataSource={tableData}
                    {...restTableProps}
                />
                <Pagination
                    className='jad-pagination-to-table'
                    pageSizeOptions={['10', '20', '50', '100']}
                    showSizeChanger
                    showQuickJumper
                    current={current}
                    total={total}
                    pageSize={pageSize}
                    showTotal={() => `总计:${total}条记录`}
                    {...restPaginationProps}
                />
            </div>
        );
    }
}

export default StandardTable;
