var windowId,proName = window.location.pathname.split("/")[1],sysUrl = "http://"+window.location.host+"/"+proName,toEdit;
var winId	= $.getUrlParam("winId");
var obj = top.$("#"+winId).panel("options").data;
$(function(){
	initDefault();	
});
//默认
function initDefault(){
	initGrid();
}
//查询条件
function getQueryParams(){
	var sParam = {};
	if(obj.deviceType=="videoOnline"){
		if(obj.type=="1"){
			sParam.isonline = 1;
		}else{
			sParam.tableparam = " and (isonline <> '1' or isonline is null)";
		}
	}else if(obj.deviceType=="videoIntact"){
		if(obj.type=="1"){
			sParam.vqdstate = 1;
		}else{
			sParam.tableparam = " and (vqdstate <> '1' or vqdstate is null)";
		}
	}else if(obj.deviceType=="recordIntact"){
		if(obj.type=="1"){
			sParam.recordstate = 1;
		}else{
			sParam.tableparam = " and (recordstate <> '1' or recordstate is null)";
		}
	}
	sParam.LIKEchannelname = $("#LIKEchannelname").textbox("getValue");
	//sParam.order = "order by currentstatetime desc ";
	return sParam;
}
//加载列表
function initGrid(){	
	var toolbar = [{
    	text	:	'查询',
        iconCls	:	'icon-search',
        handler	:	doSearch
    }];
	$('#tableGrid').datagrid({
		toolbar : toolbar,
		singleSelect:true,
		rownumbers:true,
		queryParams:getQueryParams(),
		url : 'ywvideocurrentstateAction!listYwvideocurrentstateByPage.do',
		columns : [[
		    {
				field: 'A',
				checkbox:'true',
				width:30
			},
		    {field:'currentstateid',title:'currentstateid',hidden:true,width:120, 
				formatter:function showClick(value,record,num){ 
					return "<a  href='javascript:void(0);' class='ahref' onclick='doUpdate("+num+")'>"+value+"</a>";
				}
 			},
 			{field:'xzmc',title:'行政区划',hidden:false,width:70},
 			{field:'channelname',title:'通道名称',hidden:false,width:90},
			{field:'videonum',title:'设备编号',hidden:false,width:120,
 				formatter:function showClick(value,record,num){
 					return "<span title='" + value + "'>" + value + "</span>";
 				}
			},
			{field:'channelnum',title:'通道编号',hidden:false,width:60},
			{field:'videocatalog',title:'监控行政目录',hidden:true,width:120},
			{field:'currentstatename',title:'当前状态',hidden:true,width:120},
			{field:'currentstatetime',title:'巡检时间',hidden:false,width:120,
				formatter:function showClick(value,record,num){
 					return "<span title='" + value + "'>" + transEmpty(value) + "</span>";
 				}
			},
			{field:'isonline',title:'是否在线',hidden:(obj.deviceType=="videoOnline") ? false : true,width:60,
					formatter:function showClick(value,record,num){
						if (record.isonline == '1') {
							return "在线";
						} else if (record.isonline == '0') {
							return "不在线";
						} else {
							return "未知状态";
						}
					}
			},
			{field:'playfail',title:'播放失败',hidden:true,width:120},
			{field:'networkerror',title:'网络异常',hidden:true,width:120},
			{field:'vqcstate',title:'抽帧状态',hidden:true,width:120},
			{field:'vqcfailuretype',title:'抽帧故障类型',hidden:true,width:120},
			{field:'vqcfailurecause',title:'抽帧故障原因',hidden:true,width:120},
			{field:'vqctaskid',title:'抽帧任务id',hidden:true,width:120},
			{field:'videostatus',title:'视频状态',hidden:(obj.deviceType=="videoOnline" || obj.deviceType=="recordIntact") ? true : false,width:120,
				formatter:function showClick(value,record,num){
					if (record.vqdstate == '1') {
						return "正常";
					} else if (record.vqdstate == '0')  {
						if (record.vqdfailurecause != null) {
							return "<span title='" + record.vqdfailurecause + "'>" + record.vqdfailurecause + "</span>";
						} else {
							return "异常";
						}
					} else {
						if (record.vqdfailurecause != null) {
							return "<span title='" + record.vqdfailurecause + "'>" + record.vqdfailurecause + "</span>";
						} else {
							return "未知状态";
						}
					}
				}
			},
			{field:'videofailurecause',title:'故障原因',hidden:true,width:120},
			{field:'vqdstate',title:'质量诊断状态',hidden:true,width:120,
					formatter:function showClick(value,record,num){
						if (record.vqdstate == '1') {
							return "正常";
						} else if (record.vqdstate == '0')  {
							if (record.videofailurecause != null) {
								return "<span title='" + record.videofailurecause + "'>" + record.videofailurecause + "</span>";
							} else {
								return "异常";
							}
						} else {
							if (record.videofailurecause != null) {
								return "<span title='" + record.videofailurecause + "'>" + record.videofailurecause + "</span>";
							} else {
								return "未知状态";
							}
						}
					}
			},
			{field:'nosignalstatus',title:'无信号检测状态',hidden:true,width:120},
			{field:'imgclearstatus',title:'图像清晰检测状态',hidden:true,width:120},
			{field:'imgcontraststatus',title:'图像对比检测状态',hidden:true,width:120},
			{field:'imgcolorstatus',title:'颜色检测状态',hidden:true,width:120},
			{field:'imglightstatus',title:'亮度检测状态',hidden:true,width:120},
			{field:'videofreezestatus',title:'视频冻结检测状态',hidden:true,width:120},
			{field:'videojitterstatus',title:'镜头抖动检测状态',hidden:true,width:120},
			{field:'videoupheavalstatus',title:'视频剧变检测状态',hidden:true,width:120},
			{field:'videocodeerrorstatus',title:'编码异常检测状态',hidden:true,width:120},
			{field:'videonoisestatus',title:'噪声雪花检测状态',hidden:true,width:120},
			{field:'videorollstripestatus',title:'滚动条纹检测状态',hidden:true,width:120},
			{field:'vqdfailuretype',title:'质量诊断故障类型',hidden:true,width:120},
			{field:'vqdfailurecause',title:'质量诊断故障原因',hidden:true,width:120},
			{field:'vqdtaskid',title:'质量诊断任务id',hidden:true,width:120},
			{field:'recordstate',title:'录像状态',hidden:(obj.deviceType=="recordIntact") ? false : true,width:70,
					formatter:function showClick(value,record,num){
						if (record.recordstate == '1') {
							return "正常";
						} else if (record.recordstate == '0')  {
							return "异常";
						} else {
							return "未知状态";
						}
					}
			},
			{field:'recordfailuretype',title:'录像故障类型',hidden:true,width:120},
			{field:'recordfailurecause',title:'录像故障原因',hidden:true,width:120},
			{field:'recordtaskid',title:'录像任务id',hidden:true,width:120},
			{field:'videolabelstatus',title:'标记状态',hidden:true,width:120},
			{field:'videolabeltime',title:'标记时间',hidden:true,width:120},
			{field:'videolabelaccount',title:'标记人员',hidden:true,width:120},
			{field:'createaccount',title:'创建人员',hidden:true,width:120},
			{field:'createtime',title:'创建日期',hidden:true,width:120},
			{field:'modifyaccount',title:'修改人员',hidden:true,width:120},
			{field:'modifytime',title:'修改日期',hidden:true,width:120},
			{field:'remarks',title:'备注',hidden:true,width:120},
			{field:'extend1',title:'扩展1',hidden:true,width:120},
			{field:'extend2',title:'扩展2',hidden:true,width:120},
			{field:'extend3',title:'扩展3',hidden:true,width:120},
			{field:'extend4',title:'扩展4',hidden:true,width:120}
		]]
	});
}
//查询
function doSearch(){	
	$('#tableGrid').datagrid('load',getQueryParams());
}

function transEmpty(str){
	if(!str || str==null ||str=="null"){
		return "-";
	}
	return str;
}