<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<!DOCTYPE html>
<html>
<head lang="en">
	<meta http-equiv="Content-Type" content="text/html; charset=gbk" />
 	<%@include file="../../../../frame/assets/header-all.jsp"%>
	<style>
	.form-line .text-content{
		width:120px;
	}
	</style>
</head>
<body class="easyui-layout">
<!-- <form id="childform" class="easyui-form" data-options="novalidate:true"> -->
	<div id='westPanel' data-options="region:'west',split:true,collapsible:true,border:true," title="行政目录" style="width: 250px;">
      	<div id='detailtab' class="" data-options="fit:true" >
				<div id="tree" style='border:0px solid red;'></div>
		</div>
	 </div>
	
	<div data-options="region:'center',split:true,border:false" class="easyui-layout">
				<iframe scrolling="no" id='sbtdspsrInfo' frameborder="0"  src="" style="width:100%;height:99%;"></iframe>
	</div>
	
	
	
	<!-- <div data-options="region:'center',split:true,border:false" title="选择摄像头" class="easyui-layout">
		<div id='detailtab' data-options="fit:true">
				<div class="form-line clearfix">
					<div class='fl'>
						<input class="easyui-textbox" id="name" data-options="validType:'length[0,128]'">
					</div>
						<button class="text-content">查询</button>
	        
				 </div>
			 <div data-options="region:'center',fit:true" class="easyui-layout">
				<table id='tableGrid'></table>
			 </div> 
		</div>
	</div> -->
<!-- </form> -->
</body>
</html>
<script type="text/javascript">
var proName = window.location.pathname.split("/")[1];
var sysUrl = "http://"+window.location.host+"/"+proName;
var winId	= $.getUrlParam("winId");
var channelsetid = top.$("#"+winId).panel("options").data;
var AllTree = null;
var nodeLimit = 20,nodeMore = "加载更多..";
$(function(){
	if(channelsetid==1){
		initTreePanel();
	}else{
		var url=sysUrl+"/yw/alarmWorkbench/alarmWorkbenchMachine.jsp"
		$('body').layout("remove",'west');
		$("#sbtdspsrInfo").prop("src",url);		
	}
	//加载下拉选项
	/* setTimeout(loadValue,500); */
});
function loadValue(){
	if(records){
		$("#channellistid").val(records.channellistid);
		$("#channelsetid").textbox("setValue",records.channelsetid);
		$("#videonum").textbox("setValue",records.videonum);
		$("#channelnum").numberbox("setValue",records.channelnum);
		$("#channelname").textbox("setValue",records.channelname);
		$("#videomodel").numberbox("setValue",records.videomodel);
		$("#recordxdays").numberbox("setValue",records.recordxdays);
		$("#recordmodel").numberbox("setValue",records.recordmodel);
		$("#createaccount").textbox("setValue",records.createaccount);
		$("#createtime").textbox("setValue",records.createtime);
		$("#modifyaccount").textbox("setValue",records.modifyaccount);
		$("#modifytime").textbox("setValue",records.modifytime);
		$("#remarks").textbox("setValue",records.remarks);
		$("#extend1").textbox("setValue",records.extend1);
		$("#extend2").textbox("setValue",records.extend2);
		$("#extend3").textbox("setValue",records.extend3);
		$("#extend4").textbox("setValue",records.extend4);

	}else{
		
	}
}
/*
var xx1 = $("#xx1").textbox("getValue");//文本
var xx2 = $("#xx2").combobox("getValue");//下拉
var xx3 = $("#xx3").datetimebox("getValue");//日期
var xx4 = $("#xx4").numberbox("getValue");//数字
$('#xx5').combobox({  
	url:'xtclAction!select_Xtcl.do?csdl=xx5&page=1&rows=1000', 
	textField:"csmc",  
	valueField:"csdm",
	panelWidth:148,
	loadFilter:function(data){
		//data.unshift({"csmc":"选择","csdm":""});
		return data;
	}
});
$("#xx6").textbox("setValue",records.xx6);
$("#xx7").combobox("setValue",records.xx7);
$("#xx8").combobox("setValue",records.xx8);
$("#xx9").datetimebox("setValue",$.getNowTime());
$("#xx10").datetimebox("setValue",$.getTodayStart('00:00:00',-3));//往前推3天  +'00:00:00'
$("#xx11").datetimebox("setValue",$.getTodayEnd());//当天 +'23:59:59'	
$("#xx12").datetimebox("setValue",$.getDateNumToStr(records.xx12));
$("#xx13").numberbox("setValue",records.xx13);
*/
//初始化行政树
function initTreePanel(){
	if(AllTree) return;
	AllTree = $('#tree').tree({
	        lines:false,
			animate: false, 
	    	multiple:false,
	    	editable:false,
	    	border:false,
	    	xzNode : false,
	    	parentField:"pid",  
	    	textFiled:"name",  
	    	idFiled:"id",
	    	collapse :false,
	    	data: [
/*	    	{
	    		name:'个人分组',
		 		id  	:"grTree",
		 		state	:'open',
		 		treeId	:'grTree'
			},{	
				name: '公共分组',
				id  	:"ggTree",
				state	:'open',
				treeId	:'ggTree'
			},*/
			/* {	
				name: '行政分组' ,
				id  	:"xzTree",
				state	:'open',
				treeId	:'xzTree'
			}  */],
	    	onClick:function(node){
	    		if(node && node.xzbh){
					setchecked(node);
				} 
				if(node.children && node.children.length>0 ){
					for(var i=0;i<node.children.length;i++){
						if(node.children.children && node.children.children.length>0){
							$(this).tree(node.state === 'closed' ? 'expand' : 'collapse', node.target); 
						}
					}
				}
		 	},
		 	onBeforeExpand:function(node){
		 		if(node && node.xzbh){
					setchecked(node);
				} 
		 		if(node.children && node.children.length>0 ){
					for(var i=0;i<node.children.length;i++){
						if(node.children.children && node.children.children.length>0){
							node && !$(this).tree("getChildren",node.target).length && doSearch_group(node);
						}
					}
				}
		 		
			},
			onDblClick:function(node){
				if(node && node.xzbh){
					setchecked(node);
				}
			},
			onLoadSuccess:function(){
				setchecked();
				
			}
	});
	
	$.ajax({
		 type:'post',
		 async:false,
		 dataType : 'json',
		 //url:'ptxzsAction!query_Ptxzs.do'
		 url:'menuConfigAction!query_Ptxzs.do'
	 }).done(function(data){
		if(data!=null && data.length>0) {
			$.each(data, function (i, o) {
				o.state = 'closed';
				o.treeId = o.xzbh;
				o.name = o.xzmc;
				o.treeType = "xz";
				o.id = o.xzbh;
				o.pid = o.sjxzbh;
				o.start = 0; //iconCls
			})
		}
			var xzfz = {};
		 	xzfz.treeType 	= "xz";
			xzfz.id		= "-1";
			xzfz.pid		= "-1";
			xzfz.start 	= 0; //iconCls
		 	xzfz.xzbh = "-1";
		 	xzfz.xzmc = "行政分组";
		 	xzfz.state = "open";
		 	xzfz.treeId = "-1";
		 	xzfz.sjxzbh = "-1";
		 	xzfz.name = "行政分组";
			data.push(xzfz)
			AllTree.tree('append', {
					 /* parent : AllTree.tree('find', "xzTree").target,  */
					data   : data
			});
	 });
}
//选中行政节点
function setchecked(data){
	var xzbh = "";
	if(data && data.xzbh!="-1"){
		xzbh = data.xzbh;
	}
	var url=sysUrl+"/yw/videomanage/videochannelset/sbtdspsr/sbtdspsr.jsp"
	$("#sbtdspsrInfo").prop("src",url+'?xzbh='+xzbh+"&deviceChoose=true&channelsetid="+channelsetid);		
}
function doSearch_group(node){
	if(node.treeType == 'xz'){
		loadXzChannelToTree(node);
	}
}

