(function(){
    X.pageLogic['grouptable'] = {
        init : function(parms){
            var me = this;
            this.parms = parms;
            this.callback = parms.callback;
            var dataArr = parms.extData;
            
            if(dataArr.eventView.timeParticleSize != "P1M" && dataArr.eventView.timeParticleSize != "total" && dataArr.eventView.timeParticleSize != "P1W"){
                dataArr['eventView']['endTime'] = dataArr.time+" 23:59:59";
                dataArr['eventView']['startTime'] = dataArr.time+" 00:00:00";
            }
            
            if(dataArr.type == "retained"){
                var nname,pname
                if(dataArr.retentiontype == 0) {
                    nname = 'n';
                    pname = 'p';
                }else {
                    nname = 'n_outflow';
                    pname = 'p_outflow';
                }

                X.api("ck/retention_model_details","post",dataArr,function(d){
                    var tabledata=[];
                    for(let i in d['summary_values']){
                        var arr = {
                            date: i,
                            d0:d['summary_values'][i]['d0'],
                            data:[]
                        }
                        for(let j in d['summary_values'][i]["n"]){
                            var nrr = {
                                n:0,
                                p:0
                            }
                            nrr["n"] = d['summary_values'][i][nname][j];
                            nrr["p"] = d['summary_values'][i][pname][j]
                            arr['data'].push(nrr);
                        }
                        tabledata.push(arr)
                    }
                    $('.grouptable-title-box span').html(d.start_date);
                    X.laytpldata("#table-fenxi-th-group-dot",d.title,".table-fenxi-group-th");
                    X.laytpldata("#table-fenxi-retained-td-group-dot",tabledata,".table-fenxi-group-td");
    
                });
            }else {
                
                X.api("ck/scatter_model_details","post",dataArr,function(d){
                    d['tabletitle'] = $.extend(true,[],d['label']);
                    d['tabletitle'].unshift(d.biaotou,'全部用户');
                    var contnetdata =[];
                    for(let i in d.list){
                        var arrdata= [];
                        for(let j in d.list[i]['n']){
                            var n = d.list[i]['n'][j];
                            var p = d.list[i]['p'][j];
                            var arr = {
                                n: n,
                                p: p
                            }
                            arrdata.push(arr);
                        }
                        var drr = {
                            total : d.list[i]['total'],
                            first: i,
                            data: arrdata
                        }
                        contnetdata.push(drr);
                    }
                    // console.log(contnetdata);
                    $('.grouptable-title-box span').html(d.start_date);
                    X.laytpldata("#table-fenxi-th-group-dot",d.tabletitle,".table-fenxi-group-th");
                    X.laytpldata("#table-fenxi-td-group-dot",contnetdata,".table-fenxi-group-td");
    
                });
    
                $(document).off("click",'.grouptable-title-box img').on("click",'.grouptable-title-box img',function(){
                    dataArr.eventView['download'] = 1;
                    X.download("ck/scatter_model_details",dataArr,'分布分析')
                })
            }

            
           

        }
    };
})();