var winId	= $.getUrlParam("winId");
var detetor = top.$("#"+winId).panel("options").data;

$(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.id = detetor.id;
	sParam.startTime = $('#startTime').datetimebox("getValue");	
	sParam.endTime = $('#endTime').datetimebox("getValue");
	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 : 'detectorAction!listDetectorhistorystateByPage.do',
		columns : [[
			{field:'name',title:'名称',hidden:false,width:120},
			{field:'bianma',title:'备案编码18位',hidden:false,width:120},
			{field:'detfrequency',title:'数据采集频率',hidden:false,width:60	},
			{field:'longitude',title:'经度',hidden:false,width:60},
			{field:'latitude',title:'纬度',hidden:false,width:60},
			{field:'roadname',title:'道路名称',hidden:false,width:110},
			{field:'roadid',title:'道路编码',hidden:false,width:120},
			{field:'bianma2',title:'设备私有编码',hidden:false,width:60},
			{field:'factoryid',title:'厂商编码',hidden:false,width:120},
			{field:'regionid',title:'行政区划编码',hidden:false,width:120},
			{field:'updatetime',title:'更新时间',hidden:false,width:120},
			{field:'create_time',title:'检测时间',hidden:false,width:120},
			{field:'zt',title:'检测状态',hidden:false,width:60,
				formatter:function showClick(value,record,num){
					if(value==1){//在线
						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==2){//2不在线
						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>";
					}else{
						return "报废";
					}
				}
			}
		]]
	});
}

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

