var proName = window.location.pathname.split("/")[1],sysUrl = "http://"+window.location.host+"/"+proName,toEdit;
var winId	= $.getUrlParam("winId");
var records = top.$("#"+winId).panel("options").data;
var channelsetid = records.channelsetid;
var devicetype = records.devicetype;
var devicealarmTree=null;
$(function(){
	initTree();
	initDefault();	
});
//默认
function initDefault(){
	initGrid();
}
function initTree() {
	devicealarmTree=$('#xzbh').comboTree({
		source: records.zxbhdata,
		isMultiple: true,
		cascadeSelect: true,
		collapse: false
	});

}
//查询条件
function getQueryParams(){
	var sParam = {};
	if(devicealarmTree!=null){
		if(devicealarmTree.getSelectedIds()&& devicealarmTree.getSelectedIds().length>0)
		{			//讲数组赋值给行政区划的值['1','2']
			sParam.xzbh  =devicealarmTree.getSelectedIds().join(",");
		}
	}
	sParam.devicetype=devicetype;
	sParam.LIKEtdmc = $('#LIKEtdmc').textbox("getValue");
	sParam.LIKEsbbh = $('#LIKEsbbh').textbox("getValue");
	sParam.channelsetid = channelsetid;
	return sParam;
}
//加载列表
function initGrid(){	
	var toolbar = [{
    	text	:	'查询',
        iconCls	:	'icon-search',
        handler	:	doSearch
    }];
	$('#tableGrid').datagrid({
		toolbar : toolbar,
		singleSelect:false,
		rownumbers:true,
		queryParams:getQueryParams(),
//		url : 'menuConfigAction!getChannelListFromSystem.do',
		url : 'sbtdspsrAction!listSbtdspsrToChannelSet.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:'tdmc',title:'名称',hidden:false,width:120},
			{field:'sbbh',title:'设备编号',hidden:false,width:120},
			{field:'tdbh',title:'通道编号',hidden:true,width:120},
			{field:'xzmc',title:'行政目录',hidden:false,width:120}
		]]

	});
}

function getSelectedRows(){
	var rows = $('#tableGrid').datagrid('getChecked'); 
	return rows;
}
//获取选中元素

function getSelected(){
	var rows = $('#tableGrid').datagrid('getChecked');
	return rows;
}

function doSearch(){
	$('#tableGrid').datagrid('load',getQueryParams());
	if(devicetype=="1") {
		$('#tableGrid').datagrid('showColumn', 'tdbh');
	}else{
		$('#tableGrid').datagrid('hideColumn', 'tdbh');
	}
}
