var qybh = $.getUrlParam("qybh");
var lkh = $.getUrlParam("lkh");
$(function(){
//	console.log("历史记录：",currentstateid);
	initDefault();	
});
//默认
function initDefault(){
	// 设置默认时间
	$("#startTime").datetimebox("setValue",$.getTodayStart(0,"00:00:00"));
	$("#endTime").datetimebox("setValue",$.getTodayEnd("23:59:59"));
	initGrid();
}
//查询条件
function getQueryParams(){
	var sParam = {};
	sParam.qybh = qybh;
	sParam.lkh = lkh;
	sParam.tableparam="";
	var  startTime = $('#startTime').datetimebox("getValue");
	var endTime = $('#endTime').datetimebox("getValue");
	if(!(startTime==null||startTime==""||startTime==undefined)){
		sParam.tableparam += " AND time > '" +startTime + "'";
	}
	if(!(endTime==null||endTime==""||endTime==undefined)){
		sParam.tableparam += " AND time < '" +endTime + "'";
	}
	sParam.order = "order by time desc"
//	console.log("查询参数：",sParam);
	return sParam;
}
//加载列表
function initGrid(){	
	var toolbar = [/*{
    	text    :	'刷新',
        iconCls : 	'icon-refresh',
        handler : 	function(){location.reload(true);}
    },*/{
    	text	:	'查询',
        iconCls	:	'icon-search',
        handler	:	doSearch
    }];
	$('#tableGrid').datagrid({
		toolbar : toolbar,
		singleSelect:true,
		rownumbers:true,
		queryParams:getQueryParams(),
		url : 'nhywjtxhdglAction!listNhywjtxhdglHistoryStateByPage.do',
		columns : [[
			{field:'xhdmc',title:'信号灯名称',hidden:false,width:120},
			{field:'xhdbh',title:'信号灯编号',hidden:false,width:120},
			{field:'qymc',title:'区域名称',hidden:false,width:120},
			{field:'lkmc',title:'路口名称',hidden:false,width:120},
			{field:'time',title:'检测时间',hidden:false,width:125,
				formatter:function(value,row,index){return new Date(value).format("yyyy-MM-dd hh:mm:ss");}},
			{field:'mode',title:'当前状态',hidden:false,width:60,
				formatter:function showClick(value,record,num){
					// console.log("主机：",value,record);
 					if(value==20){
						return "<div style='height:13px;width:13px;background-color:#fe0000;border-radius:50%;-moz-border-radius: 50%;-webkit-border-radius: 50%;margin:0 auto;'></div>";
					}else{
						return value;
					}
				}
			}]]
	});
}

//查询
function doSearch(){	
	$('#tableGrid').datagrid('load',getQueryParams());
}