function loadXzChannelToTree(node , startIndex){
	if( node ) {
		startIndex = startIndex || 0;
		var param = {
				xzbh : node.treeId,
				sbtd_start: startIndex,
				sbtd_limit: nodeLimit
		};
		
		$.ajax({
			 type:'post',
			 async:false,
			 dataType : 'json',
			 data:param,
			 url:'menuConfigAction!getXzTreeChannelListFromSystem.do'
		 }).done(function(rs){
			 if(rs && rs.length){
					var onLineList = [];
					var unLineList = [];
					for(var i=0;i<rs.length;i++){
						/* var obj = VideoBlockUtil.showChannelIcon_xztree(rs[i]);
						rs[i].iconCls = obj.icon; */
						/*
						if(rs[i].sfzx == "1"){
							onLineList.push(rs[i]);
						}else{
							unLineList.push(rs[i]);
						}*/
					}
					//var list = onLineList.concat(unLineList);
					var list = rs;
					if(rs.length == nodeLimit){
						var mm = {};
						mm.id = node.id+"_more";
						mm.treeType = "xz";
						mm.pid	=	node.id;
						mm.name = nodeMore;
						list.push(mm);
					}
					AllTree.tree('append', {
						parent : AllTree.tree('find', node.id).target,
						data   : list
					});
					
				}
		})
		
	}
}

function doSearchMore(node,startIndex){
	var nodeMore = AllTree.tree('find', node.id+"_more");
	AllTree.tree('remove', nodeMore.target);
	loadXzChannelToTree(node,startIndex);
}
function checkChildren(data){
	if(data && data.children && data.children.length>0 ){
		for(var i=0;i<node.children.length;i++){
			if(node.children.children && node.children.children.length>0){
				return true;
			}
		}
	}
    for (var i in data) {
        if (data[i].name == name) {
            break;
        } else {
            getArray(data[i].children, name);
        }
    }
}


</script>
