
function querySituationClick(){
    //每次点击前清空表格数据
    $(".table-tbody").empty('');
    var start_date = $("#start-time").val();
    var end_date = $("#end-time").val();
    if(start_date==null||start_date==''||start_date==undefined||end_date==null||end_date==''||end_date==undefined){
        tip("请选择起止日期");
                return ;
    }else{
        start_date += " 00:00:00";
        end_date += " 00:00:00";
    }
  
    var param = {
        "dept_id": $("#fsList").val(),
        "start_date": start_date,
        "end_date": end_date,
    }
    var url = "statistics/score/info";
    var strTbody='';
    post_common_service( url,param,function(data){
         
        for(i=0;i<data.length;i++){
           $(".table-tbody").append(gethtml(data[i],i));
             }          
        },function(error){
                return "" ;
   });
}


function initQuerySituation(){
    //默认初始化前一周查所有
    var endD = new Date();
    var now = new Date();
    var startD = new Date(now.getTime() - 7 * 24 * 3600 * 1000);
    var start_time = startD.getFullYear()+"-"+(startD.getMonth()+1)+"-"+startD.getDate(); 
    var end_time = endD.getFullYear()+"-"+(endD.getMonth()+1)+"-"+endD.getDate(); 
    //默认初始化时间页面回显
    $("#start-time").val(start_time);
    $("#end-time").val(end_time);
    var start_date = start_time+" 00:00:00"; 
    var end_date = end_time+" 00:00:00"; 
    
    var param = {
        "start_date": start_date,
        "end_date": end_date,
    }
    var url = "statistics/score/info";
    var strTbody='';
   
    post_common_service( url,param,function(data){
                
        for(i=0;i<data.length;i++){
           
       $(".table-tbody").append(gethtml(data[i],i));
        }  
               
            },function(error){
                return "" ;
     });
    
}

function gethtml(data,i){
    var strTbody = "";
    if(i==0 || i==7 || i==13){
        num = 1;
        var name = "";
        var rowspan = 0;
        if(i==0){
            name = "连云港";
            rowspan = 7;
        }else if(i==7){
            name = "盐城";
            rowspan = 6;
        }else if(i==13){
            name = "南通";
            rowspan = 8;
        }
                strTbody +="<tr><td rowspan="+rowspan+">"+name+"</td>";
                strTbody +="<td>"+num+"</td><td>"+data.name+"</td><td>"+filter(data.people_num,0)
                        +"</td><td>"+filter(data.checked_people_num,0)+"</td><td>"+filter(data.checked_num,0)
                        +"</td><td>"+(data.people_num-(data.score_fifteen+data.score_fifty+data.score_over_fifty))
                        +"</td><td>"+data.score_fifteen+"</td><td>"+data.score_fifty+"</td><td>"
                        +data.score_over_fifty+"</td><td>"+data.all_check_score+"</td><td>"
                        +filterByZeroHandle(filterJudge(data.all_check_score,data.checked_num),'0')+"</td><td>"
                        +filterByZeroHandle((1000-filterJudge(data.all_check_score,data.checked_num)),'1000')+"</td>";
                strTbody += "</tr>";
       }else{
                num ++;
            
                strTbody +="<tr>"
                strTbody +="<td>"+num+"</td><td>"+data.name+"</td><td>"+filter(data.people_num,'0')
                        +"</td><td>"+filter(data.checked_people_num,0)+"</td><td>"+filter(data.checked_num,'0')
                        +"</td><td>"+(data.people_num-(data.score_fifteen+data.score_fifty+data.score_over_fifty))
                        +"</td><td>"+data.score_fifteen+"</td><td>"+data.score_fifty+"</td><td>"
                        +data.score_over_fifty+"</td><td>"+data.all_check_score+"</td><td>"
                        +filterByZeroHandle(filterJudge(data.all_check_score,data.checked_num),'0')+"</td><td>"
                        +filterByZeroHandle((1000-filterJudge(data.all_check_score,data.checked_num)),'1000')+"</td>";
                strTbody+="</tr>";
            
      }
      return strTbody;
}

function filter(value , default_display_value){
        if(value!='' && value!=undefined ){
            return value ;
        }else if(default_display_value != undefined){
            return default_display_value ;
        }else{
            return "" ;
        }
}

/**
 * 过滤除数为0和保留二位小数时出现的0.00
 * @param {*} value 
 * @param {*} default_display_value 
 */
function filterByZeroHandle(value , default_display_value){
        if(isNaN(value)){
            return default_display_value ;
        }else{
            if((value+'').endsWith('.00')){
                return value.substring(0,value.length-3);
            }
            return value ;
        }
}

function filterJudge(num1,num2){
        if(num2==0){
            return 0;
        }else{
            return (num1/num2).toFixed(2);
        }
}

function exportExcel(){
    var start_date = $("#start-time").val();
    var end_date = $("#end-time").val();
    if( start_date=='' || end_date==''){
        tip("请选择起止日期");
        return ;
    }else{
        start_date += " 00:00:00";
        end_date += " 00:00:00";
    }
    window.open( getserveraddr() + "/file/score/info?start_date="+start_date+"&end_date="+end_date);
}






