{include file='public/meta'}
<link  rel="stylesheet" type="text/css" href="__LIB__/zTree/v3/css/zTreeStyle/zTreeStyle.css" />
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页
	<span class="c-gray en">&gt;</span>
	会员
	<span class="c-gray en">&gt;</span>
	后台管理菜单
	<a class="btn btn-success radius r btn-refresh" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a>
</nav>
<div class="page-container">
	<div class="text-l">
		管理后台菜单管理
	</div>
	<div class="cl pd-5 bg-1 bk-gray mt-20">
		<span class="l">
		<a onclick='add()' class="btn btn-primary  radius">新增</a>
		<a onclick='edit()' class="btn btn-primary  radius">编辑</a>
		<a onclick='remove()' class="btn btn-primary  radius">删除</a>
		</span>
		
	</div>
	<div class="mt-20">
		<label class="form-label col-xs-4 col-sm-1"></label>
		<div class="formControls col-xs-8 col-sm-11">
			<div id="category_tree" class="ztree"></div>
		</div>
	</div>
</div>
{include file='public/footer'}
<script src="__LIB__/zTree/v3/js/jquery.ztree.all-3.5.min.js"></script>
</body>
</html>
<script type="text/javascript">

var setting = {
	view: {
		addHoverDom: false,
		removeHoverDom: false,
		selectedMulti: false
	},
	edit: {
		enable: true,
		editNameSelectAll: true,
		showRemoveBtn: false,
		showRenameBtn: false
	},
	data: {
		simpleData: {
			enable: true
		}
	}
};

var zNodes =<?php echo $list;?>;

function add() {
	var zTree = $.fn.zTree.getZTreeObj("category_tree"),
	nodes = zTree.getSelectedNodes(),
	treeNode = nodes[0];
	if(treeNode!=undefined){
		var isp= nodes[0].isParent;
	}else{
		var isp= true;
	}			
	var id=(treeNode==undefined?0:treeNode.id);
	var url = "<?php echo url('Menu/add');?>?pid="+id;
	publish('添加',url,'700','480');
}

function edit() {
	var zTree = $.fn.zTree.getZTreeObj("category_tree"),
		nodes = zTree.getSelectedNodes(),
		treeNode = nodes[0];
		if (nodes.length == 0) {
			layer.alert("请先选择一个节点");
			return;
		}

		var url = "<?php echo url('Menu/edit');?>?id="+treeNode.id;
		publish('编辑',url,'700','480');
}



function remove() {
	var zTree = $.fn.zTree.getZTreeObj("category_tree"),
	nodes = zTree.getSelectedNodes(),
	treeNode = nodes[0];
	if (nodes.length == 0) {
		layer.alert("请先选择一个节点");
		return;
	}
	layer.confirm('确认要删除吗？',function(index){
		$.post(
			'{:url("Menu/del")}',
			{					
				'id':treeNode.id,					
			},
			function(d){			
				if(d.error){
					layer.alert(d.error);
				}else{						
					zTree.removeNode(treeNode);
				}
				layer.closeAll('dialog');
			}
		);


	})
}

$(function(){
	$.fn.zTree.init($("#category_tree"), setting, zNodes);
})
</script>