import React,{Component} from "react";
import {Button, DatePicker, Icon, Input, message, Select, Spin, Table, Tabs, Tag, Tooltip} from "antd";
import {ChooseList} from "../../order/orderNew/chooseList";
import FollowUpDetails from './followUpDetails';
import CorrespondingDetails from './correspondingDetails';
import OrderItemStatus from '../../../../component/common/orderItemStatus';
import $ from "jquery";
import {ShowModal} from "@/tools";
import ShowModalDiv from "@/showModal.jsx";
import moment from "moment";
const {TabPane} = Tabs;
const { RangePicker } = DatePicker;
class FollowUp extends Component{
    constructor(props) {
        super(props);
        this.state={
            columns:[
                {
                    title: "合同编号",
                    dataIndex: "contractNo",
                    key: "contractNo",
                    width: 120,
                    fixed:'left',
                },
                {
                    title: "订单编号",
                    dataIndex: "orderNo",
                    key: "orderNo",
                    width: 140,
                    fixed:'left',
                },
                {
                    title: "状态",
                    dataIndex: "deleteSign",
                    key: "deleteSign",
                    width:80,
                    fixed:'left',
                    render: (text) => {
                        //0=正常, 1=作废, 2=锁定, 3=变更中
                        return 
                            
                        
                    }
                },
                {
                    title: "订单部门",
                    dataIndex: "depName",
                    key: "depName",
                    width: 160,
                    fixed:'left',
                },
                {
                    title: "客户名称",
                    dataIndex: "userName",
                    key: "userName",
                    width:150,
                    fixed:'left',
                    render: text => {
                        return (
                            
                                {text}
                            
                        )
                    }
                },
                {
                    title: "合同签订时间",
                    dataIndex: "signTimes",
                    key: "signTimes",
                },
                {
                    title: "下单时间",
                    dataIndex: "orderTimes",
                    key: "orderTimes",
                },
                {
                    title: "申报项目",
                    dataIndex: "projects",
                    key: "projects",
                    width: 80,
                    render: (text) => {
                        return (
                            
                                {text}
                            
                        )
                    }
                },
                {
                    title: "咨询师",
                    dataIndex: "consultants",
                    key: "consultants",
                    width: 80,
                    render: (text) => {
                        return (
                            
                                {text}
                            
                        )
                    }
                },
                {
                    title: "申报批次",
                    dataIndex: "declareBatchs",
                    key: "declareBatchs",
                    width: 80,
                    render: (text) => {
                        return (
                            
                                {text}
                            
                        )
                    }
                },
                {
                    title: "证书编号",
                    dataIndex: "certificationNos",
                    key: "certificationNos",
                    width: 80,
                    render: (text) => {
                        return (
                            
                                {text}
                            
                        )
                    }
                },
                {
                    title: "客服最新跟进",
                    dataIndex: "newTimes",
                    key: "newTimes",
                },
                {
                    title: "跟进客服",
                    dataIndex: "adminName",
                    key: "adminName",
                },
                {
                    title: "是否已添微信",
                    dataIndex: "addWechat",
                    key: "addWechat",
                    width: 100,
                    render: (text,record) => {
                        let str = text === 1 ? '是('+record.wechat+')' : text === 0 ? '否' : '';
                        return (
                            
                                {str}
                            
                        )
                    }
                },
                {
                    title: "续签情况",
                    dataIndex: "renewal",
                    key: "renewal",
                    width: 80,
                    render: (text,record) => {
                        let str = text === 0 ? '未联系上当前联系人' :
                            text === 1 ? '企业已签其他机构' :
                                text === 2 ? '企业自己申报' :
                                    text === 3 ? '企业不打算申报/注销' :
                                        text === 4 ? '待续签,未报价(客服维护中)' :
                                            text === 5 ? '待续签,已报价(客服维护中)' :
                                                text === 6 ? ('已续签/复审、续签时间、续签项目' + (record.renewalTimes ? '('+record.renewalTimes+')' : '')): ''
                        return (
                            
                                {str}
                            
                        )
                    }
                },
                {
                    title: "满意度(技术/业务)",
                    dataIndex: "techSatisfaction",
                    key: "techSatisfaction",
                    render: (text,record) => (
                        (
                            text === 0 ? '已投诉' :
                                text === 1 ? '不满意' :
                                    text === 2 ? '一般满意' :
                                        text === 3 ? '非常满意' : '无'
                        )
                        +'/'+
                        (record.businessSatisfaction === 0 ? '已投诉' :
                            record.businessSatisfaction === 1 ? '不满意' :
                                record.businessSatisfaction === 2 ? '一般满意' :
                                    record.businessSatisfaction === 3 ? '非常满意' : '无')
                    )
                },
                {
                    title: "备注",
                    dataIndex: "remarks",
                    key: "remarks",
                    width: 80,
                    render: (text) => {
                        return (
                            
                                {text}
                            
                        )
                    }
                },
                {
                    title: "操作",
                    dataIndex: "a",
                    key: "a",
                    width: 100,
                    render: (_,record) => {
                        if(record.projects){
                            let projectsArr = record.projects.split('/');
                            let consultantsArr = record.consultants.split('/');
                            let declareBatchsArr = record.declareBatchs.split('/');
                            let certificationNosArr = record.certificationNos.split('/');
                            let data = [];
                            for (let i in projectsArr){
                                data.push({
                                    project:projectsArr[i],
                                    consultant:consultantsArr[i],
                                    declareBatch:declareBatchsArr[i],
                                    certificationNo:certificationNosArr[i],
                                })
                            }
                            return (
                                
                            )
                        }
                    }
                },
            ],
            changeList:[],
            listLoading:false,
            page:1,
            pagination: {
                defaultCurrent: 1,
                defaultPageSize: 10,
                showQuickJumper: true,
                pageSize: 10,
                onChange: function (page) {
                    this.loadData(page);
                }.bind(this),
                showTotal: function (total) {
                    return "共" + total + "条数据";
                },
            },
            departmentArr:[],
            customerName:'',
            releaseDate:[],
            signTimes:[],
        }
        this.changeList = this.changeList.bind(this);
        this.loadData = this.loadData.bind(this);
        this.search = this.search.bind(this);
        this.reset = this.reset.bind(this);
        this.departmentList = this.departmentList.bind(this);
        this.download = this.download.bind(this);
    }
    componentDidMount() {
        this.departmentList();
        this.loadData();
    }
    search(){
        this.loadData();
    }
    reset(){
        this.setState({
            customerName:undefined,
            depId:undefined,
            addWechat:undefined,
            renewal:undefined,
            releaseDate:[],
            signTimes:[],
        },()=>{
            this.loadData();
        })
    }
    loadData(pageNo) {
        this.setState({
            listLoading: true,
        });
        $.ajax({
            method: "get",
            dataType: "json",
            crossDomain: false,
            url: globalConfig.context + "/api/admin/listOrderUseService",
            data: {
                pageNo: pageNo || 1,
                pageSize: this.state.pagination.pageSize,
                userName:this.state.customerName || undefined,
                depId:this.state.depId || undefined,
                addWechat:this.state.addWechat || undefined,
                renewal:this.state.renewal || undefined,
                startFollowTimes:this.state.releaseDate[0] || undefined,
                endFollowTimes:this.state.releaseDate[1] || undefined,
                startSignTimes:this.state.signTimes[0] || undefined,
                endSignTimes:this.state.signTimes[1] || undefined,
            },
            success: function (data) {
                ShowModal(this);
                let theArr = [];
                if (!data.data || !data.data.list) {
                    if (data.error && data.error.length) {
                        message.warning(data.error[0].message);
                    }
                } else {
                    for (let i = 0; i < data.data.list.length; i++) {
                        let thisdata = data.data.list[i];
                        theArr.push(thisdata);
                    }
                    this.state.pagination.current = data.data.pageNo;
                    this.state.pagination.total = data.data.totalCount;
                    if (data.data && data.data.list && !data.data.list.length) {
                        this.state.pagination.current = 0;
                        this.state.pagination.total = 0;
                    }
                    let obj = {
                        userName:this.state.customerName || undefined,
                        depId:this.state.depId || undefined,
                        addWechat:this.state.addWechat || undefined,
                        renewal:this.state.renewal || undefined,
                        startFollowTimes:this.state.releaseDate[0] || undefined,
                        endFollowTimes:this.state.releaseDate[1] || undefined,
                        startSignTimes:this.state.signTimes[0] || undefined,
                        endSignTimes:this.state.signTimes[1] || undefined,
                    }
                    let arr = Object.keys(obj);
                    let str = '?';
                    for(let i of arr){
                        if(obj[i]){
                            str+=i+'='+obj[i]+'&'
                        }
                    }
                    this.setState({
                        dataSource: theArr,
                        page: data.data.pageNo,
                        pagination: this.state.pagination,
                        downloadSrc:str,
                    });
                }
            }.bind(this),
        }).always(
            function () {
                this.setState({
                    listLoading: false,
                });
            }.bind(this)
        );
    }
    changeList(arr) {
        const newArr = [];
        this.state.columns.forEach(item => {
            arr.forEach(val => {
                if (val === item.title) {
                    newArr.push(item);
                }
            });
        });
        this.setState({
            changeList: newArr
        });
    }
    //部门
    departmentList() {
        $.ajax({
            method: "get",
            dataType: "json",
            crossDomain: false,
            url: globalConfig.context + "/api/admin/organization/selectSuperId",
            data: {},
            success: function (data) {
                let thedata = data.data;
                let theArr = [];
                if (!thedata) {
                    if (data.error && data.error.length) {
                        message.warning(data.error[0].message);
                    }
                } else {
                    thedata.map(function (item, index) {
                        theArr.push({
                            key: index,
                            name: item.name,
                            id: item.id,
                        });
                    });
                }
                this.setState({
                    departmentArr: theArr,
                });
            }.bind(this),
        }).always(
            function () {
            }.bind(this)
        );
    }
    download() {
        window.location.href =
            globalConfig.context +
            "/api/admin/userServiceExport" + this.state.downloadSrc
    }
    render() {
        return (