import React from "react";
import {Spin, Table, message, Modal, Tooltip} from "antd";
import $ from "jquery/src/ajax";
import moment from 'moment';

const ReminderLog = React.createClass({
    getInitialState() {
        return {
            loading: false,
            colunmn: [
                {
                    title: "序号",
                    dataIndex: "id",
                    key: "id",
                },
                {
                    title: "内容",
                    dataIndex: "content",
                    key: "content",
                    width:800,
                    render: (text) => {
                        return (
                            <Tooltip placement="topLeft" title={text}>
                                <div style={{
                                    maxWidth:'800px',
                                    overflow:'hidden',
                                    textOverflow: "ellipsis",
                                    whiteSpace:'nowrap',
                                }}>{text}</div>
                            </Tooltip>
                        )
                    }
                },
                {
                    title: "时间",
                    dataIndex: "createTime",
                    key: "createTime",
                    render: (text) => (
                        moment(text).format('YYYY-MM-DD HH:mm:ss')
                    )
                }
            ]
        };
    },
    loadData() {
        this.setState({
            loading: true
        });
        $.ajax({
            method: "get",
            dataType: "json",
            crossDomain: false,
            url: globalConfig.context + "/api/admin/patentNew/selectPatentNewLog",
            data: {
                id: this.props.id,
            },
            success: function (data) {
                if (data.error.length || data.data.list == "") {
                    if (data.error && data.error.length) {
                        message.warning(data.error[0].message);
                    }
                } else {
                    this.setState({
                        dataSource: data.data,
                    });
                }
            }.bind(this),
        }).always(
            function () {
                this.setState({
                    loading: false,
                });
            }.bind(this)
        );

    },
    componentWillMount() {
        this.loadData()
    },
    render() {
        return (
            <Modal
                style={{ position: "relative" }}
                title='日志'
                visible={this.props.visible}
                onCancel={this.props.cancel}
                footer={null}
                width={1000}
                destroyOnClose={true}
            >
                <Spin spinning={this.state.loading} >
                    <Table
                        columns={this.state.colunmn}
                        dataSource={this.state.dataSource}
                        pagination={false}
                        scroll={{ x: "max-content", y: 0 }}
                        bordered
                        size="small"
                    />
                </Spin>
            </Modal>
        );
    },
});

export default ReminderLog;
