//cc
(function(){
    X.pageLogic['dashboard'] = {
        init :function(){
            
            var me = this;
            
            var popid='';

            layui.element.init();

            var userinfo = localStorage.getItem('loginData');
            if(userinfo){
                X.DATA["userinfo"] = JSON.parse(userinfo);
                if(X.DATA["userinfo"]['name'] != 'root' ){
                    $(".projectinfo").hide();
                    $(".addproduct").hide();
                }
            }else {
                layer.msg('登录过期请重新登录！！！');
                X.gourl("login");
                return;
            }

            // 退出登录
            $(document).off('click','.sifnoutlogin').on('click','.sifnoutlogin',function(){
                window.localStorage.removeItem('loginData');
                X.gourl("login");
                location.reload();
            });

            // 项目列表
            // http://10.0.0.7:6789/
            X.api("project/","get",{},function(d){
                X.laytpldata('#layui-project-dot',d,'.layui-project-box');
                X.DATA['projectarr'] = d;
                X.DATA['projectid'] = X.DATA['projectid'] || d[0]["_id"];
                X.DATA["game"] = X.DATA["game"] || d[0]["game"];
                for(let i in d){
                    if(d[i]['game'] == X.DATA["game"]){
                        $(".projecttit").html(d[i]['name']);
                    }
                }
                $("#model-box").html("");
                me.freshMenu(X.DATA['projectid']);

                // X.template("toptab","analysis-zhanwei",d);

            });

            // $(".username").html(X.DATA.userinfo.name);

            // 选择项目
            $(document).off('click','.selectproject').on('click','.selectproject',function(){
                var id = $(this).attr("data-id");
                var game = $(this).attr("data-game");
                $(".projecttit").html($(this).html());
                X.DATA['dashboard_id'] = "";
                X.DATA['projectid'] = id;
                X.DATA["game"] = game;
                //侧边栏数据渲染
                me.freshMenu(id);

                X.pagename(function(d){
                    console.log(d);
                    //当页面不在看板页面时选择项目后会自动调到看板页面
                    if(d != 'dashboard'){
                        $("#data_board a").click();
                    }
                });

                // X.pageLogic.dashboard.freshMenu(id);
            });

            //a标签点击跳转事件
            $(document).off('click','.layui-nav-child a').on('click','.layui-nav-child a',function(){
                var url = $(this).attr("data-url");
                X.gourl(url);
            });

            //空间单击事件
            $(document).off("click",'.xiangmukongjian').on('click','.xiangmukongjian',function(){
                var authority = $(this).attr("data-authority");
                X.DATA.authority = authority;
                if(authority == "rw"){
                    $(".baobiao").show();
                }else{
                    $(".baobiao").hide();
                }
                // console.log(authority);
            });

            // 修改面板名
            $(document).off('click','.layui-left-dd').on('click','.layui-left-dd',function(){
                var authority = $(this).attr("data-authority");
                X.DATA.authority = authority;
                if(authority == "rw" || X.DATA['userinfo']['userid'] == $(this).attr("data-userid")){
                    $(".baobiao").show();
                }else{
                    $(".baobiao").hide();
                }
                $(".tab-tit-box .tab-tit").html($(this).find("span").html());
                setHashParms("menu",$(this).attr('data-id'));
                // $("#model-box").html("");
                // X.DATA['dashboard_id'] = $(this).attr('data-id'); //看板id
                // 获取报表数据
                // me.gettabledata();
            });

            // 渲染添加按钮侧边栏下拉框
            X.laydropdown("#chuangjian",X.DATA.createsidebar,function(d){
                if(d.url){
                    X.open({
                        type: 1,
                        title: false,
                        closeBtn: 0,
                        shadeClose: true,
                        url: d.url
                    })
                }
              this.elem.val(d.title);
            });

            // 时间控件渲染
            X.daterender(".tab-right-box .time",function(start, end, label) {
                var startTime = start.format('YYYY-MM-DD')+ " "+ "00:00:00";
                var endTime = end.format('YYYY-MM-DD')+ " "+ "23:59:59";
                // console.log(startTime);
                // console.log(endTime);
            });

            // X.echartsdata("#charts");

            //更新时间按钮
            $(".updatetime").click(function(){
                X['DATA']['screenlist'] = [];
                X.updatatime(".updatetime");
                me.gettabledata();
            });

            //添加项目
            $(document).off('click','.addproduct').on("click",".addproduct",function(){
                X.open({
                    type: 1,
                    title: false,
                    closeBtn: 0,
                    shadeClose: true,
                    skin: 'yourclass',
                    url: 'addproduct',
                    callback :function(d){
                        X.api("project/","get",{},function(d){
                            X.laytpldata('#layui-project-dot',d,'.layui-project-box');
                            X.DATA['projectarr'] = d;
                            X.DATA['projectid'] = X.DATA['projectid'] || d[0]["_id"];
                            X.DATA["game"] = X.DATA["game"] || d[0]["game"];
                            for(let i in d){
                                if(d[i]['game'] == X.DATA["game"]){
                                    $(".projecttit").html(d[i]['name']);
                                }
                            }
                            $("#model-box").html("");
                            me.freshMenu(X.DATA['projectid']);
                        })
                    }
                  })
            });

            //管理我创建的看板
            $(document).off('click','.sousuo-box .kbglkanbanbtn').on("click",".sousuo-box .kbglkanbanbtn",function(){
                X.open({
                    type: 1,
                    title: false,
                    closeBtn: 0,
                    shadeClose: true,
                    offset: 'lt',
                    anim: 5,
                    skin: 'yourclass',
                    url: 'adminkanban'
                })
            });

            //渲染时区下拉框
            layui.dropdown.render({
                elem: ".tab-tit-box .tab-shiqvshezhi"
                ,data: X.DATA.timezone
                ,click: function(obj){
                    $(".tab-tit-box .tab-shiqvshezhi").html(obj.title);

                    //数据更新
                //   this.elem.val(obj.title);
                }
            });

            //筛选
            $(document).off('click','.tab-right-box .tjsx').on("click",".tab-right-box .tjsx",function(){

                // X.open({
                //     type: 1,
                //     title: false,
                //     closeBtn: 0,
                //     shadeClose: true,
                //     skin: 'yourclass',
                //     url: 'nodedetails'
                // })
                // layer.msg('该功能暂未开放');
                // return;
                // X.open({
                //     type: 1,
                //     title: false,
                //     closeBtn: 0,
                //     shade:0,
                //     shadeClose: false,
                //     offset: [120,270],
                //     url: "screen",
                //     extData : {}
                // })
            })

            // 单个表格筛选
            $(document).off('click','.tishi-tjsx').on('click','.tishi-tjsx',function(){
                var obj = $(this);
                var id = obj.attr('data-id');
                var screenlist;
                var cat = obj.attr('data-cat');
                var modelsize = obj.attr('data-modelsize');
                var modeltype = obj.attr('data-modeltype');
                var name = obj.attr('data-name');

                var timetxtid = 'times'+id;
                var timetxt = $("#"+timetxtid).html();
                var timetxtarr = timetxt.split(" - ");
                var startTime = timetxtarr[0] + " "+ "00:00:00";
                var endTime = timetxtarr[1]+ " "+ "23:59:59";

                for(let i in X.DATA['screenlist']){
                    if(id == X.DATA['screenlist'][i]['id']){
                        screenlist = X.DATA['screenlist'][i];
                    }
                }

                X.open({
                    type: 1,
                    title: false,
                    closeBtn: 0,
                    // shade:0,
                    shadeClose: true,
                    offset: [120,270],
                    url: "screen",
                    extData : screenlist,
                    callback : function(d){
                        d['startTime'] = startTime;
                        d['endTime']=endTime;
                        d['id'] = id;
                        var dataArr = {
                            report_id : id,
                            ext_filter : d
                        }
                        X.DATA['screenlist'].push(d);

                        for(let i in X.DATA['screenlist']){
                            var cardid = "model"+X.DATA['screenlist'][i]['id'];
                            $("#"+cardid+" .shaixjeiguo").show();
                        }

                        X.api("ck/"+ cat +"_model","post",dataArr,function(vals){
                            if(vals == '查无数据'){
                                layer.msg('筛选条件无数据');
                                return;
                            }
                            var report_id = [];
                            report_id.push(id);

                            X.api('report/read_report','post',{project_id:X.DATA['projectid'],report_id:report_id,dashboard_id:X.DATA.dashboard_id},function(q){
                                var bbsetdata = {
                                    graph_size:modelsize,
                                    graph_type:modeltype,
                                    model:cat,
                                    name:name,
                                    report_id:id,
                                    modelswitch:q[0].show_config.modelswitch,
                                    ascending:q[0].show_config.ascending
                                }
                                var modeldata = X.pageLogic['dashboard'].modeldata(bbsetdata,vals);
                                //渲染模板和数据
                                X.template("modeltable",'conent-box'+modeldata[0]['id'],modeldata[0],function(){
                                    X.pageLogic['dashboard'].morefeatures(modeldata[0]);
                                });
                            })
                        })
                    }
                })
            });

            $(document).off('click','.shaixjeiguo').on('click','.shaixjeiguo',function(){
                var id = $(this).attr('data-id');
                var filts
                for(let i in X.DATA.screenlist){
                    if(X.DATA.screenlist[i]['id'] == id){
                        filts = X.DATA.screenlist[i]['filts'];
                    }
                }
                var filtshtml = ''
                if(filts.length > 0){
                    for(let i in filts){
                        filtshtml+= filts[i]['columnDesc'] + filts[i]['comparator_name'] + filts[i]['strftv'] + '<br>'
                     }
                }   

                layui.layer.tips(filtshtml, '#sxjg'+id, {
                    tips: [4, '#475285']
                });
            })

            

            // 侧边栏搜索
            $('.sousuo-txt').bind('input propertychange', function() {
                var tit = $(this).val()
                var KanBanData = X.DATA['KanBanData'];
                var ProjectData = X.DATA['ProjectData'];
                if(tit != ''){
                    var ssKanBanData = [],
                        ssProjectData = []
                    for(let i in KanBanData){
                        if(KanBanData[i]['title'].indexOf(tit) != -1){
                            ssKanBanData.push(KanBanData[i]);
                        }else {
                            for(let j in KanBanData[i]['children']){
                                if(KanBanData[i]['children'][j]['title'].indexOf(tit) != -1 ){
                                    var arr = KanBanData[i];
                                    arr['children'].push(KanBanData[i]['children'][j]);
                                    ssKanBanData.push(arr);
                                }
                            }
                        }
                    }
                    for(let i in ProjectData){
                        for(let i in ProjectData){
                            if(ProjectData[i]['children'].length > 0){
                                if(ProjectData[i]['title'].indexOf(tit) != -1){
                                    ssProjectData.push(ProjectData[i]);
                                }else {
                                    var towProjectData = ProjectData[i]['children'];
                                    for(let j in towProjectData){
                                        if(towProjectData[j]['children'].length > 0){
                                            if(towProjectData[j]['children'].length > 0){
                                                var threProjectData = ProjectData[i]['children'][j]['children'];
                                                for(let z in threProjectData){
                                                    if(threProjectData[z]['title'].indexOf(tit) != -1){
                                                        var arr = ProjectData[i];
                                                        arr['children'] = towProjectData[j];
                                                        arr['children']['children'] = threProjectData[z];
                                                        // arr['children'].push( threProjectData[z] )
                                                        ssProjectData.push(arr);
                                                    }
                                                }
                                            }
                                        }else {
                                            if(towProjectData[j]['title'].indexOf(tit) != -1 ){
                                                var arr = ProjectData[i];
                                                arr['children'].push(towProjectData[j]);
                                                ssProjectData.push(arr);
                                            }
                                        }
    
                                    }
                                }
                            }else {
                                if(ProjectData[i]['title'].indexOf(tit) != -1){
                                    ssProjectData.push(ProjectData[i]);
                                }
                            }
                            
                        }
                    }
                    X.laytpldata('#mykanban-dot',ssKanBanData,'#mykanban');
                    X.laytpldata('#kongjian-dot',ssProjectData,'#kongjian');

                }else {
                    me.freshMenu(X.DATA['projectid']);
                }

            });
    
            // 用户搜索
            $(document).off('click','#search').on("click","#search",function(){
                // layer.msg('该功能暂未开放');
                // return;
                X.open({
                    type: 1,
                    title: false,
                    closeBtn: 0,
                    shadeClose: true,
                    skin: 'yourclass',
                    url: 'search'
                })
            });
            
            $(document).off('click','.tab-right-box .shezhi').on("click",".tab-right-box .shezhi",function(){
                layer.msg('该功能暂未开放');
                return;
                X.open({
                    type: 1,
                    title: false,
                    closeBtn: 0,
                    shadeClose: true,
                    offset: 'rt',
                    anim: 5,
                    skin: 'yourclass',
                    url: 'kanbanshezhi'
                })
            });
            // 保存报表列表
            $(document).off('click','.baobiao').on('click','.baobiao',function(){
                X.parametersopen({},'kanbanadmin','rt',function(){
                    me.gettabledata();
                })
            });

            //更新报表
            $(document).off('click','.model-gengx').on('click','.model-gengx',function(){    
                var id = $(this).attr('data-id');
                for(let i in X['DATA']['screenlist']){
                    if(X['DATA']['screenlist'][i]['id'] == id){
                        X['DATA']['screenlist'].splice(i,1);
                    }
                }
                X.api('dashboard/','post',{id:X.DATA['dashboard_id']},function(d){
                    // return;
                    X.pageLogic['dashboard'].fillmodeldata(d[id]);
    
                })

            });

            //报表跳转到详情s
            $(document).off('click','.gobaobiaoinfo').on('click','.gobaobiaoinfo',function(){
                var cat = $(this).attr('data-cat');
                var id = $(this).attr('data-id');
                var gourl='';
                if(cat == 'event'){
                    gourl = 'analysis';
                }else if(cat == 'retention'){
                    gourl = 'retained';
                    // layer.msg('暂未处理当前逻辑');
                    // return;
                }else if(cat == 'ltv'){
                    gourl = 'ltvmodel';
                    // layer.msg('暂未处理当前逻辑');
                    // return;
                }else if(cat == 'user_property'){
                    gourl = 'attribute';
                }else if(cat == 'scatter'){
                    gourl = 'distribution';
                }else if(cat == 'trace'){
                    gourl = 'routeanalysis';
                }
                
                X.gourl(gourl,'conetnt');//跳到对应的分析页面
                X.DATA[cat+'id'] = id;
            });

            //复制单个报表
            $(document).off('click','.model-fuzhi').on('click','.model-fuzhi',function(e) {
                e.stopPropagation();
                var id = $(this).attr('data-id')
                X.parametersopen(id,'copyreport',"auto",function(d) {
                    
                })
            });

            //删除空间
            $(document).off('click','.nav-space-bar').on('click','.nav-space-bar',function(e){
                e.stopPropagation();
                var id = $(this).attr('data-id');
                X.parametersopen(id,"kongjianshezhi",'auto',function(d){

                })
            })

            //删除看板
            $(document).off('click','.nav-action-bar').on('click','.nav-action-bar',function(e){
                e.stopPropagation();
                var obj = $(this);
                var offset = obj.offset();
                var innerHeight = window.innerHeight;
                var offsets = [ offset.top + 10,offset.left];

                if( innerHeight - offset.top < 150){
                    offsets = [ offset.top - 100,offset.left];
                }
                var id = $(this).attr('data-id');
                X.parametersopen(X.DATA.taboperationdata['kanban'],"dropdownlist2",offsets,function(d){
                    var arr = [];
                        arr.push(id);
                    if(d.click != 'del'){
                        X.parametersopen(arr,d.click,'auto',function(){
                            // me.updata(X.DATA['projectid']);
                            me.freshMenu(X.DATA['projectid']);
                        })
                    }else {
                        layer.confirm('确认删除选中的看板吗？该操作不可恢复', {
                            btn: ['取消','删除 '] //按钮
                          }, function(){
                            //取消
                            layer.close(layer.index);
                          }, function(){
                            //删除
                            X.api("dashboard/delete",'post',{ids:arr},function(d){
                                layer.msg('删除成功');
                                layer.close(layer.index);
                                X.pageLogic.dashboard.freshMenu(X.DATA.projectid);//刷新侧边栏
                                me.updata(X.DATA.projectid);//刷新数据
                            })
                        });
                    }
                   
                });
            });

            //留存分析模板特定留存流失按钮
            $(document).off('click',".kanben-retained-type").on('click',".kanben-retained-type",function(d){
                var obj = $(this);
                var offset = obj.offset();
                var id = obj.attr('data-id');
                var cat = obj.attr('data-cat');
                var modelsize = obj.attr('data-modelsize');
                var modeltype = obj.attr('data-modeltype');
                var name = obj.attr('data-name');
                X.parametersopen(X['DATA']['retentionlist'],'dropdownlist',[offset.top+obj.height(),offset.left],function(d){
                    obj.html(d.title);
                    var retentiontype = d.id;
                    var modelid = "retention"+id;
                    var reportid = [];
                    reportid.push(id);
                    // X.api('dashboard/','post',{id:X.DATA['dashboard_id']},function(val){
                    //     for(let i in val){
                    //         if(val[i]['report_id'] == id){
                    //             X.pageLogic['dashboard'].fillmodeldata(val[i],modelid,retentiontype);
                    //         }
                    //     }
                    // })
                   X.api("report/read_report",'post',{project_id:X.DATA['projectid'],report_id:reportid,dashboard_id:X.DATA.dashboard_id},function(q){
                       var query = {
                            eventView:q[0]['query']['eventView'],
                            events:q[0]['query']['events'],
                       };
                       //获取修改的时间
                        var dateid = "times"+id;
                        var time = $("#"+dateid).html();
                        var timearr = time.split(" ");
                        query['eventView']['startTime'] = timearr[0] + ' 00:00:00';
                        query['eventView']['endTime'] = timearr[2] + ' 23:59:59';
                        //获取修改的时间粒度
                        var timeParticleSizeid = "screenlist"+id;
                        var timeParticleSizename = $("#"+timeParticleSizeid).html();
                        var timeParticleSize;
                        X.granularityid(timeParticleSizename,function(d){
                            timeParticleSize = d;
                            if(cat == "retention"){
                                query['eventView']['unitNum'] = parseInt(timeParticleSize);
                            }else {
                                query['eventView']['timeParticleSize'] = timeParticleSize;
                            }
                            X.modelapi("ck/"+ cat +"_model","post",query,function(val){
                                if(JSON.stringify(val) != "{}"){
                                    var bbsetdata = {
                                        graph_size:modelsize,
                                        graph_type:modeltype,
                                        model:cat,
                                        name:name,
                                        report_id:id,
                                        query:query,
                                        modelswitch:q[0].show_config.modelswitch,
                                        ascending:q[0].show_config.ascending
                                    }
            
                                    var modeldata = X.pageLogic['dashboard'].modeldata(bbsetdata,val,retentiontype);
                                    //渲染模板和数据
                                    X.template("modeltable",'conent-box'+modeldata[0]['id'],modeldata[0],function(){
                                        X.pageLogic['dashboard'].morefeatures(modeldata[0]);
                                    });
    
                                }else {
                                    layer.msg('无数据!!!');
                                }
                                
                            })
                        })
                   })
                })
            });

            //报表时间粒度修改
            $(document).off('click','.model-screenlist').on('click','.model-screenlist',function(){
                var obj = $(this);
                var offset = obj.offset();
                
                var id = obj.attr('data-id');
                var cat = obj.attr('data-cat');
                var modelsize = obj.attr('data-modelsize');
                var modeltype = obj.attr('data-modeltype');
                var name = obj.attr('data-name');
                $("#sxjg"+id).hide();

                X.parametersopen(X['DATA']['companylist'][cat],'dropdownlist',[offset.top+obj.height(),offset.left],function(d){
                    // console.log(d);
                    obj.html(d.title);
                    var reportid = [];
                    reportid.push(id);
                    X.api('report/read_report','post',{project_id:X.DATA['projectid'],report_id:reportid,dashboard_id:X.DATA.dashboard_id},function(q){
                        var query = {
                            eventView:q[0]['query']['eventView'],
                            events:q[0]['query']['events'],
                        };
                        if(cat == "retention"){
                            query['eventView']['unitNum'] = parseInt(d.id);
                        }else {
                            query['eventView']['timeParticleSize'] = d.id;;
                        }
                        //时间获取修改后的时间
                        // 报表时间id
                        var dateid = "times"+id;
                        var time = $("#"+dateid).html();
                        var timearr = time.split(" ");
                        query['eventView']['startTime'] = timearr[0] + ' 00:00:00';
                        query['eventView']['endTime'] = timearr[2] + ' 23:59:59';
                        for(let i in X.DATA['screenlist']){
                            if(X.DATA['screenlist'][i]['id'] == id){
                                query['eventView']['filts'] = X.DATA['screenlist'][i]['filts']
                            }
                        }
                        // console.log(query);
                        X.modelapi("ck/"+ cat +"_model","post",query,function(vals){
                            var bbsetdata = {
                                graph_size:modelsize,
                                graph_type:modeltype,
                                model:cat,
                                name:name,
                                report_id:id,
                                query:q[0]['query'],
                                modelswitch:q[0].show_config.modelswitch,
                                ascending:q[0].show_config.ascending
                            }
                            // debugger;
                            var modeldata = X.pageLogic['dashboard'].modeldata(bbsetdata,vals);
                            //渲染模板和数据
                            X.template("modeltable",'conent-box'+modeldata[0]['id'],modeldata[0],function(){
                                X.pageLogic['dashboard'].morefeatures(modeldata[0]);
                            });
                        })
                    })

                })
            });

            $(document).off('click','.chart').on('click','.chart',function(){
                var dropdownlist = [
                    {title:'报表',id:'table'},
                    {title:'图形',id:'echarts'}
                ];
                var obj = $(this);
                var offset = obj.offset();
                var id = obj.attr('data-id');
                var modelid = id;
                var modelsize = obj.attr('data-modelsize');
                var modeltype = obj.attr('data-modeltype');
                var cat = obj.attr('data-cat');
                var name = obj.attr('data-name');
                X.parametersopen(dropdownlist,'dropdownlist',[offset.top+obj.height()+5,offset.left-150],function(d){

                    var data = {
                        report_id:id,
                        graph_size:modelsize,
                        graph_type:d.id,
                        model:cat,
                        name:name
                    }
                    X.api('dashboard/edit_show_report','post',{dashboard_id:X.DATA.dashboard_id,config:data},function(d){
                        X.api('dashboard/','post',{id:X.DATA['dashboard_id']},function(val){
                            for(let i in val){
                                if(val[i]['report_id'] == id){
                                    X.pageLogic['dashboard'].fillmodeldata(val[i],modelid);
                                }
                            }
                        })
                    })

                })
            });

            //点击时间获取到单击的报表id
            $(document).off('click','.model-times').on('click','.model-times',function(){
                var arr = {
                    id:$(this).attr('data-id'),
                    cat:$(this).attr('data-cat'),
                    modeltype:$(this).attr('data-modeltype'),
                    modelsize:$(this).attr('data-modelsize'),
                    name:$(this).attr('data-name'),
                }
                X.DATA.oclickarr =arr;
                // $("#sxjg"+$(this).attr('data-id')).hide();
            });

            //更多按钮配置下拉框
            $(document).off('click','.model-gengduo').on('click','.model-gengduo',function(){
                var obj = $(this);
                var offset = obj.offset();
                var id = obj.attr('data-id');
                // var modelid = 'model'+id;
                var modelsize = obj.attr('data-modelsize');
                var modeltype = obj.attr('data-modeltype');
                var cat = obj.attr('data-cat');
                var name = obj.attr('data-name');
                var modelswitch = obj.attr("data-modelswitch");
                var ascending = obj.attr("data-ascending");
                var avesumdata = obj.attr("data-avesumdata");
                var daydata = obj.attr("data-daydata");
                var reverseorder = obj.attr("data-reverseorder")

                var gengduolist
                if(X.DATA.authority == "rw"){
                    gengduolist = X['DATA']['gengduolist'];
                }else {
                    gengduolist = X['DATA']['gengduolist2'];
                }
                X.parametersopen(gengduolist,'dropdownlist',[offset.top+obj.height(),offset.left-170],function(d){
                    if(d.id == 'shezhi'){
                        var data = {
                            id : id,
                            modelsize : modelsize,
                            modeltype : modeltype,
                            modelswitch: modelswitch,
                            ascending:ascending,
                            daydata:daydata,
                            avesumdata:avesumdata,
                            cat: cat,
                            reverseorder:reverseorder
                        }
                        X.parametersopen(data,'setupbaobiao',"auto",function(d){
                            X.pageLogic['dashboard'].gettabledata();
                        })
                    }else if(d.id == 'export'){
                        var arr = [];
                        arr.push(id);
                        X.api('report/read_report','post',{project_id:X.DATA.projectid,report_id:arr},function(d){
                            var arr = {
                                "eventView": d[0]['query']['eventView'],
                                "events": d[0]['query']['events'],
                            }
                            var dateid = "times"+id;
                            var time = $("#"+dateid).html();
                            var timearr = time.split(" ");
                            arr['eventView']['startTime'] = timearr[0] + ' 00:00:00';
                            arr['eventView']['endTime'] = (timearr[2])? timearr[2] + ' 23:59:59' :  timearr[0] + ' 00:00:00';
                            if(d[0]['name'] && d[0]['name'] == '日充总额'){
                                var timearr = {
                                    start_time:  timearr[0] + ' 00:00:00',
                                    end_time: (timearr[2])? timearr[2] + ' 23:59:59' :  timearr[0] + ' 23:59:59'
                                }
                                X.download('ck/event_model_pay',timearr,name);
                            }else {
                                X.download('ck/'+ cat +'_model_export',arr,name);
                            }
                        })

                        
                    }else {
                        layer.confirm('确认移除['+ name + ']', {
                            btn: ['取消','删除 '] //按钮
                            }, function(){
                            //取消
                            layer.close(layer.index);
                            }, function(){
                            //删除
                            X.api('dashboard/del_report','post',{_id:X['DATA']['dashboard_id'],report_id:id},function(){
                                X.pageLogic['dashboard'].gettabledata();
                            });
                        });
                    }
                })
            });
            
        },

        // X.pageLogic.dashboard.freshMenu();
        freshMenu : function(id){
            //获取对应侧边栏
            X.api('project/kanban',"post",{"_id":id},function (d){
                X.DATA['KanBanData'] = d.kanban;
                X.DATA['ProjectData'] = d.spaces;
                if(d.spaces.length > 0){
                    X.DATA.authority = d.spaces[0]['authority'];
                    // for(let i in d.spaces){
                        if(d.spaces[0]['children'].length > 0){
                            
                            if(d.spaces[0]['authority'] == "rw" || d.spaces[0]['children'][0]['user_id'] == X.DATA['userinfo']['userid']){
                                $(".baobiao").show();
                                // continue;
                            }else{
                                $(".baobiao").hide();
                                // continue;
                            }
                        }
                    // }
                }
                
                for(let i in d.spaces){
                    if(d.spaces[i]['children'].length > 0){
                        if(X.DATA['dashboard_id'] == undefined || X.DATA['dashboard_id'] == ""){
                            for(let q in d.spaces){
                                for(let j in d.spaces[q]['children']){
                                    d.spaces[q]['children'][j]['onclick'] = 0;
                                    d.spaces[q]['children'][j]['sort'] = j
                                    if(j == 0){
                                        d.spaces[q]['children'][j]['onclick'] = 1;
                                    }
                                }
                            }
                            // console.log(d.spaces[i]['children'][0]['_id']);
                            var query = window.location.href;
                            var querys = query.split("=");
                            // debugger;
                            if(querys[2] == d.spaces[i]['children'][0]['_id']){
                                X.DATA['dashboard_id'] = querys[2];
                            }else {
                                setHashParms("menu",d.spaces[i]['children'][0]['_id']);
                            }
                            // $(".tab-tit-box .tab-tit").html(d.spaces[i]['children'][0]['name']);
                            // X.DATA['dashboard_id'] = d.spaces[i]['children'][0]['_id']; //看板id
                        }else {
                            for(let q in d.spaces){
                                for(let j in d.spaces[q]['children']){
                                    d.spaces[q]['children'][j]['onclick'] = 0;
                                    d.spaces[q]['children'][j]['sort'] = j
                                    if(d.spaces[q]['children'][j]['_id'] == X.DATA['dashboard_id']){
                                        d.spaces[q]['children'][j]['onclick'] = 1;
                                        $(".tab-tit-box .tab-tit").html(d.spaces[q]['children'][j]['name']);
                                    }
                                }
                            }
                        }
                        
                        $("#model-box").html("");
                        // 获取报表数据
                        X.pageLogic['dashboard'].gettabledata();
                        X.laytpldata('#mykanban-dot',d.kanban,'#mykanban');
                        X.laytpldata('#kongjian-dot',d.spaces,'#kongjian',function(){
                            // X.pageLogic.dashboard.sidebarslide();
                            // var sidebar = document.getElementById('sidebar-box'+d.spaces[0]['_id']);
                            var sidebar = document.getElementById('sidebar-boxhuadong');
                            new Sortable(sidebar, {
                                handle: '.tuodong', // handle class
                                animation: 150,
                                onUpdate:function(evt){
                                    var newIndex = evt.newIndex;
                                    var oldIndex = evt.oldIndex;
                                    // console.log(d.spaces);
                                    for(let j in d.spaces[i]['children']){
                                        if(j >= newIndex){
                                            d.spaces[i]['children'][j]['sort'] = Number(d.spaces[i]['children'][j]['sort'])  + Number(1);
                                        }
                                    }
                                    d.spaces[i]['children'][oldIndex]['sort'] = newIndex;
                                    var sortarr = [];
                                    for(let q in d.spaces[i]['children']){
                                        var arr = {
                                            dashboard_id: d.spaces[i]['children'][q]['_id'],
                                            sort: d.spaces[i]['children'][q]['sort']
                                        }
                                        sortarr.push(arr);
                                    }
                                    X.api('dashboard/sort','post',{sort:sortarr},function(d){
                                        if(d == 1){
                                            X.pageLogic.dashboard.freshMenu(X.DATA['projectid']);
                                        }
                                    })
                                }
                            });
                        });

                        break;//终止循环
                        
                    }else {
                        
                    }
                }
            });
        },

        // 侧边栏上下滑动 废弃
        sidebarslide:function(){
            $('.sidebarslide').sortable({
                connectWith: [".sidebarslide"],
                placeholder: "drop-area",
                distance: 15,
                tolerance:'pointer',
                opacity:0.8,
                revert:100,
                helper:'clone',
                appendTo:'body',
                start : function(event, ui){
                //   console.log(111,event);
                //   console.log(111,ui);
                },
                stop: function(event, ui){
                //   console.log(222,event);
                //   console.log(222,ui);
                },
        
            })
        },

        //填充看板数据
        //总体逻辑是：根据获取到的看板内容去先渲染放置的框，在根据不同分析模型处理对应的数据进行填充
        fillmodeldata:function(d,id,type){
            X.modelapi("ck/"+d['model']+"_model","post",{report_id:d['report_id']},function(val){
                if(typeof val  == 'string'){
                    $('#model-two-'+d['report_id']).html('<span class="woshujv">'+ val +'</span>');
                }else {
                    var eventdata = X.pageLogic['dashboard'].modeldata(d,val,type);
                    var data;
                    if(eventdata.length > 0){
                        for(var z in eventdata){
                            if(id){
                                //当有id时更新对应id看板内的内容
                                X.template("modeltype","model-two-"+id,eventdata[z],function(){ 
                                    // X.pageLogic['dashboard'].morefeatures(eventdata[z]);
                                    X.template("modeltable",'conent-box'+eventdata[z]['id'],eventdata[z],function(){ 
                                        X.pageLogic['dashboard'].morefeatures(eventdata[z]);
                                    });
                                });
                            }else {
                                //渲染模板和数据
                                X.template("modeltype",'model-two-'+eventdata[z]['id'],eventdata[z],function(){
                                    //X.pageLogic['dashboard'].morefeatures(eventdata[z]);
                                    X.template("modeltable",'conent-box'+eventdata[z]['id'],eventdata[z],function(){
                                        X.pageLogic['dashboard'].morefeatures(eventdata[z]);
                                    });
                                });
                            }
                        }
                    }

                }

            })
        },

        modeldata:function(d,val,type){
            var eventdata = [];
            if(d['query']){
                if(d.cat == "retention"){
                    var timeParticleSize =  d['query']['eventView']['unitNum'];
                }else {
                    var timeParticleSize =  d['query']['eventView']['timeParticleSize'];
                }
                
                var granularity = ''
                if(timeParticleSize){
                    X.granularity(timeParticleSize,function(d){
                        granularity = d;
                    });
                }
            }

            if(d['model'] == "event"){
                // 事件分析
                if(d['graph_size'] == 'small'){
                    X.eventsmall(val,function(data){//表格数据处理
                        data['name'] = d['name'];
                        data['modeltype'] = d['graph_type'];
                        data['id'] = d['report_id'];
                        data['modelsize'] = d['graph_size'];
                        data['cat'] = d['model'];
                        data['wow'] = Math.abs(val[0]['wow']);
                        data['chain_ratio'] = Math.abs(val[0]['chain_ratio']);
                        data['desc'] = d['desc'];
                        eventdata.push(data);
                    })
                }else {
                    if(d['graph_type'] == 'table'){
                        //表格样式
                        X.eventtable(val,function(data){//表格数据处理
                            data['name'] = d['name'];
                            data['modeltype'] = d['graph_type'];
                            data['id'] = d['report_id'];
                            data['modelsize'] = d['graph_size'];
                            data['cat'] = d['model'];
                            // data['date'] = startTimearr[0] + ' - ' + endTimearr[0];
                            data['timeParticleSize'] = granularity;
                            data['modelswitch'] = d['modelswitch'];
                            data['ascending'] = d['ascending'];
                            data['desc'] = d['desc'];
                            data['reverseorder']=d['reverseorder'];
                            eventdata.push(data);
                            // return;
                            if(d['modelswitch']){
                                var originaldata;//原始数据
                                originaldata= $.extend(true,[],eventdata[0]['condata']);
                                originaldata.unshift(eventdata[0]['titledata']);
                                var dataarr = [];
                                for(let i in originaldata[0]){
                                    var arr = [];
                                    dataarr.push(arr);
                                }
                                for(let i in originaldata){
                                    for(let j in originaldata[i]){
                                        dataarr[j].push(originaldata[i][j]);
                                    }
                                }
                                var titledata = dataarr[0];
                                var condata = dataarr.slice(1, dataarr.length);

                                eventdata[0]['titledata'] = titledata;
                                eventdata[0]['condata'] = condata;
                            }
                            //数据根据时间降序排列
                            if(d['ascending']){
                                // console.log()
                                // console.log(eventdata);
                                var condatalength =  eventdata[0]['condata'].length;
                                var condataascend=[];
                                for(var i = condatalength - 1; i >= 0; i--){
                                    condataascend.push(eventdata[0]['condata'][i]);
                                }
                                eventdata[0]['condata'] = condataascend;
                            }

                        })
                        
                    }else if(d['graph_type'] == 'echarts'){
                        //图形
                        X.eventchart(val,function(data){
                            data['name'] = d['name'];
                            data['modeltype'] = d['graph_type'];
                            data['id'] = d['report_id'];
                            data['modelsize'] = d['graph_size'];
                            data['cat'] = d['model'];
                            data['avesumdata']=d['avesumdata'];
                            data['daydata'] = d['daydata'];
                            // data['date'] = startTimearr[0] + ' - ' + endTimearr[0];
                            data['timeParticleSize'] = granularity;
                            data['desc'] = d['desc'];
                            eventdata.push(data);
                        })
                    }
                }

            } else if(d['model'] == "retention"){
                //留存分析
                if(type){
                    val['retentiontype'] = type;
                }else {
                    val['retentiontype'] = 0
                }
                if(d['graph_size'] == 'small'){

                }else {
                    if(d['graph_type'] == 'table'){
                        X.retentiontable(val,function(data){
                            data['name'] = d['name'];
                            data['modeltype'] = d['graph_type'];
                            data['id'] = d['report_id'];
                            data['modelsize'] = d['graph_size'];
                            data['cat'] = d['model'];
                            // data['date'] = startTimearr[0] + ' - ' + endTimearr[0];
                            data['timeParticleSize'] = granularity;
                            data['desc'] = d['desc'];
                            data['reverseorder']=d['reverseorder'];
                            eventdata.push(data);

                            if(d['ascending']){
                                var condatalength =  eventdata[0]['condata'].length;
                                var condataascend=[];
                                for(var i = condatalength - 1; i >= 0; i--){
                                    condataascend.push(eventdata[0]['condata'][i]);
                                }
                                eventdata[0]['condata'] = condataascend;
                            }
                        })

                    }else {
                        X.retentionchart(val,function(data){
                            data['name'] = d['name'];
                            data['modeltype'] = d['graph_type'];
                            data['id'] = d['report_id'];
                            data['modelsize'] = d['graph_size'];
                            data['cat'] = d['model'];
                            // data['date'] = startTimearr[0] + ' - ' + endTimearr[0];
                            data['timeParticleSize'] = granularity;
                            data['desc'] = d['desc'];
                            data['avesumdata']=d['avesumdata'];
                            data['daydata'] = d['daydata'];
                            eventdata.push(data);
                        })
                    }
                }
            }else if(d['model'] == 'ltv'){
                //ltv模型
                if(d['graph_type'] == 'table'){
                    X.ltvtable(val,function(data){
                        data['name'] = d['name'];
                        data['modeltype'] = d['graph_type'];
                        data['id'] = d['report_id'];
                        data['modelsize'] = d['graph_size'];
                        data['cat'] = d['model'];
                        // data['date'] = startTimearr[0] + ' - ' + endTimearr[0];
                        data['timeParticleSize'] = granularity;
                        data['desc'] = d['desc'];
                        data['reverseorder']=d['reverseorder'];
                        eventdata.push(data);

                        if(d['ascending']){
                            var condatalength =  eventdata[0]['condata'].length;
                            var condataascend=[];
                            for(var i = condatalength - 1; i >= 0; i--){
                                condataascend.push(eventdata[0]['condata'][i]);
                            }
                            eventdata[0]['condata'] = condataascend;
                        }
                    })
                }else {
                    X.ltvtable(val,function(data){
                        data['name'] = d['name'];
                        data['modeltype'] = d['graph_type'];
                        data['id'] = d['report_id'];
                        data['modelsize'] = d['graph_size'];
                        data['cat'] = d['model'];
                        // data['date'] = startTimearr[0] + ' - ' + endTimearr[0];
                        data['timeParticleSize'] = granularity;
                        data['desc'] = d['desc'];
                        data['avesumdata']=d['avesumdata'];
                        data['daydata'] = d['daydata'];
                        eventdata.push(data);
                    })
                }
            }else if(d['model'] == 'user_property'){
                // 属性分析
                if(d['graph_type'] == 'table'){
                    X.userpropertytable(val,function(data){
                        data['name'] = d['name'];
                        data['modeltype'] = d['graph_type'];
                        data['id'] = d['report_id'];
                        data['modelsize'] = d['graph_size'];
                        data['cat'] = d['model'];
                        data['date'] = "";
                        data['desc'] = d['desc'];
                        data['reverseorder']=d['reverseorder'];
                        eventdata.push(data);
                        if(d['ascending']){
                            var condatalength =  eventdata[0]['condata'].length;
                            var condataascend=[];
                            for(var i = condatalength - 1; i >= 0; i--){
                                condataascend.push(eventdata[0]['condata'][i]);
                            }
                            eventdata[0]['condata'] = condataascend;
                        }
                    })
                }else {
                    X.userpropertychart(val,function(data){
                        data['name'] = d['name'];
                        data['modeltype'] = d['graph_type'];
                        data['id'] = d['report_id'];
                        data['modelsize'] = d['graph_size'];
                        data['cat'] = d['model'];
                        data['date'] = "";
                        data['desc'] = d['desc'];
                        data['avesumdata']=d['avesumdata'];
                        data['daydata'] = d['daydata'];
                        eventdata.push(data);
                    })
                }
            }else if(d['model'] == 'scatter'){
                // 分布分析
                if(d['graph_type'] == "table"){
                    X.scattertable(val,function(data){
                        data['name'] = d['name'];
                        data['modeltype'] = d['graph_type'];
                        data['id'] = d['report_id'];
                        data['modelsize'] = d['graph_size'];
                        data['cat'] = d['model'];
                        data['desc'] = d['desc'];
                        data['reverseorder']=d['reverseorder'];
                        eventdata.push(data);
                        if(d['ascending']){
                            var condatalength =  eventdata[0]['condata'].length;
                            var condataascend=[];
                            for(var i = condatalength - 1; i >= 0; i--){
                                condataascend.push(eventdata[0]['condata'][i]);
                            }
                            eventdata[0]['condata'] = condataascend;
                        }
                    })
                }else{
                    X.scatterchart(val,function(data){
                        data['name'] = d['name'];
                        data['modeltype'] = d['graph_type'];
                        data['id'] = d['report_id'];
                        data['modelsize'] = d['graph_size'];
                        data['cat'] = d['model'];
                        data['desc'] = d['desc'];
                        data['avesumdata']=d['avesumdata'];
                        data['daydata'] = d['daydata'];
                        eventdata.push(data);
                    })
                }
            }else if(d['model'] == "trace"){

                var data = {};
                data['name'] = d['name'];
                data['modeltype'] = d['graph_type'];
                data['id'] = d['report_id'];
                data['modelsize'] = d['graph_size'];
                data['cat'] = d['model'];
                data['desc'] = d['desc'];
                data['avesumdata']=d['avesumdata'];
                data['daydata'] = d['daydata'];
                data['links'] = val['links'];
                data['nodes'] = val['nodes'];
                data['date'] = val['start_date'] + " - " + val['end_date'];
                eventdata.push(data);

            }
            eventdata[0]['authority'] = X.DATA.authority;
            return eventdata;
        },

        //画统计图和添加移入移出事件
        morefeatures:function(eventdata){

            //更多按钮配置下拉框
            // X.laydropdown(".model-gengduo",X['DATA']['gengduolist'],function(d){
            //     if(d.id == 'shezhi'){
            //         var data = {
            //             id : eventdata.id,
            //             modelsize : eventdata.modelsize,
            //             modeltype : eventdata.modeltype,
            //             modelswitch: eventdata.modelswitch
            //         }
            //         X.parametersopen(data,'setupbaobiao',"auto",function(d){
            //             X.pageLogic['dashboard'].gettabledata();
            //         })
            //     }else if(d.id == 'export'){
            //         X.download('ck/'+ eventdata.cat +'_model_export',{report_id:eventdata.id},eventdata.name);
            //     }else {

            //         layer.confirm('确认移除['+ eventdata.name + ']', {
            //             btn: ['取消','删除 '] //按钮
            //           }, function(){
            //             //取消
            //             layer.close(layer.index);
            //           }, function(){
            //             //删除
            //             X.api('dashboard/del_report','post',{_id:X['DATA']['dashboard_id'],report_id:eventdata.id},function(){
            //                 X.pageLogic['dashboard'].gettabledata();
            //             });
            //         });
            //     }
            // });

            //设置时间
            X.daterender(".model-times",function(start, end, label){
                // var id = $(this).attr('data-id');
                var oclickarr = X.DATA.oclickarr;
                var id = 'times'+oclickarr.id;
                var startTime = start.format('YYYY-MM-DD')+ " "+ "00:00:00";
                var endTime = end.format('YYYY-MM-DD')+ " "+ "23:59:59";
                $("#"+id).html(start.format('YYYY-MM-DD') + ' - ' + end.format('YYYY-MM-DD'));
                var reportid = [];
                reportid.push(oclickarr.id);
                X.api('report/read_report','post',{project_id:X.DATA['projectid'],report_id:reportid,dashboard_id:X.DATA.dashboard_id},function(q){
                    if(q.length > 0){
                        var query = {
                            eventView:q[0]['query']['eventView'],
                            events:q[0]['query']['events'],
                        };
                        query['eventView']['startTime'] = startTime;
                        query['eventView']['endTime'] = endTime;
    
                        var sameday = Date.parse(new Date()) / 1000; //当天时间戳
                    
                        var enddate = new Date(end.format('YYYY-MM-DD'));
                        var endmonth = Date.parse(enddate)/1000;
    
                        var startdate = new Date(start.format('YYYY-MM-DD'));
                        var startmonth = Date.parse(startdate)/1000;
                        query['eventView']['e_days'] = parseInt((sameday - endmonth)/86400);
                        query['eventView']['s_days'] = parseInt((sameday - startmonth)/86400);

                        if(q[0]['cat'] != "trace"){
                             // 获取选择后的时间粒度
                        var timeParticleSizeid = "screenlist"+oclickarr.id;
                        var timeParticleSizename = $("#"+timeParticleSizeid).html();
                        var timeParticleSize;
                        X.granularityid(timeParticleSizename,function(d){
                            timeParticleSize = d;
                            if(oclickarr.cat == "retention" || oclickarr.cat == "scatter"){
                                query['eventView']['unitNum'] = parseInt(timeParticleSize);
                            }else {
                                query['eventView']['timeParticleSize'] = timeParticleSize;
                            }
                            // query['eventView']['timeParticleSize'] = timeParticleSize;
                            for(let i in X.DATA['screenlist']){
                                if(X.DATA['screenlist'][i]['id'] == oclickarr.id){
                                    query['eventView']['filts'] = X.DATA['screenlist'][i]['filts']
                                }
                            }
                            X.api("ck/"+ oclickarr.cat +"_model","post",query,function(val){
                                if(JSON.stringify(val) != "{}" && JSON.stringify(val) != "[]"){
                                    var bbsetdata = {
                                        graph_size:oclickarr['modelsize'],
                                        graph_type:oclickarr['modeltype'],
                                        model:oclickarr['cat'],
                                        name:oclickarr['name'],
                                        report_id:oclickarr['id'],
                                        query:query,
                                        modelswitch:q[0].show_config.modelswitch,
                                        ascending:q[0].show_config.ascending
                                    }
            
                                    var modeldata = X.pageLogic['dashboard'].modeldata(bbsetdata,val);
                                    //渲染模板和数据
                                    X.template("modeltable",'conent-box'+modeldata[0]['id'],modeldata[0],function(){
                                        X.pageLogic['dashboard'].morefeatures(modeldata[0]);
                                    });
    
                                }else {
                                    layer.msg('无数据!!!');
                                }
                                
                            })
                        });
                        }else {
                            X.api("ck/"+ oclickarr.cat +"_model","post",query,function(val){
                                if(JSON.stringify(val) != "{}" && JSON.stringify(val) != "[]"){
                                    var bbsetdata = {
                                        graph_size:oclickarr['modelsize'],
                                        graph_type:oclickarr['modeltype'],
                                        model:oclickarr['cat'],
                                        name:oclickarr['name'],
                                        report_id:oclickarr['id'],
                                        query:query,
                                        modelswitch:q[0].show_config.modelswitch,
                                        ascending:q[0].show_config.ascending
                                    }
            
                                    var modeldata = X.pageLogic['dashboard'].modeldata(bbsetdata,val);
                                    //渲染模板和数据
                                    X.template("modeltable",'conent-box'+modeldata[0]['id'],modeldata[0],function(){
                                        X.pageLogic['dashboard'].morefeatures(modeldata[0]);
                                    });
    
                                }else {
                                    layer.msg('无数据!!!');
                                }
                                
                            })
                        }
                       
                    }else {
                        layer.msg('无数据qqq');
                    }
                })
            });


            if(eventdata['modeltype'] == 'echarts' && eventdata['modelsize'] != 'small' ){
                var myChart = echarts.init(document.getElementById(eventdata['id']));
                if(eventdata['cat'] == 'user_property'){
                    var option = {
                        color: X.DATA.echartscolor,
                        tooltip: {
                            trigger: 'axis',
                            axisPointer: {
                                type: 'cross',
                                label: {
                                    backgroundColor: '#6a7985'
                                }
                            }
                        },
                        color: X.DATA.echartscolor,
                        legend: {
                            // data: eventdata['legendnamearr'],
                        },
                        grid: {
                            left: '2%',
                            right: '2%',
                            bottom: '2%',
                            top: '10%',
                            containLabel: true
                        },
                        xAxis: [
                            {
                                type: 'category',
                                axisTick: {show: false},
                                data: eventdata['xAxisData']
                            }
                        ],
                        yAxis: [
                            {
                                type: 'value'
                            }
                        ],
                        series: [{
                            data: eventdata['seriesData'],
                            type: 'bar',
                        
                        }]
                    };
                }else if(eventdata.cat == "trace"){ 


                    var colordata = X.DATA['echartscolor'];
                    var levelsdata = [];
                    for(let i in colordata){
                        var arr = {
                            depth: i,
                            itemStyle: {
                                color: '#3ea7fd'
                            },
                            lineStyle: {
                                color: '#eeeeee',
                                opacity: 0.8
                            }
                        };
                        levelsdata.push(arr);
                    }
                    console.log(eventdata);
                    option = {
                        title: {
                            // text: ''
                        },
                        tooltip: {
                            trigger: 'item',
                            triggerOn: 'mousemove'
                        },
                        series: [
                            {
                                type: 'sankey',
                                left: '1%',
                                right: '0%',
                                top: "5%",
                                data: eventdata.nodes,
                                links: eventdata.links,
                                nodeWidth: 100,
                                nodeGap: 10,
                                draggable:false,
                                nodeAlign: 'left',
                                label:{
                                    position:'',
                                },
                                emphasis: {
                                    focus: 'adjacency'
                                },
                                levels: levelsdata,
                                lineStyle: {
                                    curveness: 0.5
                                }
                            }
                        ]
                    };

                }else{
                    var option = {
                        color: X.DATA.echartscolor,
                        tooltip: {
                            trigger: 'axis',
                            axisPointer: {
                                type: 'cross',
                                label: {
                                    backgroundColor: '#6a7985'
                                }
                            },
                            formatter:function(params){
                                //鼠标移入图表自定义显示内容
                                var axisIndex = params[0]['axisIndex'];
                                if(eventdata['proid_name'] && eventdata['proid_name'].length > 0){
                                    var index = params[0]['dataIndex'];
                                    var money = eventdata['proid_money'][index];
                                    var name = eventdata['proid_name'][index];
                                    var html = name+'<br/>'+'次数：'+ params[axisIndex]['data']+"<br/>"+'总金额：'+money;
                                   
                                }else {
                                    var html = params[0]['axisValue']+'<br/>';
                                    for(let i in params){
                                        html+= params[i]['seriesName']+':'+ params[i]['value']+"<br/>"
                                    }
                                }    
                                return html;                   
                            }
                        },
                        legend: {
                            type:'scroll',
                            bottom:0,
                            data: eventdata['legenddata'],
                            selected:eventdata['selected']
                        },
                        grid: {
                            left: '2%',
                            right: '2%',
                            bottom: '10%',
                            top: '5%',
                            containLabel: true
                        },
                        xAxis: [
                            {
                                type: 'category',
                                axisTick: {show: false},
                                data: eventdata['xAxisData']
                            }
                        ],
                        yAxis: [
                            {
                                type: 'value'
                            }
                        ],
                        series: eventdata['seriesData']
                    };
                }
                
                myChart.setOption(option,true);
            };
            
        },

        //获取表格数据
        //先渲染外框大小位置和标题
        gettabledata:function(){
            if(X.DATA['dashboard_id'] && X.DATA['dashboard_id'] != ""){
                X.modelapi('dashboard/','post',{id:X.DATA['dashboard_id']},function(d){
                    X['DATA']['kanbanlist'] = d;
                    var modellist=[];
                    for(let i in d){
                        var arr = {
                            sort:d[i]['sort'],
                            report_id:d[i]['report_id']
                        }
                        modellist.push(arr);
                    }
                    modellist.sort( X.compare("sort") );
                    var num = 0;
                    $("#model-box").html("");//清空表格数据
                    for(let i in modellist){
                        for(let z in d){
                            if(modellist[i]['sort'] == d[z]['sort'] && modellist[i]['report_id'] == d[z]['report_id']){
                                //渲染模板和数据
                                X.laytpldata("#kanban-model-box-dot",d[z],null,function(html){
                                    $('#model-box').append(html);
                                    num ++;
                                    // X.pageLogic['dashboard'].fillmodeldata(d[z]);
                                });
                                //当外框和标题渲染完在渲染数据
                                if(num == Object.getOwnPropertyNames(d).length){
                                    for(let q in d){
                                        // console.log(d[q]);
                                        X.pageLogic['dashboard'].fillmodeldata(d[q]);
                                    }
                                }
                            }
                        }
                    }
               
                })
            }
        },

    }; 
})();
