import React from "react";
import {Spin, Table, message, Modal, Tooltip} from "antd";
import $ from "jquery/src/ajax";
const TransferRecords = React.createClass({
    getInitialState() {
        return {
            loading: false,
            colunmn: [
                {
                    title: "序号",
                    dataIndex: "id",
                    key: "id",
                },
                {
                    title: "客户姓名",
                    dataIndex: "userName",
                    key: "userName",
                },
                {
                    title: "原管理员",
                    dataIndex: "usedAName",
                    key: "usedAName",
                },
                {
                    title: "现管理员",
                    dataIndex: "newAName",
                    key: "newAName",
                },
                //  0录入 1 领取 2 转交私有客户 3转交业务 4 未跟进丢失(30) 5未签单丢失（270天）6释放  7转交签单客户  8渠道录入  9渠道客户分配  10 渠道客户转交 11渠道释放 12 回收 13离职转交
                {
                    title: "转交类型",
                    dataIndex: "type",
                    key: "type",
                    render: text => {
                        return (
                            <span>
                  {
                      text === 0 ? "录入":
                          text === 1 ? "领取":
                              text === 2 ? "转交私有客户":
                                  text === 3 ? "转交业务":
                                      text === 4 ? "未跟进丢失(30天)":
                                          text === 5 ? "未签单丢失（270天）" :
                                              text === 6 ? "移除" :
                                                  text === 7 ? "转交签单客户" :
                                                      text === 8 ? "渠道录入" :
                                                          text === 9 ? "渠道客户总监分配" :
                                                              text === 10 ? "渠道客户经理分配" :
                                                                  text === 11 ? "渠道释放" :
                                                                      text === 12 ? '回收' :
                                                                          text === 13 ? '离职转交' :""
                  }
                </span>
                        )
                    }
                },
                {
                    title: "项目名称",
                    dataIndex: "pName",
                    key: "pName",
                },
                {
                    title: "创建时间",
                    dataIndex: "createDate",
                    key: "createDate",
                },
                {
                    title: "备注",
                    dataIndex: "remarks",
                    key: "remarks",
                    render: (text) => {
                        return (
                            <Tooltip placement="topLeft" title={text}>
                                <div style={{
                                    maxWidth:'150px',
                                    overflow:'hidden',
                                    textOverflow: "ellipsis",
                                    whiteSpace:'nowrap',
                                }}>{text}</div>
                            </Tooltip>
                        )
                    }
                },
            ]
        };
    },
    loadData() {
        this.setState({
            loading: true
        });
        $.ajax({
            method: "get",
            dataType: "json",
            crossDomain: false,
            url: globalConfig.context + "/api/admin/customer/transferList",
            data: {
                uid: 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={this.props.type === 1 ? '转交记录' : this.props.type === 2 ? '回收记录' : '分配记录'}
                title='日志'
                visible={this.props.visible}
                onCancel={this.props.cancel}
                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 TransferRecords;
