import * as React from 'react';
import { Table, } from 'kts-xui';
import { Descriptions, Modal, Pagination, Tooltip } from 'kts-components-antd-x4';
import agent from '../../Server';
import moment from 'moment';
import { findLabel,  effectiveStatusEnum, } from '../../CommonComponents/FiledsEnum';
/** Props接口 */
interface IProps {
    onClose?: () => void;
    /**
     * 列表id
     */
    dataId?: string;
    /**
     * 发票id
     */
    invoiceUuid?: number;
}
export default class UIComponents extends React.Component<IProps, any> {
    columns = [
        {
            title: '处理',
            dataIndex: 'operate',
            width: 120,
        },
        {
            title: '时间',
            dataIndex: 'createTime',
            width: 160,
            ellipsis: true,
            render: (text) => {
                return moment(text).format('YYYY-MM-DD HH:mm');
            }
        },
        {
            title: '证明结果',
            width: 100,
            dataIndex: 'proveStatus',
            render: (text, record) => {
                if (text === 1) {
                    return <span>正常</span>
                } else if (text === 2) {
                    return <Tooltip title={record.message}><span style={{ color: 'red' }}>异常</span></Tooltip>
                }
            }
        },

        {
            title: '业务有效性',
            dataIndex:'effectiveStatus',
            width: 120,
            render: (text, record) => {
                if (text === 2) {
                    return <Tooltip title={record.refusalCause}><span style={{ color: 'red' }}>{findLabel(text, effectiveStatusEnum)}</span></Tooltip>
                } else {
                    return  <span style={{ color: '#0074ff' }}>{findLabel(text, effectiveStatusEnum)}</span>
                }
            }
        },

    ];
    constructor(props) {
        super(props);
        this.state = {
            dataId: this.props.dataId,
            invoiceUuid:this.props.invoiceUuid,
            list: [],
            pageMeta: null,
        }
    }
    componentDidMount() {
        const params = {
            pageNum: 1,
            pageSize: 10
        };
        this.getData(params);
    }
    getData = async (params) => {
        params = {
            ...params,
            dataId: this.state.dataId,
            invoiceUuid: this.state.invoiceUuid,
        }
        const res: any = await agent.post('/web/verifier/invoice/record/queryRecordPage', params, this);
        if (res.er) {
            return;
        } else if (res.res) {
            this.setState({
                list: res.res.items,
                pageMeta: res.res.pageMeta,
            })
        }

    }
    onPageChange = (pageNum, pageSize) => {
        this.setState({
            pageMeta: {
                ...this.state.pageMeta,
                pageNum,
                pageSize
            }
        }, () => {
            this.onRefresh();
        });
    }
    onRefresh = () => {
        const params = {
            ...this.state.params,
            ...this.state.pageMeta,
        };
        this.getData(params);
    }
    render() {
        const { pageMeta, list } = this.state;
        return (
            <Modal
                title='复验记录'
                onCancel={this.props.onClose}
                visible={true}
                width={900}
                footer={null}
                bodyStyle={{ maxHeight: 500, overflow: 'auto' }}
            >
                {list &&
                    <Table
                        dataSource={list}
                        columns={this.columns}
                        scroll={{ x: 700 }}
                        pagination={false}
                    />
                }
                {pageMeta && <Pagination onChange={this.onPageChange} showTotal={(total, range) => `第 ${range[0]}-${range[1]} 条,  共有 ${total} 条`} style={{ padding: '16px 0', flex: 'none', background: 'white', textAlign: 'center' }} total={pageMeta.total} pageSize={pageMeta.pageSize} current={pageMeta.pageNum} showSizeChanger={true} />}
            </Modal>);
    }

}