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 = {};
	var startTime = $('#startTime').datetimebox("getValue");
	var endTime = $('#endTime').datetimebox("getValue");
	sParam.LIKEledmc = $('#LIKEledmc').textbox("getValue");
	sParam.TaskMachine="0";
	if($('#TaskMachine').is(':checked')){
		sParam.TaskMachine="1";
		$("#taskDiv").show();
		$("#notaskDiv").hide();
	}else{
		$("#taskDiv").hide();
		$("#notaskDiv").show();
	}

	var tableparam = "";
	if(!(startTime==null||startTime==""||startTime==undefined)){
		tableparam += " AND statusuptime > '" +startTime + "'";
	}
	if(!(endTime==null||endTime==""||endTime==undefined)){
		tableparam += " AND statusuptime < '" +endTime + "'";
	}
	sParam.tableparam = tableparam;

	return sParam;
}
//加载列表
function initGrid(){
	$("#taskDiv").show();
	$("#notaskDiv").hide();
	var toolbar = [{
		text	:	'查询',
		iconCls	:	'icon-search',
		handler	:	doSearch
	}];
	$('#tableGrid').datagrid({
		toolbar : toolbar,
		singleSelect:true,
		rownumbers:true,
		queryParams:getQueryParams(),
		url : 'nhywjtledydpglAction!listYwydpstatusinfoByPage.do',
		columns : [[
			{
				field: 'A',
				checkbox:'true',
				width:30
			},
			{field:'ledstatusid',title:'ledstatusid',hidden:true,width:120,
				formatter:function showClick(value,record,num){
					return "<a  href='javascript:void(0);' class='ahref' onclick='doUpdate("+num+")'>"+value+"</a>";
				}
			},
			{field:'xh',title:'编码',hidden:false,width:110},
			{field:'ledmc',title:'LED名称',hidden:false,width:120},
			{field:'ledbh',title:'LED编号',hidden:false,width:110},
			{field:'ydpstatus',title:'状态',hidden:true,width:60,
				formatter:function showClick(value,record,num){
					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 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;
					}
				}
			},
			{field:'statusuptime',title:'检测时间',hidden:false,width:125},
			{field:'xxx',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="lookdetail('+num+')"  group="" id=""><span class="l-btn-left"><span class="l-btn-text">详情</span></span></a>';
				}
			}
		]]
	});
	$('#tableNoTaskGrid').datagrid({
		toolbar : toolbar,
		singleSelect:true,
		rownumbers:true,
		queryParams:getQueryParams(),
		url : 'nhywjtledydpglAction!listYwydpstatusinfoByPage.do',
		columns : [[
			{
				field: 'A',
				checkbox:'true',
				width:30
			},
			{field:'xh',title:'xh',hidden:true,width:120,
				formatter:function showClick(value,record,num){
					return "<a  href='javascript:void(0);' class='ahref' onclick='doUpdate("+num+")'>"+value+"</a>";
				}
			},
			{field:'ledbh',title:'编号',hidden:false,width:120},
			{field:'ledmc',title:'信号灯名称',hidden:false,width:100},
			{field:'csmc',title:'是否启用',hidden:false,width:80}
		]]
	});
}

function lookdetail(index) {
	var selRows = $('#tableGrid').datagrid('getRows')[index];
	windowId = top.$.createWin({
		title : '查看详情',
		width : 800,
		height : 500,
		data : selRows,
		url : sysUrl+"/yw/patroltask/ydptaskhistory/ywydpstatusinfo_show.jsp"
	});
}

//查询
function doSearch(){
	if($('#TaskMachine').is(':checked')){
		$('#tableGrid').datagrid('load',getQueryParams());
	}else{
		$('#tableNoTaskGrid').datagrid('load',getQueryParams());
	}
}

