<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" type="text/css" th:href="@{/static/sys/css/meun/base.css}">
<link rel="stylesheet" type="text/css" th:href="@{/static/sys/css/meun/font.css}">
<link rel="stylesheet" type="text/css" th:href="@{/static/sys/css/meun/common.css}">
<link rel="stylesheet" type="text/css" th:href="@{/static/sys/css/meun/patientManage.css}">

<script type="text/javascript" th:src="@{/static/sys/js/meun/jquery/jquery-1.9.1.min.js}"></script>
<script type="text/javascript" th:src="@{/static/sys/js/meun/jqueryform/jquery.form-3.48.js}"></script>
<script type="text/javascript" th:src="@{/static/sys/js/meun/platform/plugin/picker/WdatePicker.js}"></script>
<script type="text/javascript" th:src="@{/static/sys/js/meun/platform/common.js}"></script>
</head>
<body>
	<!-- wrap start -->
	<div class="wrap index bc clr">
	<!-- conbox start -->
		<div class="conbox patientManage fr">
			 <div class="wx-ui fl">
			 	<ul class="home-list">
			 		<li style="width: 40px;"></li>
			 		<li class="current">
			 			<label style="color: red;">一级菜单</label>
			 			<ol class="item-list"> 
			 				<li style="color: red;">添加</li>
			 			</ol>
			 		</li>
			 		<li class="">
			 			<label style="color: red;">一级菜单</label>
			 			<ol class="item-list"> 
			 				<li style="color: red;">添加</li>
			 			</ol>
			 		</li>
			 		<li class="">
			 			<label style="color: red;">一级菜单</label>
			 			<ol class="item-list"> 
			 				<li style="color: red;">添加</li>
			 			</ol>
			 		</li>
			 		
			 	</ul> 
			 </div>
			 
			 <div class="wx-setup fr">
			 	<div class="childMenu-box">
			 		  <p>子菜单编辑</p>
				 	  <div class="menu-title"> 
				 	  	子菜单名称 &nbsp;  &nbsp; <input type="text" id="menuname" maxlength="6" />
				 	  </div>
				 	  <div class="menu-content">
				 	  		<label class="txt-al-l">子菜单内容</label>   
				 	  		<label><input type="radio" name="sel" id="clickrad" > <span>发送信息</span></label> &nbsp;  &nbsp; 
				 	  		<label><input type="radio" name="sel" id="viewrad" > <span>跳转网页</span></label>
				 	  		<label><input type="radio" name="sel" id="pageview" > <span>小程序</span></label>
				 	  		<div class="menu-content-txt" style="overflow-y: scroll; max-height: 380px;width: 455px;min-height: 380px">
				 	  			<p><a href="javascript:;">图文</a> <a href="javascript:;">文字</a></p>   
				 	  			<div class="img-txt-box">
				 	  				<div class="img-txt-add">
				 	  						+添加图文
				 	  				</div>
				 	  				<a class="delete-btn">删除</a>
				 	  			</div>
				 	  			<textarea class="txt-box" placeholder="请输入..." id="textmenu"></textarea>
				 	  		</div>
				 	  		<div class="link-box">
				 	  			<label>页面地址:</label>
				 	  			<textarea style="display:block;width: 75%;height: 43px;float: right;margin: 0px;" id="viewurl" placeholder="请输入..."></textarea>
				 	  			
				 	  		</div>
				 	  		<div class="page-box" style="height:150px">
				 	  		<div style="height:50px">
				 	  			<label>APPID:</label>
				 	  			<textarea style="display:block;width: 75%;height: 43px;float: right;margin: 0px;" id="appid" placeholder="请输入小程序APPID"></textarea>
				 	  		
				 	  		</div>
				 	  		<div  style="height:50px">	<label>路径:</label>
				 	  			 <textarea style="display:block;width: 75%;height: 43px;float: right;margin: 0px;" id="appidurl" placeholder="请输入小程序路径"></textarea>
				 	  		</div>	
				 	  		</div>
				 	  </div>
			 	</div>
			 	<div class="parentMenu-box">
			 		<p>菜单编辑</p>
			 		<div class="menuName-box">
			 			<label>菜单名称</label>
			 			<input type="text" placeholder="请输入菜单名字" maxlength="6" />
			 		</div>
			 	</div>
			 	<div>
			 		<div style="cursor: pointer;width: 120px;background: #44b549;color: #fff;font-size: 14px;height: 30px;line-height: 30px;text-align: center;margin: auto;margin-top: 30px;border-radius: 5px;" id="deletemeun">删除当前菜单</div>
			 	</div>
			 </div>  
			 <div class="cb"></div>
			  <div class="save-btn" style="cursor: pointer;">保存并发布</div>
		</div>
	<!-- conbox end -->
	
	<!-- 弹出层 -->
	<div class="shade-box"></div>
	<div class="shade-content" style="top:0px;">
		<h3>
			选择素材
			<img src="../../static/sys/images/close.png" class="close-shade" />
		</h3>
		<div class="search-box">
			 <div  id="do-btu" style="cursor: pointer;margin-top: 0px;    background: #44b549;    color: #fff;    font-size: 14px;    height: 30px;    line-height: 30px;    text-align: center;    margin: auto;    border-radius: 5px; width: 120px;">下载公众号图文</div>
		</div>
		<div class="list-box">
			<div class="img-txt-item" > 
				<div class="hide-box"></div>
				<div class="check-box"></div>
				<span>16:40</span>
				<p></p> 
				<img src="../../static/sys/images/wx-bg.jpg" >
				<p></p> 
				
				<p style="width: 80%;height: 50px;float: left;padding: 2px;"></p> 
				<img style="width: 18%;height: 50px;float: right;margin-top:4px; " alt="" src="../../static/sys/images/wx-bg.jpg">	
				
				<p style="width: 80%;height: 50px;float: left;padding: 2px;"></p> 
				<img style="width: 18%;height: 50px;float: right;margin-top:4px; " alt="" src="../../static/sys/images/wx-bg.jpg">	
	
			</div>
			<div class="img-txt-item" > 
				<div class="hide-box"></div>
				<div class="check-box"></div>
				<span>16:40</span>
				<p></p> 
				<img src="../../static/sys/images/wx-bg.jpg" >
				<p></p> 
			</div>
			<div class="img-txt-item" > 
				<div class="hide-box"></div>
				<div class="check-box"></div>
				<span>16:40</span>
				<p></p> 
				<img src="../../static/sys/images/wx-bg.jpg" >
				<p></p> 
			</div>
			<div class="img-txt-item" > 
				<div class="hide-box"></div>
				<div class="check-box"></div>
				<span>16:40</span>
				<p></p> 
				<img src="../../static/sys/images/wx-bg.jpg" >
				<p></p> 
			</div>
			<div class="img-txt-item" > 
				<div class="hide-box"></div>
				<div class="check-box"></div>
				<span>16:40</span>
				<p></p> 
				<img src="../../static/sys/images/wx-bg.jpg" >
				<p></p> 
			</div>
			<div class="img-txt-item" > 
				<div class="hide-box"></div>
				<div class="check-box"></div>
				<span>16:40</span>
				<p></p> 
				<img src="../../static/sys/images/wx-bg.jpg" >
				<p></p> 
				
			</div>
			<div class="img-txt-item" > 
				<div class="hide-box"></div>
				<div class="check-box"></div>
				<span>16:40</span>
				<p></p> 
				<img src="../../static/sys/images/wx-bg.jpg" >
				<p></p> 
			</div>
		</div>
		<div class="shade-content-bottom">
			<div class="shade-btn">
				<a class="confirm-btn">确认</a>
				<a class="cancel-btn">取消</a>
			</div>
		</div>
	</div>

	<script type="text/javascript">
	var path="[[${sysUrl}]]";
	var gtype="";
	var media="";
	var curobj=null;
	var delkey=[];
	var tempobj=null;
	$(function(){
		getWxMenu();
		getWxMaterialList();
		$(".parentMenu-box").find("input[type='text']").val($(".current").find("label").text());
		$(".current").find("ol").show();
		$(".home-list>li").click(function(){
			$(this).find("li").removeClass("current");
			$(this).siblings().removeClass("current"); 
			$(this).addClass("current").find("ol").show(); 
			$(this).siblings().find("ol").hide();
		}); 
		$("#deletemeun").click(function(){
			if(curobj!=null && $(curobj).html()!="添加"){
				if(curobj.nodeName=='LABEL' && $(curobj).next().children().length>1){
					alert("请选择删除的子菜单");
					return;
				}
				var key=curobj.dataset.key;
				if(key!=undefined && key!='undefined' && key!=null && key!=''){
					delkey.push(key);
				}
				curobj.remove();
				curobj=null;
			}else{
				alert("请选择删除的子菜单");
			}	
		});
		
		$("#do-btu").click(function(){
			$.ajax({
		        url:path+"/sys/menu/domaterial",
		        dataType:'json',
		        cache:false,
		        type:'post',
		        data:{},
		        error:function(){return false;},
		        success:function(data){
		        	location.reload();
		        }
		     });
		});
		
		
		$(".save-btn").click(function(){
			var jsondata=joinJsonParam();
			if(jsondata==null){
				return false;
			}
			$.ajax({
		        url:path+"/sys/menu/saveMenu.req",
		        dataType:'json',
		        cache:false,
		        type:'post',
		        data:{"jsondata":jsondata},
		        error:function(){return false;},
		        success:function(data){
		        	alert(data.msg);	
		        	location.reload();
		        }
		     });
		});
		//输入框失去焦点时
		$("#menuname").blur(function(){
			if(curobj==null || $(curobj).html()=="添加"){
				alert("请选中子菜单");
			}
			$(".item-list li.current,.current").text($(this).val());
		});
		
		$("#viewurl").blur(function(){
			if(curobj==null || $(curobj).html()=="添加"){
				alert("请选中子菜单");
			}
			curobj.dataset.url=$(this).val();
		});
		
		$("#appid").blur(function(){
			if(curobj==null || $(curobj).html()=="添加"){
				alert("请选中子菜单");
			}
			curobj.dataset.appid=$(this).val();
		});
		
		$("#appidurl").blur(function(){
			if(curobj==null || $(curobj).html()=="添加"){
				alert("请选中子菜单");
			}
			curobj.dataset.pagepath=$(this).val();
		});
		
		$(".parentMenu-box").find("input[type='text']").blur(function(){
			$(".home-list>li.current").text($(this).val());
		});
		//点击发送信息与跳转链接切换
		$(".menu-content input[type='radio']").on("click",function(){
			if(curobj==null || $(curobj).html()=="添加"){
				return false;
			}
			if($(this).next().text()=="发送信息"){
				if(curobj.dataset.texttype==null || curobj.dataset.texttype==''){
					curobj.dataset.type='click';
				}else{
					curobj.dataset.type='text';
				}
				$(".menu-content-txt").show();
				$(".link-box").hide();
				$(".page-box").hide();
				$(".img-txt-box").html('<div class="img-txt-add">+添加图文</div><a class="delete-btn">删除</a>');
				$(".delete-btn").on("click",function(){
					$(this).next().remove();
					$(this).hide();
					$(".img-txt-add").show();
				});
				$(".img-txt-add").on("click",function(){
					$(".shade-box,.shade-content").show();
				});
			}else if($(this).next().text()=="小程序"){
				curobj.dataset.type='miniprogram';
				$(".menu-content-txt").hide();
				$(".page-box").show();
				$(".link-box").hide();
			}else{
				curobj.dataset.type='view';
				$(".menu-content-txt").hide();
				$(".page-box").hide();
				$(".link-box").show();
			}
		});
		//点击主菜单
		$(".home-list li").on("click",function(e){
			$(".parentMenu-box").show();
			$(".childMenu-box").hide();
		});
		$(".item-list li").on("click",function(e){
			e.stopPropagation();
			$(".parentMenu-box").hide();
			$(".childMenu-box").show();
		});
		$(".shade-content .img-txt-item").on("click",function(){
			$(this).addClass("checked-item").siblings().removeClass("checked-item");
			$(this).find(".hide-box").show();       
			$(this).find(".check-box").show();
			$(this).siblings().find(".hide-box").hide();
			$(this).siblings().find(".check-box").hide();
		});
		//点击弹出图文选择框
		$(".img-txt-add").on("click",function(){
			$(".shade-box,.shade-content").show();
		});
		//点击关闭遮罩层
		$(".close-shade,.shade-content .cancel-btn").on("click",function(){
			$(".shade-box,.shade-content").hide();
		});
		$(".shade-content .confirm-btn").on("click",function(){
			if($(".checked-item")){
				$(".shade-box,.shade-content,.img-txt-add,.hide-box,.check-box").hide();
				$(".img-txt-box").append("<div class='img-txt-item'>"+$(".checked-item").html()+"</div>");
				$(".delete-btn").show();
			}else{
				alert("请选择素材");
			}
		});
		$("#textmenu").on("blur",function(){
			var val=$(this).val();
			curobj.dataset.media=val;
			curobj.dataset.url="";
			curobj.dataset.texttype="text";
		});
		//点击删除
		$(".delete-btn").on("click",function(){
			$(this).next().remove();
			$(this).hide();
			$(".img-txt-add").show();
		});
		//点击图文和文字切换
		$(".menu-content-txt p a").on("click",function(){
			if(curobj==null || $(curobj).html()=="添加"){
				alert("请选中菜单");
			}
			if($(this).text()=="图文"){
				$(".img-txt-box").show();
				$(".txt-box").hide();
			}else{
				$(".img-txt-box").hide();
				$(".txt-box").show();
			}
		});
	});
	
	
	function getWxMenu(){
		$.ajax({
	        url:path+"/sys/menu/getwxmenu",
	        dataType:'json',
	        cache:false,
	        type:'get',
	        data:{},
	        error:function(){return false;},
	        success:function(data){
	        	
	        	if(data.status=='success'){
	        		if(data.data.menu=='' ){
	        			alert("当前公众号不支持开发者模式");
	        			window.location.href=path+"/customCfg/list.req";
	        			return false;
	        		}
	        		var temp=[],obj=JSON.parse(data.data.menu).button;
	        		for(var i=0,len=obj.length;i<len;i++){
	        			var subbutton=obj[i].sub_button;
	        			var html='';
	        			 html+='<li>';
	        			 if(subbutton==undefined || subbutton=='undefined' || subbutton==null || subbutton.length<1){
	        			 	html+='<label class="onemenu" style="cursor: pointer;" data-type="'+obj[i].type+'" data-key="'+obj[i].key+'" data-media="" data-url="'+obj[i].url+'" >'+obj[i].name+'</label>'; 
	        			 }else{
	        					html+='<label class="onemenu" style="cursor: pointer;" data-type="click" >'+obj[i].name+'</label>'; 
	        			 }
	        			 html+='<ol class="item-list"> ';
	        			 
	        			 if(subbutton!=undefined && subbutton!='undefined' && subbutton!=null){
	        				 for(var j=0,jlen=subbutton.length;j<jlen;j++){
	        					 if(subbutton[j].type=='view'){
			        			 	html+='<li data-type="'+subbutton[j].type+'"  data-key="" data-media="" data-url="'+subbutton[j].url+'" class>'+subbutton[j].name+'</li>';
	        					 }else if(subbutton[j].type=='miniprogram'){
			        			 	html+='<li data-type="'+subbutton[j].type+'"  data-key="" data-media="" data-url="'+subbutton[j].url+'" data-appid="'+subbutton[j].appid+'"   data-pagepath="'+subbutton[j].pagepath+'" class>'+subbutton[j].name+'</li>';
	        					 }else{
	        						 html+='<li data-type="'+subbutton[j].type+'"  data-key="'+subbutton[j].key+'" data-media="" data-url="" class>'+subbutton[j].name+'</li>';
	        					 }
	        				  }
	        			 }
	        			 html+='<li style="color: red;">添加</li>';
	        			 html+='</ol>';
	        			 html+='</li>';
	        			 temp[i]=html;
	        		}
	        		html=temp.join('');
	        		if(obj.length<3){
	        			for (var int = 0; int < 3-obj.length; int++) {   
	        				 html+='<li>';
	        				 html+='<label class="onemenu" style="cursor: pointer;color: red;" data-type="click" >一级菜单</label>';     
	        				 html+='<ol class="item-list"> ';
	        				 html+='<li style="color: red;">添加</li>';
	        				 html+='</ol>';
	            			 html+='</li>';   
						}
	        			
	        		}
	        		$(".home-list").html('<li style="width:40px"> </li>'+html);
	        		$(".onemenu,.item-list li").click(function(e){
	        			curobj=this;
	        			var type=this.dataset.type;
	        			var url=this.dataset.url;
	        			$(".childMenu-box").find("input[type='text']").val($(this).text());
	        			$(".home-list li,.home-list .onemenu").removeClass("current");
	        			$(this).addClass("current");  
	        			$(".parentMenu-box").hide();
	        			$(".childMenu-box").show();
	        			if(type=='view'){
	        				$(".link-box").show();
	        				$(".menu-content-txt").hide();
	        				$(".page-box").hide();
	        				$("#viewurl").val(url);
	        				$("#clickrad").attr("checked",false);
	        				$("#pageview").attr("checked",false);
	        				$("#viewrad").attr("checked",true).click();
	        			}else if(type=='miniprogram'){
	        				$(".link-box").hide();
	        				$(".menu-content-txt").hide();
	        				$(".page-box").show();
	        				$("#appid").val(this.dataset.appid);
	        				$("#appidurl").val(this.dataset.pagepath);
	        				$("#clickrad").attr("checked",false);
	        				$("#viewrad").attr("checked",false);
	        				$("#pageview").attr("checked",true).click();
	        			}else{
	        				getCurWxMaterial(this.dataset.key,this.dataset.media);
	        				$(".link-box").hide();
	        				$(".page-box").hide();
	        				$(".menu-content-txt").show();
	        				$("#viewrad").attr("checked",false);
	        				$("#pageview").attr("checked",false);
	        				$("#clickrad").attr("checked",true).click();
	        			}
	        			$(".menu-content").show();
	        			if($(this).hasClass("onemenu")){
	        				if($(this).next().children("li").length>1){
	        					$(".menu-content").hide();
	        				}
	        			}
	        			if($(this).text()=="添加"){
	        				$(this).removeClass("current");
	        				$(this).before("<li data-key='' data-media='' data-url=''  data-type='click'>子菜单名字</li>");
	        				$(".childMenu-box").find("input[type='text']").val("子菜单名字");
	       	 				liOnClick();
	        			} 
	        		});
	        		
	        	}
	        }
	    });
	}
	
	function  liOnClick(){
		
		$(".onemenu,.item-list li").click(function(e){
			curobj=this;
			var type=this.dataset.type;
			var url=this.dataset.url;
			$(".childMenu-box").find("input[type='text']").val($(this).text());
			$(".home-list li,.home-list .onemenu").removeClass("current");
			$(this).addClass("current");  
			$(".parentMenu-box").hide();
			$(".childMenu-box").show();
			if(type=='view'){
				$(".link-box").show();
				$(".menu-content-txt").hide();
				$("#viewurl").val(url);
				$("#clickrad").attr("checked",false);
				$("#viewrad").attr("checked",true).click();
			}else{
				getCurWxMaterial(this.dataset.key,this.dataset.media);
				$(".link-box").hide();
				$(".menu-content-txt").show();
				$("#viewrad").attr("checked",false);
				$("#clickrad").attr("checked",true).click();
				
			}
			$(".menu-content").show();
			if($(this).hasClass("onemenu")){
				if($(this).next().children("li").length>1){
					$(".menu-content").hide();
				}
			}
		});
	}
	//String eventKey,String event,String channel
	function getCurWxMaterial(key,media){
		var mediaId="";
		if((key==null || key=='') && (media==null || media=='') ){
			$(".menu-content-txt").show();
			$(".link-box").hide();
			$(".img-txt-box").html('<div class="img-txt-add">+添加图文</div><a class="delete-btn">删除</a>');
			$(".delete-btn").on("click",function(){
				$(this).next().remove();
				$(this).hide();
				$(".img-txt-add").show();
			});
			$(".img-txt-add").on("click",function(){
				$(".shade-box,.shade-content").show();
			});
			return false;
		}else if((key==null || key=='') && (media!=null && media!='')){
			mediaId=media;
			var temp=[];
	    	for(var i=0,len=tempobj.length;i<len;i++){
	    		if(mediaId==tempobj[i].mediaId){
	    			var wxMaterials=tempobj[i].wxMaterials;
	    			var html='';
	    				html+='<div class="img-txt-item" data-media="'+wxMaterials[0].mediaId+'" >';
	    				html+='<div class="hide-box"></div>';
	    				html+='<div class="check-box"></div>';
	    				html+='<span>'+wxMaterials[0].createDate+'</span>';
	    				html+='<p>'+wxMaterials[0].title+'</p> ';
	    				html+='<img src="'+wxMaterials[0].thumbUrl+'" >';
	    				html+='<p> '+wxMaterials[0].digest+'</p>';
	    			
	    			for(var j=1,jlen=wxMaterials.length;j<jlen;j++){
	    				html+='<p style="width: 80%;height: 50px;float: left;padding: 2px;">'+wxMaterials[j].title+'</p>';
	    				html+='<img style="width: 18%;height: 50px;float: right;margin-top:4px; " alt="" src="'+wxMaterials[j].thumbUrl+'">';	
	    			}
	    			html+='</div>';
	    			temp[i]=html;
	    		}
	    	}
	    	$(".img-txt-box").html('<div class="img-txt-add">+添加图文</div><a class="delete-btn">删除</a>');
	    	$(".delete-btn").on("click",function(){
	    		$(this).next().remove();
	    		$(this).hide();
	    		$(".img-txt-add").show();
	    	});
	    	$(".img-txt-add").on("click",function(){
				$(".shade-box,.shade-content").show();
			});
	    	$(".shade-box,.shade-content,.img-txt-add,.hide-box,.check-box").hide();
			$(".delete-btn").show();
	    	$(".img-txt-box").append(temp.join(''));
	    	return false;
		}
		$(".menu-content-txt").show();
		$(".link-box").hide();
		$(".img-txt-box").html('<div class="img-txt-add">+添加图文</div><a class="delete-btn">删除</a>');
		$(".delete-btn").on("click",function(){
			$(this).next().remove();
			$(this).hide();
			$(".img-txt-add").show();
		});
		$(".img-txt-add").on("click",function(){
			$(".shade-box,.shade-content").show();
		});
		
		$.ajax({
	        url:path+"/sys/menu/getmaterial",
	        dataType:'json',
	        cache:false,
	        type:'post',
	        data:{"eventKey":key,"event":"CLICK"},
	        error:function(){return false;},
	        success:function(data){
	        	mediaId=data.data.wxMsgEvent.mediaId;
	        	if(key==mediaId){
						
	        		$(".img-txt-box").hide();
	    			$(".txt-box").show();
	    			for(var i=0,len=tempobj.length;i<len;i++){
	            		if(mediaId==tempobj[i].mediaId){
	            			var wxMaterials=tempobj[i].wxMaterials;
	    					$("#textmenu").val(wxMaterials[0].content);
	            		}
	            	}
	        		
	        		return;
	        	}
	        	$(".img-txt-box").show();
				$(".txt-box").hide();
	        	var temp=[];
	        	for(var i=0,len=tempobj.length;i<len;i++){
	        		if(mediaId==tempobj[i].mediaId){
	        			var wxMaterials=tempobj[i].wxMaterials;
	        			var html='';
	        				html+='<div class="img-txt-item" data-media="'+wxMaterials[0].mediaId+'" >';
	        				html+='<div class="hide-box"></div>';
	        				html+='<div class="check-box"></div>';
	        				html+='<span>'+wxMaterials[0].createDate+'</span>';
	        				html+='<p>'+wxMaterials[0].title+'</p> ';
	        				html+='<img src="'+wxMaterials[0].thumbUrl+'" >';
	        				html+='<p> '+wxMaterials[0].digest+'</p>';
	        			
	        			for(var j=1,jlen=wxMaterials.length;j<jlen;j++){
	        				html+='<p style="width: 80%;height: 50px;float: left;padding: 2px;">'+wxMaterials[j].title+'</p>';
	        				html+='<img style="width: 18%;height: 50px;float: right;margin-top:4px; " alt="" src="'+wxMaterials[j].thumbUrl+'">';	
	        			}
	        			html+='</div>';
	        			temp[i]=html;
	        		}
	        	}
	        	$(".img-txt-box").html('<div class="img-txt-add">+添加图文</div><a class="delete-btn">删除</a>');
	        	$(".delete-btn").on("click",function(){
	        		$(this).next().remove();
	        		$(this).hide();
	        		$(".img-txt-add").show();
	        	});
	        	$(".img-txt-add").on("click",function(){
					$(".shade-box,.shade-content").show();
				});
	        	$(".shade-box,.shade-content,.img-txt-add,.hide-box,.check-box").hide();
				$(".delete-btn").show();
	        	$(".img-txt-box").append(temp.join(''));
	        }
	      });
	}
	
	
	function getWxMaterialList(){
		$.ajax({
	        url:path+"/sys/menu/materiallist",
	        dataType:'json',
	        cache:false,
	        type:'get',
	        data:null,
	        error:function(){return false;},
	        success:function(data){
	        	var temp=[],obj=data.data.rows;
	        	tempobj=data.data.rows;
				for(var i=0,len=obj.length;i<len;i++){
					var wxMaterials=obj[i].wxMaterials;
					if(wxMaterials[0].msgType=='news' || wxMaterials[0].msgType=='image'){
						var html='';
							html+='<div class="img-txt-item" ';
							if(wxMaterials[0].msgType=='news' ){
								html+='style="border:1px solid #ef0909" ';
							}
							html+='data-media="'+wxMaterials[0].mediaId+'" >';
							html+='<div class="hide-box"></div>';
							html+='<div class="check-box"></div>';
							html+='<span>'+wxMaterials[0].createDate+'</span>';
							html+='<p>'+wxMaterials[0].title+'</p> ';
							html+='<img src="'+wxMaterials[0].thumbUrl+'" >';
						if(wxMaterials[0].msgType=='news' ){
							html+='<p> '+wxMaterials[0].digest+'</p>';
				
						for(var j=1,jlen=wxMaterials.length;j<jlen;j++){
							html+='<p style="width: 80%;height: 50px;float: left;padding: 2px;">'+wxMaterials[j].title+'</p>';
							html+='<img style="width: 18%;height: 50px;float: right;margin-top:4px; " alt="" src="'+wxMaterials[j].thumbUrl+'">';	
						}
					}
						html+='</div>';
						temp[i]=html;
					}
				}
				$(".list-box").html(temp.join(''));
				$(".shade-content .img-txt-item").on("click",function(){
					media=this.dataset.media;
					curobj.dataset.media=media;
					$(this).addClass("checked-item").siblings().removeClass("checked-item");
					$(this).find(".hide-box").show();       
					$(this).find(".check-box").show();
					$(this).siblings().find(".hide-box").hide();
					$(this).siblings().find(".check-box").hide();
				});
				
	        }
	    });
	}
	
	function joinJsonParam(){
		var temp=[];
		var mediatemp=[];
		var homeli=$(".home-list").children("li");
		for ( var i = 0; i < homeli.length; i++) {
			var itemli=$(homeli[i]).find("ol").children("li");
			var len=itemli.length;
			var json='';
			var label=$(homeli[i]).children("label").get(0);
			
			if(len==1){
				if(label.dataset.type=='view'){
					json='{"type": "'+label.dataset.type+'", "name": "'+$(label).html()+'", "url": "'+label.dataset.url+'"}';
				}else if(label.dataset.type=='miniprogram'){
					json='{"type": "'+label.dataset.type+'", "name": "'+$(label).html()+'", "url": "'+label.dataset.url+'","appid":"'+label.dataset.appid+'","pagepath":"'+label.dataset.pagepath+'"}';
				}else if(label!=undefined){
					var type=label.dataset.type;
					var media=label.dataset.media;
					var key=label.dataset.key;
					if((type==undefined || type=='undefined' || type==null || type=="") ||
							((media==undefined || media=='undefined' || media==null || media=="") && (key==undefined || key=='undefined' ||  key==null || key==""))){
					
					}else{
						if(key==undefined || key=='undefined' ||  key==null || key==""){
							key=randomKey(12);
							mediatemp.push('{"key":"'+key+'","media":"'+label.dataset.media	+'","type":"'+label.dataset.texttype+'"}');
						}
						json='{"type": "'+label.dataset.type+'", "name": "'+$(label).html()+'", "key": "'+key+'"}';
					}
				}
				temp[i]=json;
			}else if(len>1 && label!=undefined){
				json='{"name": "'+$(label).html()+'","sub_button": [';
				var templi=[];
				for ( var j = 0; j < itemli.length-1; j++) {
					if(itemli[j].dataset.type=='view'){
						templi[j]='{"type": "'+itemli[j].dataset.type+'", "name": "'+$(itemli[j]).html()+'", "url": "'+itemli[j].dataset.url+'"}';
					} else 	if(itemli[j].dataset.type=='miniprogram'){
						templi[j]='{"type": "'+itemli[j].dataset.type+'", "name": "'+$(itemli[j]).html()+'", "url": "'+itemli[j].dataset.url+'" ,"appid":"'+itemli[j].dataset.appid+'","pagepath":"'+itemli[j].dataset.pagepath+'"}';
					}else{
						var key=itemli[j].dataset.key;
						if(key==undefined ||  key==null || key==""){
							key=randomKey(12);
						}
						templi[j]='{"type": "'+itemli[j].dataset.type+'", "name": "'+$(itemli[j]).html()+'", "key": "'+key+'"}';
						var media=itemli[j].dataset.media;
						if(media!=undefined && media!=null && media!=""){
							mediatemp.push('{"key":"'+key+'","media":"'+itemli[j].dataset.media+'","type":"'+itemli[j].dataset.texttype+'"}');
						}
					}
				}
				json+=templi.join(',');
				json+=']}';
			}
			temp[i]=json;
		}
		var data='{"menu":['+temp.join(",")+'],"mediakey":['+mediatemp.join(",")+'],"delkey":"'+delkey.join(",")+'"}';
		return data;
		
	}
	/*生成key*/
	function  randomKey(l)  {
		var  x="0123456789qwertyuioplkjhgfdsazxcvbnm";
		var  tmp="";
		var timestamp = new Date().getTime();
		for(var  i=0;i<l;i++)  {
		tmp  +=  x.charAt(Math.ceil(Math.random()*100000000)%x.length);
		}
		return  timestamp+tmp;
	}
	
	</script>
	
	</div>
	<!-- wrap ended -->

</body>
</html>