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

class MainBusinessLog extends Component{
    constructor(props) {
        super(props);
        this.state={
            loading: false,
            dataSource:[],
            columns:[
                {
                    title: '序号',
                    dataIndex: 'id',
                    key: 'id',
                },
                {
                    title: '内容',
                    dataIndex: 'remarks',
                    key: 'remarks',
                    width:500,
                    render: text => {
                        return (
                            <Tooltip title={text}>
                                <div style={{
                                    maxWidth:'500px',
                                    overflow:'hidden',
                                    textOverflow: "ellipsis",
                                    whiteSpace:'nowrap',
                                }}>{text}</div>
                            </Tooltip>
                        )
                    }
                },
                {
                    title: '时间',
                    dataIndex: 'createTimes',
                    key: 'createTimes',
                },
            ],
        }
    }

    loadData() {
        this.setState({
            loading: true,
        });
        $.ajax({
            method: 'get',
            dataType: "json",
            crossDomain: false,
            url: globalConfig.context + '/api/admin/customer/userDateLogList',
            data:{
                uid:this.props.uid
            },
            success: function(data) {
                if(data.error.length === 0){
                    this.setState({
                        dataSource: data.data,
                    });
                }else{
                    message.warning(data.error[0].message);
                }
            }.bind(this),
        }).always(function() {
            this.setState({
                loading: false
            });
        }.bind(this));
    }

    componentDidMount() {
        this.loadData();
    }

    render() {
        return (
            <Modal
                maskClosable={false}
                className="customeDetails"
                footer=""
                title="主营日志"
                width="800px"
                visible={this.props.visible}
                onOk={this.props.onCancel}
                onCancel={this.props.onCancel}
            >
                <div>
                    <Spin spinning={this.state.loading}>
                        <Table
                            size="middle"
                            columns={this.state.columns}
                            dataSource={this.state.dataSource}
                        />
                    </Spin>
                </div>
            </Modal>
        )
    }
}

export default MainBusinessLog;
