var windowId,proName = window.location.pathname.split("/")[1],sysUrl = "http://"+window.location.host+"/"+proName,toEdit;

$(function(){
	initDefault();	
});
//默认
function initDefault(){
	// 默认时间
	$("#startTime").datetimebox("setValue",$.getTodayStart(0,"00:00:00"));
	$("#endTime").datetimebox("setValue",$.getTodayEnd("23:59:59"));
	initGrid();
}
//查询条件
function getQueryParams(){
	var sParam = {};
	sParam.LIKEmachinename = $("#LIKExhdmc").textbox("getValue");
	sParam.startTime = $('#startTime').datetimebox("getValue");	
	sParam.endTime = $('#endTime').datetimebox("getValue");
	sParam.order = "order by qybh desc"
	return sParam;
}
//加载列表
function initGrid(){	
	var toolbar = [{
    	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:'qybh',title:'区域编号',hidden:false,width:120},
			{field:'qymc',title:'区域名称',hidden:false,width:120},
			{field:'lkh',title:'路口号',hidden:false,width:120},
			{field:'lkmc',title:'路口名称',hidden:false,width:120},
			{field:'create_time',title:'检测时间',hidden:false,width:125,
			     formatter:function(value,row,index){
					 if(value==null || value=='' || value=='null' || value===undefined) {
						return "";
					}
					 else {
						return new Date(value).format("yyyy-MM-dd hh:mm:ss");}
					}},
			{field:'state',title:'当前状态',hidden:false,width:60,
				formatter:function showClick(value,record,num){
					if(value==null || value=='' || value=='null' || value===undefined) {
						return "未知";
					}else if(value!=20){
						return "<div style='height:13px;width:13px;background-color:green;border-radius:50%;-moz-border-radius: 50%;-webkit-border-radius: 50%;margin:0 auto;'></div>";				
					}else{
						return "<div style='height:13px;width:13px;background-color:red;border-radius:50%;-moz-border-radius: 50%;-webkit-border-radius: 50%;margin:0 auto;'></div>";				
					}
				}	
			},
			{field:'machineid',title:'操作',hidden:false,width:70,
				formatter:function showClick(value,record,num){
					return '<a href="javascript:;" style="background: #67c23a;color:white;padding: 2px,5px;" class="l-btn l-btn-small" onclick="lookHistory('+num+')"  group="" id=""><span class="l-btn-left"><span class="l-btn-text">详情</span></span></a>';
				}
			}

		]]
	});
}

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

//查看历史记录
function lookHistory(index){
	var selRows = $('#tableGrid').datagrid('getRows')[index];
	windowId = top.$.createWin({
		title	: 	'历史详情',
		width	:  	800,
		height	: 	500, 
		data  :  selRows,
		url	:	sysUrl+"/yw/history/xhd/ywxhdhistorystate_show.jsp",
//		onClose : closeRecordVideo
	});
}
