import React,{Component} from "react";
import {Button, message, Modal, Spin, Table, Tooltip} from "antd";
import {
    getSocialAttribute,
    getChannelAllocationStatus
} from "@/tools.js";
import {
    channelAllocationStatus
} from "@/dataDic.js";
import $ from "jquery/src/ajax";
import IntentionDetail from "./intentionDetail/intentionDetail";
class StatisticalDetails extends Component{
    constructor(props) {
        super(props);
        this.state={
            columns: [
                {
                    title: "客户名称",
                    dataIndex: "userName",
                    key: "userName",
                    width:250,
                    render: (text,record) => {
                        return (
                            
                              
                                  {record.recovery === 1 ? 
                                      回收
                                  
 : null}
                                  {text}
                              
                                
                            
                        );
                    },
                },
                {
                    title: "备注",
                    dataIndex: "remarks",
                    key: "remarks",
                    render: (text) => {
                        return (
                            
                                {text}
                            
                        )
                    }
                }
            ],
            dataSource:[],
            pagination: {
                defaultCurrent: 1,
                defaultPageSize: 10,
                showQuickJumper: true,
                pageSize: 10,
                onChange: function (page) {
                    this.loadData(page);
                }.bind(this),
                showTotal: function (total) {
                    return "共" + total + "条数据";
                },
            },
            pageNo:1,
            listLoading:false,
            categoryArr:[],
        }
        this.tableRowClick = this.tableRowClick.bind(this);
        this.category = this.category.bind(this);
        this.detailCloseDesc = this.detailCloseDesc.bind(this);
        this.loadData = this.loadData.bind(this);
    }
    tableRowClick(record) {
        this.category();
        this.setState({
            rowData:record,
            modalVisible: true,
            basicState: true,
            contactState: true,
            modalName: record.userName
        })
    }
    componentWillReceiveProps (nextProps){
        if(nextProps.visible){
            this.loadData(1,nextProps);
        }
    }
    loadData(pageNo = 1,nextProps=this.props) {
        this.setState({
            listLoading: true,
            selectedRows: [],
            selectedRowKeys: [],
        });
        $.ajax({
            method: "post",
            dataType: "json",
            crossDomain: false,
            url: globalConfig.context + '/api/admin/customer/listChannelCustomer',
            data: {
                pageNo: pageNo || 1,
                pageSize: this.state.pagination.pageSize,
                type:nextProps.type,                     // 0营销员 1渠道专员 2营销总监 3营销经理 4释放 5未分配 6已分配 7已签单
                aid:nextProps.aid
            },
            success: function (data) {
                let theArr = [];
                if (data.error.length > 0) {
                    message.warning(data.error[0].message);
                } else {
                    if(data.data.list.length === 0 && pageNo !== 1){
                        this.loadData(pageNo - 1)
                    }else{
                        for (let i = 0; i < data.data.list.length; i++) {
                            let thisdata = data.data.list[i];
                            let diqu =
                                (thisdata.province == null ? "" : thisdata.province) +
                                (thisdata.city == null ? "" : "-" + thisdata.city) +
                                (thisdata.area == null ? "" : "-" + thisdata.area);
                            thisdata.key = i;
                            thisdata.id = thisdata.uid;
                            thisdata.lastFollowTime = thisdata.lastFollowTime &&
                                thisdata.lastFollowTime.split(" ")[0];
                            thisdata.transferTime= thisdata.transferTime && thisdata.transferTime.split(" ")[0];
                            thisdata.surplusFollowTime = thisdata.surplusFollowTime && thisdata.surplusFollowTime.split(" ")[0];
                            thisdata.surplusSignTime = thisdata.surplusSignTime && thisdata.surplusSignTime.split(" ")[0];
                            thisdata.locationProvince = diqu;
                            theArr.push(thisdata);
                        }
                        this.state.pagination.current = data.data.pageNo;
                        this.state.pagination.total = data.data.totalCount;
                        this.setState({
                            pageNo: data.data.pageNo,
                            dataSource: theArr,
                            pagination: this.state.pagination,
                        })
                    }
                }
            }.bind(this),
        }).always(
            function () {
                this.setState({
                    listLoading: false,
                });
            }.bind(this)
        );
    }
    category() {
        $.ajax({
            method: "get",
            dataType: "json",
            crossDomain: false,
            url: globalConfig.context + "/api/admin/Varieties/getSuperList",
            data: {},
            success: function (data) {
                let thedata = data.data;
                let theArr = [];
                if (!thedata) {
                    if (data.error && data.error.length) {
                        message.warning(data.error[0].message);
                    }
                    thedata = {};
                } else {
                    thedata.map(function (item, index) {
                        theArr.push({
                            value: item.id,
                            key: item.cname,
                        });
                    });
                }
                this.setState({
                    categoryArr: theArr,
                });
            }.bind(this),
        });
    }
    detailCloseDesc(){
        this.setState({
            rowData:'',
            modalVisible: false,
            basicState: false,
            contactState: false,
            modalName: '',
        },()=>{
            this.loadData(this.state.pageNo);
        })
    }
    render() {
        return (
            
                
                    
                
                
            
        );
    }
}
export default StatisticalDetails;