var windowid,proName = window.location.pathname.split("/")[1],sysUrl = "http://"+window.location.host+"/"+proName,toEdit;
var winId	= $.getUrlParam("winId");
var records = top.$("#"+winId).panel("options").data;
//var records = [];
//var date = new Date();
//var nowDate = date.getFullYear()+"-"+(date.getMonth()+1);
var flag=true;
$(function(){
	$("#title").text(records.areaname+" - 区域运维考核统计");
	$("#timeTJ").text("制表时间："+getCurrtentTime());
	initGrid();
	initHeader();
	
});
function initHeader(){
	$.ajax({
		type : 'post',
		dateType : 'json',
		url : 'ywcountvideoappraiseAction!getWeight.do',
		data : "",
		success : function(res){
			if(res){
				$("#zxl").text("("+res.onlineweight+")");
				$("#spwhl").text("("+res.videoweight+")");
				$("#lxwhl").text("("+res.recordweight+")");
				$("#jwdcjl").text("("+res.lalweight+")");
				$("#xfl").text("("+res.repairweight+")");
			}
		}
	});
}

//加载列表
function initGrid(){	
	showList();
}
//列表展示
function showList(page,rows){
	$("#searchGridListDiv").show();
	$("#searchGridPicDiv").hide();
	displayType = "list";
	if(page == undefined || page==null){       // 页码
		page = 1;
	} 
	if(rows == undefined || rows==null){       //每页10条
		rows = 10;
	} 
	records.page = page;			
	records.rows = rows;	
	$.ajax({
		type : 'post',
		dateType : 'json',
		url : 'ywcountvideoappraiseAction!regionAssessmentCountListByRegion.do',
		data : records,
		success : function(res){
			renderTable(res);
		}
	});
}


function showGraph(){
	$("#searchGridPicDiv").show();
	$("#searchGridListDiv").hide();
	$.ajax({
		type : 'post',
		dateType : 'json',
		url : 'ywcountvideoappraiseAction!regionAssessmentCountListByRegion.do',
		data : getQueryParams(),
		success : function(res){
			if(res && res.total>0){
				var x = [];
				var score = [];
				
				var rows = res.rows
				for(var i=0;i<rows.length-1;i++){
					x.push((rows[i].areaname==null?"":rows[i].areaname));
					score.push(rows[i].score);
				}
				var data={
						"title":"区域运维考核统计",
						xAxis: x,//["监控","NVR","服务器","应用系统"],
						"legend":[
						          {"name":"得分", "data":score,"color":"green"},
						          /*{"name":"无效经纬度数","data":invalidJWnum,"color":"blue"},
						          {"name":"经纬度缺失数","data":defectJWnum,"color":"gray"},
						          {"name":"经纬度完整数","data":completeJWnum,"color":"green"},*/
						          ]};
//				$('#searchGridStatics').datagrid({ toolbar : toolbar});
				EchartsBase.barChart({
					id:"searchGridGraph",
					data:data
				});
			}
		}
	});
	
}
function renderTable(res){
	var areaname = records.areaname==null?"-":records.areaname;
	var table = '';
	if(res && res.total>0){
		var rows = res.rows;
		for (var i=0 ; i<rows.length; i++) {
			table += '<tr>\
				<td>'+(i+1)+'</td>\
				<td>'+areaname+'</td>\
				<td>'+rows[i].videoname+'</td>\
				<td>'+rows[i].zxsc+'</td>\
				<td>'+rows[i].zxRate+'</td>\
				<td>'+rows[i].videoIntactRate+'</td>\
				<td>'+rows[i].recordIntactRate+'</td>\
				<td>'+rows[i].lalIntactRate+'</td>\
				<td>'+rows[i].jobIntactRate+'</td>\
				<td>'+rows[i].score+'</td>\
				<td>'+(i+1)+'</td>\
				<tr>'
		}
	}else{
		table += '<tr> <td colspan="11">未查询到数据</td> <tr>';
	}
	 

	$("#searchGridList").html(table);
	if(flag){
		$('#pp').pagination({
		    total:res.total,
		    showRefresh:true,
		    pageSize:10,
		    pageList:[2,10,20,30,50,100],
			onSelectPage:function(pageNumber, pageSize){
				$(this).pagination('loading');
				$(this).pagination('loaded');
				showList(pageNumber,pageSize)
			}
		});
		flag=false;
	}
}
function transStr2Int(str){
	if(str){
		return parseInt(str);
	}else{
		return 0;
	}
}
//导出
function doExport(){
	execExport();
}
// 调用后台
function execExport() {
	var downParam = JSON.stringify(getQueryParams());
	document.excelForm.action = 'ywcountvideoappraiseAction!exp_Ywcountvideoappraise.do?downParam='+downParam;
	document.excelForm.submit(); 
}
function getCurrtentTime(){
	var date = new Date();
	var year = date.getFullYear();
	var month = date.getMonth()+1;
	var day = date.getDate();
	var hour = date.getHours();
	var minute = date.getMinutes();
	var second = date.getSeconds();
	if(month<10){
		month = "0"+month;
	}
	if(day<10){
		day = "0"+day;
	}
	if(hour<10){
		hour = "0"+hour;
	}
	if(minute<10){
		minute = "0"+minute;
	}
	if(second<10){
		second = "0"+second;
	}
	console.log(year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second);
	return year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second; 
}