<?php include $this->admin_tpl('meta', 'admin');?>
<title>微信菜单管理 - YzmCMS内容管理系统</title>
</head>
<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" 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="cl pd-5 bg-1 bk-gray"> <span class="l"><a href="javascript:;" onclick="yzm_open('添加菜单','<?php echo U('add');?>',600,350)" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i> 添加菜单</a> <a href="javascript:;" onclick="create_menu()" class="btn btn-success radius"><i class="Hui-iconfont">&#xe603;</i> 同步至微信</a> <a href="javascript:;" onclick="wechat_menu_del()" class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 删除所有菜单并提交微信</a></span></div>
	<form action="<?php echo U('order');?>" method="post">
	<table class="table table-border table-bordered table-bg table-hover">
		<thead>
			<tr class="text-c">
				<th width="50">排序</th>
				<th class="text-l">菜单名称</th>
				<th width="80">菜单类型</th>
				<th>Key/URL</th>		
				<th width="250">管理操作</th>
			</tr>
		</thead>
		<tbody>
			<?php 
			   foreach($data as $val){
			 ?>
			<tr class="text-c">
				<td><input type="text" class="input-text listorder" name="listorder[]" value="<?php echo $val['listorder']?>"><input type="hidden" name="id[]" value="<?php echo $val['id']?>"></td>
				<td class="text-l"><?php echo $val['name'];?></td>
				<td><?php echo $val['type']=="1" ? '关键字' : '<span style="color:red">跳转链接</span>';?></td>
				<td><?php echo $val['type']=="1" ? $val['keyword'] : '<a href="'.$val['url'].'" target="_blank">'.$val['url'].'</a>';?></td>
				<td class="td-manage"><a title="增加子菜单" class="btn-mini btn-success ml-5" href="javascript:;" onclick="yzm_open('增加子菜单','<?php echo U('add',array('id'=>$val['id']));?>',600,350)" style="text-decoration:none">增加子菜单</a> 
				<a title="编辑" class="btn-mini btn-secondary ml-5" href="javascript:;" onclick="yzm_open('编辑菜单','<?php echo U('edit',array('id'=>$val['id']));?>',600,350)" style="text-decoration:none">编辑</a>
				<a title="删除" class="btn-mini btn-warning ml-5" href="javascript:;" onclick="yzm_del('<?php echo U('delete',array('id'=>$val['id']));?>')" style="text-decoration:none">删除</a></td>
			</tr>
			<?php 
				$r = $wechat_menu->where(array('parentid' => $val['id']))->order('listorder ASC,id DESC')->limit('5')->select();
				foreach($r as $val){
			 ?>
			<tr class="text-c">
				<td></td>
				<td class="text-l"><?php echo $val['name'];?></td>
				<td><?php echo $val['type']=="1" ? '关键字' : '<span style="color:red">跳转链接</span>';?></td>
				<td><?php echo $val['type']=="1" ? $val['keyword'] : '<a href="'.$val['url'].'" target="_blank">'.$val['url'].'</a>';?></td>
				<td class="td-manage"><span class="btn-mini btn-disabled ml-5">增加子菜单</span> <a title="编辑" href="javascript:;" onclick="yzm_open('编辑菜单','<?php echo U('edit',array('id'=>$val['id']));?>',600,350)" class="btn-mini btn-secondary ml-5" style="text-decoration:none">编辑</a> <a title="删除" class="btn-mini btn-warning ml-5" href="javascript:;" onclick="yzm_del('<?php echo U('delete',array('id'=>$val['id']));?>')" style="text-decoration:none">删除</a></td>
			</tr>			  
			<?php 
				}
			   }		 
			?>	
		</tbody>
	</table>
	<?php if(!$data){ ?><div class="yzm_no_data"><i class="Hui-iconfont">&#xe6e0;</i> 暂无数据</div><?php } ?>
	<div class="cl pd-5 bg-1 bk-gray"> <span class="l"><input class="orderbutton btn-primary radius" name="dosubmit" value="排序" type="submit"></span></div>
	</form>
</div>
<?php include $this->admin_tpl('footer', 'admin');?>
<script type="text/javascript">

function wechat_menu_del(){
	layer.confirm('确认要删除所有菜单吗？',function(index){
		$.ajax({
		    type: 'GET',
		    url: '<?php echo U('delete_menu');?>', 
		    dataType: "json", 
		    success: function (msg) {
				if(msg.status == 1){
					layer.msg(msg.message, {icon:1}, function(){
						location.reload();
					});     
			    }else{
					layer.alert(msg.message);
				}
		    }
		})
	});
}

function create_menu(){
	layer.msg('正在处理中……', { icon: 16, shade: 0.21, shadeClose:true, time:0 });
	$.ajax({
	    type: 'GET',
	    url: '<?php echo U('create_menu');?>', 
	    dataType: "json", 
	    success: function (msg) {
			if(msg.status == 1){
				layer.msg(msg.message, {icon:1});     
		    }else{
				layer.alert(msg.message);
			}
	    }
	})
}

</script>
</body>
</html>