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

class ProjectLog extends Component{
    constructor(props) {
        super(props);
        this.state={
            loading:false,
            dataSource:[],
            colunmn:[
                {
                    title: "序号",
                    dataIndex: "key",
                    key: "key",
                },
                // {
                //     title: "客户姓名",
                //     dataIndex: "key",
                //     key: "key",
                // },
                // {
                //     title: "项目名称",
                //     dataIndex: "key",
                //     key: "key",
                // },
                {
                    title: "操作人",
                    dataIndex: "aName",
                    key: "aName",
                },
                {
                    title: "接收人",
                    dataIndex: "receiveName",
                    key: "receiveName",
                },
                {
                    title: "操作类型",
                    dataIndex: "statusName",
                    key: "statusName",
                },
                {
                    title: "操作时间",
                    dataIndex: "createTimes",
                    key: "createTimes",
                },
            ]
        }
        this.loadData = this.loadData.bind(this);
    }

    loadData() {
        this.setState({
            loading: true
        });
        $.ajax({
            method: "get",
            dataType: "json",
            crossDomain: false,
            url: globalConfig.context + "/api/admin/orderProject/taskAttributionLog",
            data: {
                tid: this.props.projectLogId,
            },
            success: function (data) {
                if (data.error && data.error.length) {
                    message.warning(data.error[0].message);
                }else{
                    let theArr = [];
                    for (let i = 0; i < data.data.length; i++) {
                        let thisdata = data.data[i];
                        thisdata.key = i+1 ;
                        theArr.push(thisdata)
                    }
                    this.setState({
                        dataSource: theArr,
                    })
                }
            }.bind(this),
        }).always(
            function () {
                this.setState({
                    loading: false,
                });
            }.bind(this)
        );

    }

    componentDidMount() {
        this.loadData();
    }

    render() {
        return (
            <Modal
                style={{ position: "relative" }}
                title="项目日志"
                visible={this.props.visible}
                onCancel={this.props.onCancel}
                footer={null}
                width={800}
                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 ProjectLog;
