/**
 * app公告发布
 * 2018/4/20 by liufang
 */
$(function () {
	var layer;
	var permPublish = $("#perm-publish").val();//发送公众号所有用户权限
	var noticeType = ''; //发布类型
	var contentType = ''; //发布内容
	var ERROR_OK = 200; //请求200
	var contextPath = $("#contextPath").val(); //请求前缀
//	var picture = '';
	var fileType = '';
	var orgArr = [] //选择项目对象数组
	var orgTmpArr = [] //临时选择项目对象数组
	var editorA, editorB, editorC;
	var announceArr =[],graphArr = [];//临时存储搜素对象数组
	var num = 1;//新增公告多少次
	var editorObj = {};
	var detailApproveTyp="";
	//var currentUrl;
	var projectOrgId;
	var state = 0;//公告发布状态 0-未发布 1-已发布
	layui.use('layer', function () {
		layer = layui.layer;
	});

	template.config("escape", false);
	var tpl = {
		noticeTpl: '<div class="notice-wrapper">\
		  	<div class="notice-mask"></div>\
		  	<div class="notice-close-btn"></div>\
		  	<div class="notice-content clearfloat">\
		  		<div class="notice-con-left"></div>\
		  		<div class="notice-con-right">\
		  			<div class="notice-tabs clearfloat">\
		  				<div class="tab tab-left active">微信端预览</div>\
		  				<div class="tab tab-right">app端预览</div>\
		  			</div>\
		  			<% if(showTip){%>\
		  				<div class="notice-tip" >提示：点击banner可查看跳转效果。</div>\
		  			<%}%>\
		  		</div>\
		  	</div>\
		  </div>',
		noticeDetailTpl: '<div class="notice-wrapper notice-detail-tpl notice-detail-tpl-<%=type%>">\
			  	<div class="notice-mask"></div>\
			  	<div class="notice-close-btn"></div>\
			  	<div class="notice-content clearfloat">\
			  		<div class="notice-con-left">\
					  <div class="notice-detail-wp">\
					  	<div class="notice-detail-con">\
						  	<div class="notice-detail-top">\
						  		<div class="back-btn"></div>\
					  		</div>\
					  		<div class="notice-detail-con-wp">\
						  		<div class="notice-title-and-date">\
								  	<div class="title"><%=title%></div>\
							  		<div class="date">04-12 10:30 &nbsp;&nbsp;编辑人：学友</div>\
						  		</div>\
						  		<div class="content"><%=con%></div>\
							</div>\
					  </div>  	\
			  		</div>\
			  		</div>\
			  		<div class="notice-con-right" >\
			  			<% if(!showTab){%>\
				  			<div class="notice-tabs clearfloat">\
				  				<div class="tab tab-left <%if(type=="detail"){%> active <%}%>">微信端预览</div>\
				  				<div class="tab tab-right <%if(type=="main"){%> active <%}%>"">app端预览</div>\
				  			</div>\
			  			<%}%>\
			  			<% if(showTip){%>\
			  				<div class="notice-tip" >提示：点击banner可查看跳转效果。</div>\
			  			<%}%>\
			  		</div>\
			  	</div>\
			  </div>',
		appTpl: '<div class="notice-wrapper app-tpl">\
				  	<div class="notice-mask"></div>\
				  	<div class="notice-close-btn"></div>\
				  	<div class="notice-content clearfloat">\
				  		<div class="notice-con-left">\
						  <div class="app-wp">\
						 	<div class="app-con">\
						 		<div class="banner-wp"  style="background-image: url( <%=banner%>)"></div>\
						 	</div>\
						 </div>\
				  		</div>\
				  		<div class="notice-con-right">\
				  			<div class="notice-tabs clearfloat">\
				  				<div class="tab tab-left ">微信端预览</div>\
				  				<div class="tab tab-right active">app端预览</div>\
				  			</div>\
				  			<% if(showTip){%>\
				  				<div class="notice-tip" >提示：点击banner可查看跳转效果。</div>\
				  			<%}%>\
				  		</div>\
				  	</div>\
				  </div>',
		wxTpl: '<div class="notice-wrapper wx-tpl">\
					  	<div class="notice-mask"></div>\
					  	<div class="notice-close-btn"></div>\
					  	<div class="notice-content clearfloat">\
					  		<div class="notice-con-left">\
								  <div class="wx-wp">\
								 	<div class="wx-con">\
							 		<div class="banner-wp"  style="background-image: url( <%=banner%>)"></div>\
							 	</div>\
							 </div>\
					  		</div>\
					  		<div class="notice-con-right">\
					  			<div class="notice-tabs clearfloat">\
					  				<div class="tab tab-left active">微信端预览</div>\
					  				<div class="tab tab-right">app端预览</div>\
					  			</div>\
					  			<% if(showTip){%>\
					  				<div class="notice-tip" >提示：点击banner可查看跳转效果。</div>\
					  			<%}%>\
					  		</div>\
					  	</div>\
					  </div>',
		noticeListTpl: '<div class="notice-wrapper notice-list-tpl">\
						  	<div class="notice-mask"></div>\
						  	<div class="notice-close-btn"></div>\
						  	<div class="notice-content clearfloat">\
						  		<div class="notice-con-left">\
									  <div class="notice-list-wp">\
									 	<div class="notice-list-con">\
										<%for(var i=0;i<list.length;i++){%>\
											<div class="notice-item-wp" >\
										 		<div class="banner-wp" style="background-image: url( <%=list[i].banner%>)"></div>\
										 		<div class="banner-descript"><%=list[i].title%></div>\
										 	</div>\
										<%}%>\
									</div>\
								</div>\
						  		</div>\
						  		<div class="notice-con-right">\
						  			<div class="notice-tabs clearfloat">\
						  				<div class="tab tab-left active">微信端预览</div>\
						  				<div class="tab tab-right">app端预览</div>\
						  			</div>\
						  			<% if(showTip){%>\
						  				<div class="notice-tip" >提示：点击banner可查看跳转效果。</div>\
						  			<%}%>\
						  		</div>\
						  	</div>\
						  </div>',
		searchTpl: '<div class="search-wp">\
						<div class="s-input-wp">\
							<input class="s-input" type="text" placeholder="输入内容以搜索" />\
							<span class="s-icon"></span>\
						</div>\
						<div class="choosed-person-wp"></div>\
						<div class="project-person-list"></div>\
					</div>'	,
		"chooseTpl": '<div class="choosed-person">\
						<span class="choosed-tip">已选用户：</span>\
						<% for(var i=0;i<list.length;i++){%>\
							<div class="person-item" data-userid="<%=list[i].userId%>" data-openid="<%=list[i].openId%>" >\
								<span class="person"><%=list[i].name%>  <%=list[i].mobile%></span>\
								<span class="peoject-del-btn" data-userid="<%=list[i].userId%>" ></span>\
							</div>\
						<%}%>\
					</div>'	,
		"projectTpl": '<div class="project-person-item">\
						<% for(var j=0;j<list.length;j++){%>\
							<div class="checkbox-wp">\
								<span class="checkbox-input">\
									<input type="checkbox" id="project-<%=list[j].userId%>" <%if(userIds.indexOf(list[j].userId+"")!=-1){%> checked <%}%> class="check-item" name="project-p-<%=list[j].userId%>" data-openid="<%=list[j].openId%>" data-name="<%=list[j].name%>"  data-mobile="<%=list[j].mobile%>" data-userid="<%=list[j].userId%>"/>\
									<span class="checkbox-inner"></span>\
								</span>\
								<label class="checkbox-con" for="project-<%=list[j].userId%>"> <%=list[j].name%>  <%=list[j].mobile%> <%=list[j].orgName%> </label>\
							</div>\
						<%}%>\
					</div>'	,
		"addNoticeTpl": '<div class="small-notice-item small-notice-item">\
							<div class="s-notice-wp">\
								<div class="s-notice-title">标题</div>\
								<div class="s-notice-cover"></div>\
							</div>\
							<div class="notice-operate-wp">\
								<span class="n-up-bnt"></span>\
								<span class="n-down-bnt"></span>\
								<span class="n-del-bnt"></span>\
							</div>\
						</div>'	,
		"addAgainNoticeTpl": '<div class="small-notice-item small-notice-item">\
						<div class="s-notice-wp">\
							<div class="s-notice-title"><%=data.title%></div>\
							<div class="s-notice-cover" style="background-image:url(<%=data.coverUrl%>)"></div>\
						</div>\
						<div class="notice-operate-wp">\
							<span class="n-up-bnt"></span>\
							<span class="n-down-bnt"></span>\
							<span class="n-del-bnt" data-id="<%=data.id%>"></span>\
						</div>\
					</div>'	,				
		"noticeAgainModeTpl": '<div class="announcement-item" data-id="<%=data.id%>">\
							<div class="cover-wp clearfloat">\
								<span class="tips">封面图片</span>\
								<div class="cover-con">\
									<div class="img-wrapper" style="background-image:url(<%=data.coverUrl%>)"></div>\
									<div class="upload-btn-wp">\
										<span class="upload-icon"></span>\
										<input id="photoBtn" type="button" onclick="document.getElementById(\'inputImage\').click()" value="更换照片">\
										<input id="inputImage" type="file" accept="image/*" style="display: none;" />\
										<br/>\
										<img id="showImg" style="display: none" src="<%=data.coverUrl%>" data-url="<%=data.coverUrl%>"/>\
									</div>\
								</div>\
							</div>\
							<div class="titles-wp clearfloat">\
								<span class="tips">主题</span>\
								<input class="editot-input title-con" type="text" value="<%=data.title%>"/>\
							</div>\
							<div class="content-wp clearfloat">\
								<span class="tips">正文</span>\
								<div id="myeditor_a_<%=num%>" class="u_editor"></div>\
							</div>\
							<div class="summary-wp clearfloat">\
								<span class="tips">摘要</span>\
								<textarea rows="" cols="" class="summary-con"><%=data.summaryInfo%></textarea>\
							</div>\
						</div>'	,
			"noticeModeTpl": '<div class="announcement-item">\
									<div class="cover-wp clearfloat">\
										<span class="tips">封面图片</span>\
										<div class="cover-con">\
											<div class="img-wrapper"></div>\
											<div class="upload-btn-wp">\
												<span class="upload-icon"></span>\
												<input id="photoBtn" type="button" onclick="document.getElementById(\'inputImage\').click()" value="选择照片">\
												<input id="inputImage" type="file" accept="image/*" style="display: none;" />\
												<br/>\
												<img id="showImg" style="display: none" />\
											</div>\
										</div>\
									</div>\
									<div class="titles-wp clearfloat">\
										<span class="tips">主题</span>\
										<input class="editot-input title-con" type="text" />\
									</div>\
									<div class="content-wp clearfloat">\
										<span class="tips">正文</span>\
										<div id="myeditor_a_<%=num%>" class="u_editor"></div>\
									</div>\
									<div class="summary-wp clearfloat">\
										<span class="tips">摘要</span>\
										<textarea rows="" cols="" class="summary-con"></textarea>\
									</div>\
								</div>'	,
					"typeTpl": '<option value="">选择审核类型</option>\
					<% for(i=0;i<data.length;i++){%> \
						<option value="<%=data[i].id%>"><%=data[i].name%></option>\
						<%}%>'				
	}
	var appPublish = {
		init: function () {
			this.bindEvent();
			this.render();
			if(!permPublish){
				$(".radio-perm").remove();
			}
		},
		
		render: function () {
			var _this = this;
			var id = _this.getQueryString("id");
			_this.renderEditor();
			if (!!id) {
				_this.sortOrg(function(){
					_this.ajaxDetail(id)
				});
				
			}else{
				_this.sortOrg();
			}
			
		},
		bindEvent: function () {
			var _this = this;
			
			//选择发布类型变化
			$("#state").on("change", function () {

				//noticeType 公告类型： 1 公告 ；2 banner图；3 跳转链接 5：楼闪送
				//选择公告和跳转链接时contentType传1
				noticeType = $(this).val();

				if (!noticeType) { //发布类型没选择
					//各个类型内容隐藏
					//$(".img-wrapper").css("background-image", "url(../images/admin/notice_cover.png)");
					$(".app-publish-wrapper").hide();
					$(".choose-publish-con").hide();
					//$(".public-extra-wp").hide();
				} else if (noticeType == 1) {
					contentType = 1; //选择公告和跳转链接时contentType传1
					//$(".img-wrapper").css("background-image", "url(../images/admin/notice_cover.png)");
					$(".app-publish-wrapper").eq(0).show().siblings().hide();
					$(".choose-publish-con").hide();
				} else if (noticeType == 2 || noticeType == 5) {
					//$(".img-wrapper").css("background-image", "url(../images/admin/notice_cover.png)");
					$(".app-publish-wrapper").hide();
					$(".choose-publish-con").show();
					$("#content").val("");
				} else if (noticeType == 3) {
					//$(".img-wrapper").css("background-image", "url(../images/admin/notice_cover.png)");
					contentType = 1; //选择公告和跳转链接时contentType传1
					$(".app-publish-wrapper").eq(1).show().siblings().hide();
					$(".choose-publish-con").hide();
				}

			});
			//选择发布内容变化
			$("#content").on("change", function () {
				//图文类型： 1 图文消息 ；2 跳转链接
				contentType = $(this).val();
				if (!contentType) {
					//$(".img-wrapper").css("background-image", "url(../images/admin/notice_cover.png)");
					$(".app-publish-wrapper").hide();
					$(".choose-publish-con").hide();
				} else if (contentType == 1) {
					//$(".img-wrapper").css("background-image", "url(../images/admin/notice_cover.png)");
					$(".app-publish-wrapper").eq(3).show().siblings().hide();
					$(".choose-publish-con").show();
					if($("#state").val()==5){
						$(".app-publish-wrapper").eq(3).find('.port-wp').css('visibility','hidden');
					}else{
						$(".app-publish-wrapper").eq(3).find('.port-wp').css('visibility','visible');
					}
				} else if (contentType == 2) {
					//$(".img-wrapper").css("background-image", "url(../images/admin/notice_cover.png)");
					$(".app-publish-wrapper").eq(2).show().siblings().hide();
					$(".choose-publish-con").show();
					if($("#state").val()==5){
						$(".app-publish-wrapper").eq(2).find('.port-wp').css('visibility','hidden');
					}else{
						$(".app-publish-wrapper").eq(2).find('.port-wp').css('visibility','visible');
					}
				}
			});
			//选择公众号发布端口
			$(" #announcement .port-con .checkbox-wp .check-item").on("click",function(){ 
				if(!($("#announcement").is(':hidden')) && $(".port-con").find('input:checkbox[name="public"]').prop("checked") ){
					if($(this).data("type")==3){
						$("#announcement .public-extra-wp").show();
						//$('input:radio:first').attr('checked', 'checked');
						$("#announcement").find("input:radio[name='public']:first").prop('checked', true);
						 $("#announcement .search-wp").remove();
					}
					
				}else{
					$("#announcement .public-extra-wp").hide();
				}
			});
			$("#graphic .port-con .checkbox-wp").on("click",function(){
				if(!($("#graphic").is(':hidden')) && $(".port-con").find('input:checkbox[name="public2"]').prop("checked")){
					$("#graphic .public-extra-wp").show();
					$("#announcement").find("input:radio[name='public1']:first").prop('checked', true);
					$("#announcement .search-wp").remove();
				}else{
					$("#graphic .public-extra-wp").hide();
					
				}
			});
			//选择项目部分用户
			$("#announcement .radio-block .radio-item").on("click",function(){
				var type = $("#announcement").find("input:radio[name='public']:checked").data("type");
				if(type==3){
					_this.renderSearchList()
					//
					$("#announcement .search-select-wp").html(template.render(tpl.searchTpl));
					announceArr = []
					_this.searchEvent(1)
				}else{
					$("#announcement .search-wp").remove();
				}
			});
//			$("#graphic .radio-block").on("click",function(){
//				var type = $("#graphic").find("input:radio[name='public1']:checked").data("type");
//				if(type==3){
//					$("#graphic .search-select-wp").html(template.render(tpl.searchTpl));
//					_this.searchEvent(2)
//				}else{
//					$("#graphic .search-wp").remove();
//				}
//			});
			//各个公告切换
			_this.noticeAddEvent()
			//点击返回
			$(".edit-back-btn").on("click",function(){
				 window.location.href= contextPath+ '/notice/audit/noticeAppVerify';
			})
			//发布公告绑定事件
			_this.noticeBindEvent();
			//发布banner图文消息绑定事件
			_this.bannerImageBindEvent();
			//发布banner跳转链接绑定事件
			_this.bannerLinkBindEvent();
			//发布生成链接绑定事件
			_this.produceLinkBindEvent();
			// 筛选项目
//			if(!!_this.getQueryString("id");){
//				
//			}
			
		},
		// 筛选项目
		sortOrg: function( callback){
			var _this = this
			// 初始化一下筛选项目
			_this.ajaxSortOrg({city:''},callback)
			$('.default-select#orgId').on('click', function(event) {
				event.preventDefault();
				/* Act on the event */
				$('.sortOrg_wrap').toggleClass('_hide');
			});
			// 点击搜搜索
			$('.sortOrg_search_btn').on('click', function(event) {
				event.preventDefault();
				/* Act on the event */
				var city = $('#sortOrg_search').val()
				var obj = {
					city : city
				}
				_this.ajaxSortOrg(obj)
			});
			// cheaked选择
			$("body").on('click', '.item_cheak', function(event) {
				event.preventDefault();
				/* Act on the event */
				var that = $(this)
				that.toggleClass('item_cheaked');
				// 看是否是全选按钮或者城市按钮
				if(that.hasClass('item_cheak_all') || that.hasClass('item_cheak_city')){
					if(that.hasClass('item_cheak_all')){
						var cheakDom = $('.item_cheak')
					}else if(that.hasClass('item_cheak_city')){
						var cheakDom = that.parent().parent().find('.item_cheak:not(.item_cheak_city)')
					}
					if(that.hasClass('item_cheaked')){
						$.each(cheakDom,function(index, el) {
							if(!$(el).hasClass('item_cheaked')){
								$(el).addClass('item_cheaked')
							}
						});
					}else{
						$.each(cheakDom,function(index, el) {
							if($(el).hasClass('item_cheaked')){
							$(el).removeClass('item_cheaked')
							}
						});
					}
				}
				// 存一下数据
				var cheakDom = $('.item_cheak:not(.item_cheak_all,.item_cheak_city)')
				var cheakedDom = $('.item_cheaked:not(.item_cheak_all,.item_cheak_city)')
				if(that.hasClass('item_cheaked')){
					var tmpcheakedArr = []
					var tmpsameArr = []
					// 把选中的项目存一下
					$.each(cheakedDom,function(index, el) {
						var tmpObj = {}
						tmpObj._org_id = $(el).attr('_org_id')
						tmpObj._org_name = $(el).attr('_org_name')
						tmpcheakedArr.push(tmpObj)
					});
					// 数组去重
					$.each(orgArr,function(i,v){
					    var flag = true;
					    if(tmpcheakedArr.length > 0){
					        $.each(tmpcheakedArr,function(n,m){
					            if(tmpcheakedArr[n]._org_id == orgArr[i]._org_id){flag = false;};
					        });
					    };
					    if(flag){
					        tmpcheakedArr.push(orgArr[i]);
					    };
					});
					orgArr = tmpcheakedArr
				}else{
					if(that.hasClass('item_cheak_all')){
						var _orgArr = []
						$.each(cheakDom,function(i,v){
						    _orgArr.push($(v).attr('_org_id'))
						});
						orgArr = orgArr.filter(function (item) {
				            return _orgArr.indexOf(item._org_id) < 0;
				        })
					}else if(that.hasClass('item_cheak_city')){
						var _orgArr = []
						var dom = that.parent().parent().find('.item_cheak:not(.item_cheak_all,.item_cheak_city)')
						$.each(dom,function(i,v){
						    _orgArr.push($(v).attr('_org_id'))
						});
						orgArr = orgArr.filter(function (item) {
				            return _orgArr.indexOf(item._org_id) < 0;
				        })
					}else{
						var _org_id = that.attr('_org_id')
						var orgArrClone = orgArr.concat([])
						$.each(orgArrClone,function(index, el) {
							if(el._org_id == _org_id){
								orgArr.splice(index,1)
							}
						});
					}
				}
				//console.log(orgArr)
				// 渲染
				_this.rendOrgName()
			});
			// 删除项目
			$('body').on('click', '.org_close', function(event) {
				event.preventDefault();
				var that = $(this)
				var orgDom = $(this).parent()
				/* Act on the event */
				var _org_id = $(this).parent().attr('_org_id')
				var cheakDom = $('.item_cheak:not(.item_cheak_all,.item_cheak_city)')
				//更改数组
				var orgArrClone = orgArr.concat([])
				$.each(orgArrClone,function(index, el) {
					if(orgDom.attr('_org_id') == el._org_id ){
						orgArr.splice(index,1)
					}
				});
				//取消勾选
				$.each(cheakDom,function(index, el) {
					if($(el).hasClass('item_cheaked') && $(el).attr('_org_id') ==_org_id ){
						$(el).removeClass('item_cheaked')
					}
				});
				// 渲染
				_this.rendOrgName()
			});
		},
		ajaxSortOrg: function(obj,callback){
			_this = this
			$.ajax({
				url: contextPath + '/notice/appNotice/getOrgListByCity',
				type: "POST",
				dataType: "json",
				data: obj,
				success: function (data) {
					if(data.code == 200 && data.data){
						var dataObj = data.data
						if(jQuery.isEmptyObject(dataObj)){
							return
						}else{
							_this.renderSortList(dataObj)
							callback && callback();
						}
					}else{
						layer.msg(data.msg);
					}
				},
				error: function(err){

				}
			});
		},
		renderSortList: function(data){
			// 已选择的选中
			var html = ''
			var _orgArr = []
			$.each(orgArr,function(i,v){
			    _orgArr.push($(v).attr('_org_id'))
			});
			$.each(data,function(index, el) {
				html += '<li>'
				html +=  '<div class="org_city_wrap"><span class="item_cheak item_cheak_city"></span><span class="org_city">'+index+'</span></div>'
				$.each(el,function(_index, _el) {
					html += '<div class="sortOrg_cheak_wrap">'
					if(_orgArr.indexOf(_index) > -1){
						html += '<span class="item_cheak item_cheaked" _org_id="'+_index+'" _org_name="'+_el+'"></span>'
					}else{
						html += '<span class="item_cheak" _org_id="'+_index+'" _org_name="'+_el+'"></span>'
					}
					html += '<span class="org_name">'+_el+'</span>'		
					html += '</div>'
				})
				html += '</li>'
			});
			$('.org_list').empty().append(html)
		},
		rendOrgName:function(){
			var html = ''
			$.each(orgArr,function(index, el) {
				html += '<span class="orgName_span" _org_id="'+ el._org_id +'">'
				html += '<span class="org_close"></span>'
				html += el._org_name
				html += '</span>'
			});
			$('.orgName_div').empty().append('<span>已选项目：</span>' + html)
		},
	
		//渲染编辑器
		renderEditor: function () {
			//公告编辑器
			editorObj["myeditor_a_1"] = new UE.ui.Editor({
				imageActionName: 'ueAction',
				imageFieldName: "uploadfile",
				fileActionName: "ueAction",
				fileFieldName: "uploadfile",
				fileAllowFiles: [
					".png", ".jpg", ".jpeg", ".gif", ".bmp",
					".flv", ".swf", ".mkv", ".avi", ".rm", ".rmvb", ".mpeg", ".mpg",
					".ogg", ".ogv", ".mov", ".wmv", ".mp4", ".webm", ".mp3", ".wav", ".mid",
					".rar", ".zip", ".tar", ".gz", ".7z", ".bz2", ".cab", ".iso",
					".doc", ".docx", ".xls", ".xlsx", ".ppt", ".pptx", ".pdf", ".txt", ".md", ".xml"
				],
				imageAllowFiles: [".png", ".jpg", ".jpeg", ".gif", ".bmp"],
				/* 上传图片格式显示 */
				imageUrlPrefix: '' //contextPath
			});
			editorObj["myeditor_a_1"].render("myeditor_a_1");
			editorObj["myeditor_a_1"].ready(function () {
				editorObj["myeditor_a_1"].setHeight(400);
			});
			//生成链接编辑器
			editorB = new UE.ui.Editor({
				imageActionName: 'ueAction',
				imageFieldName: "uploadfile",
				fileActionName: "ueAction",
				fileFieldName: "uploadfile",
				fileAllowFiles: [
					".png", ".jpg", ".jpeg", ".gif", ".bmp",
					".flv", ".swf", ".mkv", ".avi", ".rm", ".rmvb", ".mpeg", ".mpg",
					".ogg", ".ogv", ".mov", ".wmv", ".mp4", ".webm", ".mp3", ".wav", ".mid",
					".rar", ".zip", ".tar", ".gz", ".7z", ".bz2", ".cab", ".iso",
					".doc", ".docx", ".xls", ".xlsx", ".ppt", ".pptx", ".pdf", ".txt", ".md", ".xml"
				],
				imageAllowFiles: [".png", ".jpg", ".jpeg", ".gif", ".bmp"],
				/* 上传图片格式显示 */
				imageUrlPrefix: '' //contextPath
			});
			editorB.render("myeditor_b");
			editorB.ready(function () {
				editorB.setHeight(400);
			});
			//banner的图文消息编辑器
			editorC = new UE.ui.Editor({
				imageActionName: 'ueAction',
				imageFieldName: "uploadfile",
				fileActionName: "ueAction",
				fileFieldName: "uploadfile",
				fileAllowFiles: [
					".png", ".jpg", ".jpeg", ".gif", ".bmp",
					".flv", ".swf", ".mkv", ".avi", ".rm", ".rmvb", ".mpeg", ".mpg",
					".ogg", ".ogv", ".mov", ".wmv", ".mp4", ".webm", ".mp3", ".wav", ".mid",
					".rar", ".zip", ".tar", ".gz", ".7z", ".bz2", ".cab", ".iso",
					".doc", ".docx", ".xls", ".xlsx", ".ppt", ".pptx", ".pdf", ".txt", ".md", ".xml"
				],
				imageAllowFiles: [".png", ".jpg", ".jpeg", ".gif", ".bmp"],
				/* 上传图片格式显示 */
				imageUrlPrefix: '' //contextPath
			});
			editorC.render("myeditor_c");
			editorC.ready(function () {
				editorC.setHeight(400);
			});
		},
		//发布公告绑定事件
		noticeBindEvent: function () {
			var _this = this;
			//上传图片
			$("#announcement #inputImage").on("change", function (e) {
				var $dom = $(this)
				// $(".alert").css("display","block")
				_this.uploadImage($dom, e)
			});
			//提交发送
			$("#announcement .submit-btn").on("click", function () {
				_this.noticeSubmit(1, $("#announcement"), 'add');
			});
			//预览
			$("#announcement .preview-btn").on("click", function () {
				_this.noticeSubmit(1, $("#announcement"), 'preview');
			})
		},

		//裁剪图片s


		//发布banner图文消息绑定事件
		bannerImageBindEvent: function () {
			var _this = this;
			//上传图片
			$("#graphic #inputImage").on("change", function (e) {
				var $dom = $(this)
				// $(".alert").css("display","block")
				_this.uploadImage($dom, e)
			});
			//提交发送
			$("#graphic .submit-btn").on("click", function () {
				_this.noticeSubmit(2, $("#graphic"), 'add');
			})
			//预览
			$("#graphic .preview-btn").on("click", function () {
				_this.noticeSubmit(2, $("#graphic"), 'preview');
			})
		},
		//发布banner跳转链接绑定事件
		bannerLinkBindEvent: function () {
			var _this = this;
			//上传图片
			$("#link #inputImage").on("change", function (e) {
				var $dom = $(this)
				// $(".alert").css("display","block")
				_this.uploadImage($dom, e)
			});
			//提交发送
			$("#link .submit-btn").on("click", function () {
				_this.noticeSubmit(3, $("#link"), 'add');
			})
			//预览
			$("#link .preview-btn").on("click", function () {
				_this.noticeSubmit(3, $("#link"), 'preview');
			})
		},
		//发布生成链接绑定事件
		produceLinkBindEvent: function () {
			var _this = this;
			//提交发送
			$("#line .submit-btn").on("click", function () {
				_this.noticeSubmit(4, $("#line"), 'add');
			});
			//预览
			$("#line .preview-btn").on("click", function () {
				_this.noticeSubmit(4, $("#line"), 'preview');
			})
		},
		/**
		 * 上传图片
		 * @param $dom 上传按钮dom
		 * @param e 上传文件信息
		 */
		uploadImage: function ($dom, e) {
			var _this = this;
			var fileName = e.target.value;
			var file = e.target.files[0];
			var size =  e.target.files[0].size;
			var suffixIndex = fileName.lastIndexOf(".");
			var suffix = fileName.substring(suffixIndex + 1).toUpperCase();
			fileType = suffix.toLowerCase();
			// console.log(fileType,222);
			if (suffix != "BMP" && suffix != "JPG" && suffix != "JPEG" && suffix != "PNG" && suffix != "GIF") {
				layer.msg('请上传图片（格式BMP、JPG、JPEG、PNG等）!');
				return false;
			};
		},
		/**
		 * 提交app公告
		 * @param type创建公告类型 1 公告 2 banner图文链接 3 banner跳转链接 4 生成链接
		 * @param $dom 
		 * @param func add新建 preview 预览
		 */
		noticeSubmit: function (type, $dom, func) {
			var _this = this;
			var formData = new FormData();
			var id = $("#noticeId").val();
			var editType = $("#editType").val();
			// if(editType == '' || editType != '2'){
			// 	formData.append("id", id);
			// }
			formData.append("id", id);

			//    	formData.append("id","");
			if (!!id) {
				noticeType = $("#state").val();
				formData.append("noticeType", noticeType);
			} else {
				formData.append("noticeType", noticeType);
			}

			if (noticeType == 1 || noticeType == 3) {
				formData.append("contentType", 1);
			} else {
				var contentType = $("#content").val();
				formData.append("contentType", contentType);
			}


			//项目选择
			var singleDom = $('.single-orgid')
			if(singleDom.length){
				var orgId = $("#orgId").val();
				if (!orgId) {
					layer.msg("请选择项目");
					return false;
				};
				formData.append("orgId", orgId);
			}else{
				if(!orgArr.length){
					layer.msg("请选择项目");
					return
				}
				var orgIdStr = ''
				$.each(orgArr,function(index, el) {
					orgIdStr += el._org_id + ',' 
				});	
				formData.append("orgIds", orgIdStr);
			}
			//封面图片
			if(type==1){
				let url = $(".announcement-item").eq(0).find("#showImg").data("url");
				if(!url){
					layer.msg("请上传封面图片");
					return false;
				};
				formData.append("coverUrl", url);
			}else if (type != 4) {
				let typeImg = "image/" + fileType;
				let coverFile;
				var picture = $dom.find("#showImg").attr("src");

				if (!picture) {
					if (type == 1) {
						layer.msg("请上传封面图片");
					} else {
						layer.msg("请上传banner图片");
					}
					return false;
				}
				if (!!id && picture.indexOf('data:image') <= -1) {
					formData.append("coverFile", "");
				} else {
					coverFile = upload(picture, typeImg || "image/png");
//					if (!coverFile) {
//						if (type == 1) {
//							layer.msg("请上传封面图片");
//						} else {
//							layer.msg("请上传banner图片");
//						}
//						return false;
//					};
					formData.append("coverFile", coverFile.get("pictures"));
				}

			}

			//主题
			if(type==1){
				var title = $(".announcement-item").eq(0).find(".title-con").val();
				if (!title) {
					layer.msg("请输入公告主题");
					return false;
				};
				formData.append("title", title);
			}else if (type != 3) {
				var title = $dom.find(".title-con").val();
				if (!title) {
					layer.msg("请输入公告主题");
					return false;
				};
				formData.append("title", title);
			}

			//正文
			var ue;
			if(type==1){
				ue = UE.getEditor($(".announcement-item").eq(0).find(".u_editor").attr("id"));
				var content = ue.getContent(); //发件主题
				var contentTxt = ue.getContentTxt();
				if (!content) {
					layer.msg("请输入公告正文");
					return false;
				};
				formData.append("content", content);
				formData.append("contentTxt", contentTxt);
			}else if (type != 3) {
				if (type == 1) {
					ue = UE.getEditor('myeditor_a_1');
				} else if (type == 2) {
					ue = UE.getEditor('myeditor_c');
				} else if (type == 4) {
					ue = UE.getEditor('myeditor_b');
				}

				var content = ue.getContent(); //发件主题
				var contentTxt = ue.getContentTxt();
				if (!content) {
					layer.msg("请输入公告正文");
					return false;
				};
				formData.append("content", content);
				formData.append("contentTxt", contentTxt);
			}

			//摘要
			if(type==1){
				var summaryInfo = $(".announcement-item").eq(0).find(".summary-con").val();
				formData.append("summaryInfo", summaryInfo);
			}else if (type == 1) {
				var summaryInfo = $dom.find(".summary-con").val();
				formData.append("summaryInfo", summaryInfo);
			}
			
			//发布端口
			var  isPublic=0;//是否训中公众号
			var  isWechat=0;//是否选中微信
			var   isApp=0;//是否选中app
			if (type != 4 && func == 'add') {
				var positionTypeArr = [];
				if (type == 1) {
					//$dom.find("input[type='checkbox']").is(':checked')
					if ($dom.find('input:checkbox[name="app"]').prop("checked")) {
						positionTypeArr.push(1);
						isApp = 1;
					};
					if ($dom.find('input:checkbox[name="wx"]').prop("checked")) {
						positionTypeArr.push(2);
						isWechat = 1
					};
					if ($dom.find('input:checkbox[name="public"]').prop("checked")) {//选择公众号
						isPublic = 1;
						positionTypeArr.push(3);
						if(!$dom.find("input:radio[name='public']:checked").data("type")){
							layer.msg("请选择发布对象");
							return false;
						}else if($dom.find("input:radio[name='public']:checked").data("type")==3){
							if($(".person-item").length ==0 || $(".person-item").length <1){
								layer.msg("请选择用户,且用户不得少于两个！！");
								return false;
							}else{
								var useridArr =[];
								var openidArr = [];
								$(".person-item").each(function(index,ele){
									useridArr.push($(ele).data("userid"));
									openidArr.push($(ele).data("openid"));
								})
								formData.append("openIds", openidArr.join(","));
								formData.append("userIds", useridArr.join(","));
							}
						}
						var  publicObj = $dom.find("input:radio[name='public']:checked").data("type");//公众号发布对象:1-公众号所有用户；2-项目所有用户；3-部分用户；
						formData.append("publicObj", publicObj);
						var  isMessageList = $dom.find("input:radio[name='msg']:checked").data("type") ? 1  : 0 ;//是否加入消息列表0-否1-是
						
						formData.append("isMessageList", isMessageList);
					};
				} else if (type == 2) {
					if(noticeType == 5){
						isApp = 0;
						isWechat = 1;
						positionTypeArr.push(2);
					}else{
						if ($dom.find('input:checkbox[name="app2"]').prop("checked")) {
							positionTypeArr.push(1);
							isApp = 1;
						};
						if ($dom.find('input:checkbox[name="wx2"]').prop("checked")) {
							positionTypeArr.push(2);
							isWechat = 1
						};
					}
					if ($dom.find('input:checkbox[name="public2"]').prop("checked")) {
						isPublic = 1;
						positionTypeArr.push(3);
						if(!$dom.find("input:radio[name='public1']:checked").data("type")){
							layer.msg("请选择发布对象");
							return false;
						}else if($dom.find("input:radio[name='public1']:checked").data("type")==3){
//							alert(1)
						}else{
							var  publicObj = $dom.find("input:radio[name='public1']:checked").data("type");//公众号发布对象:1-公众号所有用户；2-项目所有用户；3-部分用户；
							formData.append("publicObj", publicObj);
							console.log('publicObj',publicObj);
							var  isMessageList = $dom.find("input:radio[name='msg1']:checked").data("type") ? 1  : 0 ;//是否加入消息列表0-否1-是
							formData.append("isMessageList", isMessageList);
							console.log('isMessageList',isMessageList);
						}
					};
				} else if (type == 3) {
					if(noticeType == 5){
						isApp = 0;
						isWechat = 1;
						positionTypeArr.push(2);
					}else{
						if ($dom.find('input:checkbox[name="app3"]').prop("checked")) {
							positionTypeArr.push(1);
							isApp = 1;
						};
						if ($dom.find('input:checkbox[name="wx3"]').prop("checked")) {
							isWechat = 1
							positionTypeArr.push(2)
						}
					}
				}
				if (positionTypeArr.length == 0) {
					layer.msg("请选择发布端口");
					return false;
				} else if (positionTypeArr.length == 1) {
					positionType = positionTypeArr.join(",")
				}else if(positionTypeArr.length == 3){
					positionType = 6;
				}else if(positionTypeArr.length == 2){
					if((positionTypeArr.indexOf(1) !=-1) && (positionTypeArr.indexOf(2) !=-1 ) ){
						positionType = 0;
					}else if((positionTypeArr.indexOf(2)  !=-1) && (positionTypeArr.indexOf(3) !=-1 )){
						positionType = 4;
					}else if((positionTypeArr.indexOf(1)  !=-1) && (positionTypeArr.indexOf(3) !=-1 )){
						positionType = 5;
					}
				}
				//positionType 展示位置 0-微信+app端/1-app端/2-微信/3-公众号/4-微信+公众号/5-app+公众号/6-微信+app+公众号
				
				formData.append("isPublic", isPublic);
				formData.append("isWechat", isWechat);
				formData.append("isApp", isApp);
				formData.append("positionType", positionType);

				//添加审核类型
				formData.append("approvalType", $("#approvalType").val()?$("#approvalType").val():'');

				console.log('positionType',positionType);
				console.log('isPublic',isPublic);
				console.log('isWechat',isWechat);
				console.log('isApp',isApp);
				
			};
			if(type ==1){
				//!!id
				var noticeDetailList = [];
				$(".announcement-item").each(function(index,ele){
					var ue = UE.getEditor($(ele).find(".u_editor").attr("id"));
					var title = $(ele).find(".title-con").val();
					var coverUrl = $(ele).find("#showImg").data("url");
					var content = ue.getContent(); //发件主题
					var contentTxt = ue.getContentTxt();
					if(title && content && coverUrl ){
						noticeDetailList.push({
							id: $(ele).data("id") ? $(ele).data("id") : '',
							title: title,
							coverUrl: coverUrl,
							summaryInfo: $(ele).find(".summary-con").val(),
							position: index,
							content: content,
							contentTxt: contentTxt,
						})
					}
					
				});
				formData.append("noticeDetailList", JSON.stringify(noticeDetailList));
			}
			
			// 跳转链接
			if (type == 3) {
				var url_address = $dom.find(".link-con").val();
				if (!url_address) {
					layer.msg("请输入跳转链接");
					return false;
				}else{
					var regTxt = url_address.match(/^http:\/\//);
					var regTxts = url_address.match(/^https:\/\//);
					if(regTxt||regTxts){
						formData.append("url_address", url_address);
					}else{
						layer.msg("请输入正确的跳转链接");
						return false;
					}
				}
			}
			// if (type == 3) {
			// 	var url_address = $dom.find(".link-con").val();
			// 	if (!url_address) {
			// 		layer.msg("请输入跳转链接");
			// 		return false;
			// 	}
			// 	formData.append("url_address", url_address);
			// }
				//调用审核功能
			
			if (func == 'add') {
				_this.ajaxCreateApp(type, formData, ue, $dom);
			} else {
				_this.previewPhone(type);
			}

		
		},
		// 调用审核功能接口 ，就是之前的发布接口加上New

		postApprovel(){
			var _this=this
			var id = _this.getQueryString("id")
			console.log("postApprovel",id)
			var type = $(".radio-item.status:checked").data("status")
			var auditOpinion = $(".summary-con-wx").val()
			console.log("type",type)
			console.log("auditOpinion",auditOpinion)
			$.ajax({
				type: "post",
				async:false,
				url: contextPath + "/notice/appNotice/approvalAppNoticeNew",
				data: {
					"id": id,
					"state": type,
					"approvalOpinion":auditOpinion
				},
				success: function (data) {
					console.log("返回",data.code)
		        	if (data.code == '200') {
		    			 console.log("返回",'11111')
		    			 layer.msg('审核成功！')
		    			 window.location.href = contextPath + '/notice/audit/noticeAppVerify';
					} else {
						console.log("返回",data.code=='100')
						layer.msg(data.msg)
					}
				},
				error: function (error) {
					layer.msg('审核失败')
				}
			});
		},
		/**
		 * 发请求创建新的app公告
		 * @param formdata 提交的数据
		 * @param type 创建公告类型 1 公告 2 banner图文链接 3 banner跳转链接 4 生成链接
		 * @param $dom
		 * @param ue 编辑器
		 */
		ajaxCreateApp: function (type, formData, ue, $dom) {

            var _this=this
			var id ;
			var editType = $("#editType").val();
			console.log("editType",editType)
			if(editType == '' || editType != '2' ){
				id = $("#noticeId").val();
			}
			id = $("#noticeId").val();
			$.ajax({
				type: "post",
				url: contextPath + "/notice/appNotice/saveUpdateAppNotice",
				data: formData,
				cache: false, // 不缓存
				processData: false, // 告诉jQuery不要去处理发送的数据
				contentType: false, // 告诉jQuery不要去设置Content-Type请求头
				success: function (data) {
					_this.postApprovel();
					if (data.code == ERROR_OK) {
						if (!!id) {
							window.location.href = contextPath + '/notice/audit/noticeAppVerify';
						} else {
							type != 3 && ue.setContent('');
							if (type != 4) {
								$dom.find(".upload-input").data("file", "");
								$dom.find(".img-wrapper").css("background-image", "url(../images/admin/notice_cover.png)");
							}
							if (type != 3) {
								$dom.find(".title-con").val("");
							}
							if (type == 1) {
								announceArr =[];//临时存储搜素对象数组
								num = 1;//新增公告多少次
								editorObj = {};
								$dom.find(".summary-con").val("");
								$(".small-notice-item:not(:first)").remove();
								$(".small-notice-item").addClass("current");
								$(".s-notice-title").html("标题");
								$(".s-notice-cover").css("background-image", "url(../images/back_gray_big.png)");
								$(".announcement-item:not(:first)").remove();
								$(".announcement-item").show();
								$("#announcement .public-extra-wp").hide();
								$("#announcement").find("input:checkbox[name='public']").prop('checked', false);
								$("#announcement").find("input:radio[name='public']:first").prop('checked', true);
								 $("#announcement .search-wp").remove();
							}
							if (type != 4) {
								$dom.find('input:checkbox').attr("checked", false);
							}
							if (type == 3) {
								$dom.find(".link-con").val("");
							};
							if (type == 4) {
								$(".produce-link-wp ").show();
								$(".produce-link-con").val(data.data.url_address);
								layer.msg("生成链接成功！")
							} else {
								layer.msg("提交发送成功！")
							}
						}


					} else {
						layer.msg(data.msg)
					}
				},
				error: function () {

					layer.msg('error')
				}
			});
		},
		/**
		 * 预览
		 * @param type 创建公告类型 1 公告 2 banner图文链接 3 banner跳转链接 4 生成链接
		 */
		previewPhone: function (type) {
			if (type == 1) {
				var $index = $(".small-notice-item.current").index();
				
//				var notice = {
//					banner: $(".announcement-item").eq($index).find("#showImg").attr("src"),
//					title: $(".announcement-item").eq($index).find(".title-con").val(),
//					con: UE.getEditor($(".announcement-item").eq($index).find(".u_editor").attr("id")).getContent(),
//					showTip: true
//				};
				var noticeDetailList = [];
				$(".announcement-item").each(function(index,ele){
					var ue = UE.getEditor($(ele).find(".u_editor").attr("id"));
					var title = $(ele).find(".title-con").val();
					var coverUrl = $(ele).find("#showImg").data("url");
					var content = ue.getContent(); //发件主题
					var contentTxt = ue.getContentTxt();
					if(title && content && coverUrl ){
						noticeDetailList.push({
							banner: coverUrl,
							title: title,
							con: content,
							//showTip: true
						})
					}
					
				});
				var noticeDetail = {
					type: 'detail',
					title: $(".announcement-item").eq($index).find(".title-con").val(),
					con: UE.getEditor($(".announcement-item").eq($index).find(".u_editor").attr("id")).getContent(),
					showTip: true,
				}
				var app = {
					type: 'main',
					title: $(".announcement-item").eq($index).find(".title-con").val(),
					con: UE.getEditor($(".announcement-item").eq($index).find(".u_editor").attr("id")).getContent(),
				}
				//公告微信端
				$("body").append(template.render(tpl.noticeListTpl)({list: noticeDetailList,showTip: true}));

				//公告app端
				$("body").append(template.render(tpl.noticeDetailTpl)(noticeDetail));

				//公告详情
				$("body").append(template.render(tpl.noticeDetailTpl)(app));

				var $wx = $(".notice-list-tpl");
				var $wxDetail = $(".notice-detail-tpl-detail");
				var $app = $(".notice-detail-tpl-main");
				$wxDetail.hide();
				$app.hide();
				//点击banner跳转
				$wx.find(".banner-wp").on("click", function () {
					$wxDetail.show();
					$app.hide();
					$wx.hide();
				});
				//点击返回
				$wxDetail.find(".back-btn").on("click", function () {
					$wxDetail.hide();
					$app.hide();
					$wx.show();
				});
				//tab切换
				$wx.find(".tab-right").on("click", function () {
					$wxDetail.hide();
					$app.show();
					$wx.hide();
				});
				$wxDetail.find(".tab-right").on("click", function () {
					$wxDetail.hide();
					$app.show();
					$wx.hide();
				});
				$app.find(".tab-left").on("click", function () {
					$wxDetail.hide();
					$app.hide();
					$wx.show();
				});
			} else if (type == 2) {
				var wx = {
					banner: $("#graphic #showImg").attr("src"),
					title: $("#graphic .title-con").val(),
					con: UE.getEditor('myeditor_c').getContent(),
					showTip: true
				};
				var wxDetail = {
					type: 'detail',
					title: $("#graphic .title-con").val(),
					con: UE.getEditor('myeditor_c').getContent(),
					showTip: true,
				}
				var app = {
					banner: $("#graphic #showImg").attr("src"),
					title: $("#graphic .title-con").val(),
					con: UE.getEditor('myeditor_c').getContent(),
					showTip: true,
				}
				var appDetail = {
					type: 'main',
					title: $("#graphic .title-con").val(),
					con: UE.getEditor('myeditor_c').getContent(),
					showTip: true,
				};
				//图文微信端
				$("body").append(template.render(tpl.wxTpl)(wx));

				//图文app端
				$("body").append(template.render(tpl.appTpl)(app));

				//图文微信端详情
				$("body").append(template.render(tpl.noticeDetailTpl)(wxDetail));

				//图文app端详情
				$("body").append(template.render(tpl.noticeDetailTpl)(appDetail));
				var $wx = $(".wx-tpl");
				var $wxDetail = $(".notice-detail-tpl-detail");
				var $app = $(".app-tpl");
				var $appDetail = $(".notice-detail-tpl-main");
				$wxDetail.hide();
				$app.hide();
				$appDetail.hide();
				//微信端和APP段banner跳转
				$wx.find(".banner-wp").on("click", function () {
					$wx.hide();
					$wxDetail.show();
					$app.hide();
					$appDetail.hide();
				});
				$app.find(".banner-wp").on("click", function () {
					$wx.hide();
					$wxDetail.hide();
					$app.hide();
					$appDetail.show();
				});
				//点击返回
				$wxDetail.find(".back-btn").on("click", function () {
					$wx.show();
					$wxDetail.hide();
					$app.hide();
					$appDetail.hide();
				});
				$appDetail.find(".back-btn").on("click", function () {
					$wx.hide();
					$wxDetail.hide();
					$app.show();
					$appDetail.hide();
				});
				//tab切换
				$wx.find(".tab-right").on("click", function () {
					$wx.hide();
					$wxDetail.hide();
					$app.show();
					$appDetail.hide();
				});
				$wxDetail.find(".tab-right").on("click", function () {
					$wx.hide();
					$wxDetail.hide();
					$app.show();
					$appDetail.hide();
				});
				$app.find(".tab-left").on("click", function () {
					$wx.show();
					$wxDetail.hide();
					$app.hide();
					$appDetail.hide();
				});
				$appDetail.find(".tab-left").on("click", function () {
					$wx.show();
					$wxDetail.hide();
					$app.hide();
					$appDetail.hide();
				});
			} else if (type == 3) {
				var wx = {
					banner: $("#link #showImg").attr("src")
				};
				var app = {
					banner: $("#link #showImg").attr("src")
				}
				//图文微信端
				$("body").append(template.render(tpl.wxTpl)(wx));

				//图文app端
				$("body").append(template.render(tpl.appTpl)(app));

				var $wx = $(".wx-tpl");

				var $app = $(".app-tpl");
				$app.hide();

				//tab切换
				$wx.find(".tab-right").on("click", function () {
					$wx.hide();

					$app.show();

				});
				$app.find(".tab-left").on("click", function () {
					$wx.show();

					$app.hide();

				});
			} else if (type == 4) {
				var noticeDetail = {
					type: 'detail',
					title: $("#line .title-con").val(),
					con: UE.getEditor('myeditor_b').getContent(),
					showTab: true,
				};
				//公告详情
				$("body").append(template.render(tpl.noticeDetailTpl)(noticeDetail));
			};
			$(".notice-mask,.notice-close-btn").on("click", function () {
				$(".notice-wrapper").remove();
			})
		},
		getQueryString: function (name) {
			var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
			var r = window.location.search.substr(1).match(reg);
			if (r != null) return unescape(r[2]);
			return null;
		},
		/*获取详情*/
		ajaxDetail: function (id) {
			var _this = this;
			$.ajax({
				type: "post",
				url: contextPath + "/notice/appNotice/getDetail",
				data: {
					"id": id
				},
				success: function (data) {
					if (data.code == 200) {
						_this.renderNotice(data.data)
						_this.getProjectList()
					} else {
						layer.msg(data.msg)
					}
				},
				error: function (error) {
					layer.msg('error')
				}
			});
		},
		/**
		 * 复现公告
		 * @param data 详情数据
		 */
		renderNotice: function (data) {
			var _this = this;
			state = data.state;
			$("#noticeId").val(data.id);
			_this.detailApproveTyp=data.approvalType
			console.log("111",data.approvalType)

			//$("#orgId").val(data.orgId);
			//noticeType 公告类型： 1 公告 ；2 banner图；3 跳转链接 5 楼闪送banner
			//选择公告和跳转链接时contentType传1
			//图文类型contentType： 1 图文消息 ；2 跳转链接
			if (data.noticeType == 1) {
				projectOrgId = !!data.orgId ? data.orgId+',' : data.orgIds;
//				if(data.orgIds){
					//console.log('length',$(".item_cheak ").length);
					//_org_id
					var orgArr = projectOrgId.split(',');
					if($(".item_cheak ").length >0){
						$.each(orgArr,function(oIndex,oVal){
							$(".sortOrg_cheak_wrap .item_cheak").each(function(ind,ele){
								if($(ele).attr("_org_id")==oVal+''){
									$(ele).click();
								}
							})
						})
					}
					
//				}
				$("#state").val(data.noticeType)
				//picture = data.coverUrl;
				$(".announcement-item .img-wrapper").css("background-image", "url(" + data.coverUrl + ")");
				$(".app-publish-wrapper").eq(0).show().siblings().hide();
				$(".choose-publish-con").hide();
				$(".announcement-item .title-con").val(data.title);
				$(".announcement-item #showImg").attr("src",data.coverUrl )
				$(".announcement-item #showImg").data("url",data.coverUrl )
				editorObj["myeditor_a_1"].ready(function () {
					var ue = UE.getEditor('myeditor_a_1');
					ue.setContent(data.content);
				})
				$(".small-notice-item .s-notice-cover").css("background-image", "url(" + data.coverUrl + ")");
				$(".small-notice-item .s-notice-title").html(data.title);
				$("#announcement .edit-back-btn").show();
				$(".announcement-item").data("id",data.detailList[0].id);
				$(".announcement-item .summary-con").val(data.summaryInfo);
				//positionType isPublic isWechat isApp publicObj  isMessageList
				if(data.detailList.length > 0){
					_this.addNoticeEvent(2,data.detailList)
				}
				if (data.positionType == 0) {
					$('#announcement input:checkbox[name="app"]').prop("checked", true);
					$('#announcement input:checkbox[name="wx"]').prop("checked", true);
				} else if (data.positionType == 1) {
					$('#announcement input:checkbox[name="app"]').prop("checked", true);
				} else if (data.positionType == 2) {
					$('#announcement input:checkbox[name="wx"]').prop("checked", true)
				}else if(data.positionType == 3){
					$("#announcement .public-extra-wp").show();
					$('#announcement input:checkbox[name="public"]').prop("checked", true)
				};
				if(data.isPublic == 1){
					$(".public-extra-wp").show();
					$('#announcement input:checkbox[name="public"]').prop("checked", true);
					if(data.publicObj==1){
						
						$('#announcement input:radio[name="public"]').eq(0).prop("checked", true);
					}else if(data.publicObj==2){
						var $dom = permPublish ? $('#announcement input:radio[name="public"]').eq(1) : $('#announcement input:radio[name="public"]').eq(0)
						$dom.prop("checked", true);
					}else if(data.publicObj==3){
						var $dom = permPublish ? $('#announcement input:radio[name="public"]').eq(2) : $('#announcement input:radio[name="public"]').eq(1)
						   $dom.prop("checked", true);
						//$('#announcement input:radio[name="public"]').eq(2).prop("checked", true);
						$("#announcement .search-select-wp").html(template.render(tpl.searchTpl));
						announceArr =[]
						_this.getProjectSearch($(".search-select-wp"),2,function(allData){
				        	_this.searchChooseEvent(2,$(".search-select-wp"),allData,data.userIds)
				        });
					};
					if(data.isMessageList ==1){
						$('#announcement input:radio[name="msg"]').eq(0).prop("checked", true);
					}else{
						$('#announcement input:radio[name="msg"]').eq(1).prop("checked", true);
					}
				};
				if(data.isWechat == 1){
					$('#announcement input:checkbox[name="wx"]').prop("checked", true)
				};
				if(data.isApp == 1){
					$('#announcement input:checkbox[name="app"]').prop("checked", true)
				};
				
				if(data.state == 1){
					$(".add-notice-wp").hide();
					$(".notice-operate-wp").hide();
					// $(".upload-btn-wp").hide();
					// $('#announcement input:checkbox[name="app"]').attr("disabled", true);
					// $('#announcement input:checkbox[name="wx"]').attr("disabled", true);
					// $('#announcement input:checkbox[name="public"]').attr("disabled", true);
					// $('#announcement input:radio[name="public"]').attr("disabled", true);
					// $('#announcement input:radio[name="msg"]').attr("disabled", true);
				}
			} else if ((data.noticeType == 2 || data.noticeType == 5) && data.contentType == 1) {
				
				projectOrgId = !!data.orgId ? data.orgId+',' : data.orgIds;
				var orgArr = projectOrgId.split(',');
				if($(".item_cheak ").length >0){
					$.each(orgArr,function(oIndex,oVal){
						$(".sortOrg_cheak_wrap .item_cheak").each(function(ind,ele){
							if($(ele).attr("_org_id")==oVal+''){
								$(ele).click();
							}
						})
					})
				}
				
				$("#state").val(data.noticeType)
				$("#content").val(1);
				
				$("#graphic #showImg").attr("src",data.coverUrl)
				$(".img-wrapper").css("background-image", "url(" + data.coverUrl + ")");
				$(".app-publish-wrapper").eq(3).show().siblings().hide();
				if(data.noticeType == 5){
					$(".app-publish-wrapper").eq(3).find('.port-wp').css('visibility','hidden');
				}
				$(".choose-publish-con").show();
				$("#graphic .title-con").val(data.title);
				$("#graphic .edit-back-btn").show();
				editorC.ready(function () {
					var ue = UE.getEditor('myeditor_c');
					ue.setContent(data.content);
				})
				if (data.positionType == 0) {
					$('input:checkbox[name="app2"]').prop("checked", true);
					$('input:checkbox[name="wx2"]').prop("checked", true)
				} else if (data.positionType == 1) {
					$('input:checkbox[name="app2"]').prop("checked", true);

				} else if (data.positionType == 2) {
					$('input:checkbox[name="wx2"]').prop("checked", true)
				}
				if(data.isPublic == 1){
					$('#graphic input:checkbox[name="public2"]').prop("checked", true);
					if(data.publicObj==1){
						$('#graphic input:radio[name="public1"]').eq(0).prop("checked", true);
					}else if(data.publicObj==2){
						$('#graphic input:radio[name="public1"]').eq(1).prop("checked", true);
					}else if(data.publicObj==3){
						$("#graphic .public-extra-wp").show();
						$('#graphic input:radio[name="public1"]').eq(2).prop("checked", true);
					};
					if(data.isMessageList ==1){
						$('#graphic input:radio[name="msg1"]').eq(0).prop("checked", true);
					}else{
						$('#graphic input:radio[name="msg1"]').eq(1).prop("checked", true);
					}
				};
				if(data.isWechat == 1){
					$('#graphic input:checkbox[name="wx2"]').prop("checked", true)
				};
				if(data.isApp == 1){
					$('#graphic input:checkbox[name="app2"]').prop("checked", true)
				};
			} else if ((data.noticeType == 2 || data.noticeType == 5) && data.contentType == 2) {
				
				projectOrgId = !!data.orgId ? data.orgId+',' : data.orgIds;
				var orgArr = projectOrgId.split(',');
				if($(".item_cheak ").length >0){
					$.each(orgArr,function(oIndex,oVal){
						$(".sortOrg_cheak_wrap .item_cheak").each(function(ind,ele){
							if($(ele).attr("_org_id")==oVal+''){
								$(ele).click();
							}
						})
					})
				}
				
				$("#state").val(data.noticeType)
				$("#content").val(2);
				$("#link #showImg").attr("src",data.coverUrl)
				$(".img-wrapper").css("background-image", "url(" + data.coverUrl + ")");
				$(".app-publish-wrapper").eq(2).show().siblings().hide();
				if(data.noticeType == 5){
					$(".app-publish-wrapper").eq(2).find('.port-wp').css('visibility','hidden');
				}
				$(".choose-publish-con").show();
				$(".link-con").val(data.urlAddress);
				if (data.positionType == 0) {
					$('input:checkbox[name="app3"]').prop("checked", true);
					$('input:checkbox[name="wx3"]').prop("checked", true)
				} else if (data.positionType == 1) {
					$('input:checkbox[name="app3"]').prop("checked", true);

				} else if (data.positionType == 2) {
					$('input:checkbox[name="wx3"]').prop("checked", true)
				}
			} else if (data.noticeType == 3) {
				
				projectOrgId = !!data.orgId ? data.orgId+',' : data.orgIds;
				var orgArr = projectOrgId.split(',');
				if($(".item_cheak ").length >0){
					$.each(orgArr,function(oIndex,oVal){
						$(".sortOrg_cheak_wrap .item_cheak").each(function(ind,ele){
							if($(ele).attr("_org_id")==oVal+''){
								$(ele).click();
							}
						})
					})
				}
				
				$("#state").val(data.noticeType)
				$(".app-publish-wrapper").eq(1).show().siblings().hide();
				$(".choose-publish-con").hide();
				$("#line .title-con").val(data.title);
				editorB.ready(function () {
					var ue = UE.getEditor('myeditor_b');
					ue.setContent(data.content);
				})
			}
		},
		/*
		 * 搜索事件
		 * @param type 1-公告 2-图文
		 */
		searchEvent(type){
			var _this = this;
			$('.s-input').keydown(function(e){
				var $dom = $(this).closest(".search-select-wp")
			    if(e.keyCode==13){
			        _this.getProjectSearch($dom,1,function(data){
			        	var idArr = []
			        	for(var i=0;i<announceArr.length;i++){
			        		idArr.push(announceArr[i].userId)
			        	}
			        	_this.searchChooseEvent(1,$dom,data,idArr)
			        });
			    }
			});
			$(".s-icon").on("click",function(){
				var $dom = $(this).closest(".search-select-wp")
				_this.getProjectSearch($dom,1,function(data){
					var idArr = []
		        	for(var i=0;i<announceArr.length;i++){
		        		idArr.push(announceArr[i].userId)
		        	}
		        	_this.searchChooseEvent(1,$dom,data,idArr)
		        });
			})
		},
		/**
		 * 点击搜索或者enter触发事件 //根据项目获取部分用户
		 * @param $dom 搜索框的父元素
		 * @param type 1-正常搜索 2-复现搜索
		 * @param callback 回调，搜索框的事件
		*/
		getProjectSearch($dom,type,callback){
			
			var _this = this;
			if(type==1){
				_this.renderSearchList();
			}
			
			
			$.ajax({
				url: contextPath + '/notice/publicno/getUserByOrgId',
				type: "POST",
				dataType: "json",
				data: {
					orgIds: projectOrgId,//项目Id 以逗号分隔 最后面不要带逗号
					name: $(".search-wp .s-input").val(),//姓名、手机号、项目名 模糊搜索，默认传""
				},
				success: function (data) {
					if(data.code == 200 && data.data){
						callback(data.data)
					}else{
						layer.msg(data.msg);
					}
				},
				error: function(err){

				}
			});
		},
		/**
		 * 搜索事件
		 * @param type 1-正常搜索 2-复现搜索
		 * @param $dom 搜索框的父元素
		 * @param projectList 项目部分数据数组
		 */
		searchChooseEvent: function(type,$dom,projectList,chooseUserIds){
			var _this = this;
			if(type==1){
				$dom.find(".project-person-list").html(template.render(tpl.projectTpl)({list: projectList,userIds:chooseUserIds.join(',').split(',')}));
			}else{
				
				$dom.find(".project-person-list").html(template.render(tpl.projectTpl)({list: projectList,userIds:chooseUserIds.split(',')}));
				$.each(projectList,function(ind,val){
					if((chooseUserIds.split(',')).indexOf(val.userId+'') !=-1){
						announceArr.push({
							userId:val.userId,
							openId:val.openId,
							name: val.name,
							mobile:val.mobile
						});
					}
				});
				$dom.find(".choosed-person-wp").html(template.render(tpl.chooseTpl)({list: announceArr}));
				//删除选择用户
				if(state!=1){
					$(".peoject-del-btn").on("click",function(){
						var userId = $(this).data("userid");
						$(this).closest(".person-item").remove();
						var arr = [];//临时数组
						$.each(announceArr,function(index,value){
							if(value.userId != userId){
								arr.push(value);
							}
						});
						announceArr = arr;
						$("#announcement #project-"+userId).prop("checked", false);
						if(announceArr.length==0){
							$dom.find(".choosed-person-wp").html("")
						}
					})
				}
				
			}
			if(state==1){
				$dom.find(".check-item").attr("disabled",true)
			}

			$dom.find(".check-item").on("click",function(){
				var userId = $(this).data("userid");
				var openId = $(this).data("openid");
				var name = $(this).data("name");
				var mobile = $(this).data("mobile");
				//点击选择用户
				if($(this).prop("checked")){
					announceArr.push({
						userId:userId,
						openId:openId,
						name: name,
						mobile:mobile
					});
					$dom.find(".choosed-person-wp").html(template.render(tpl.chooseTpl)({list: announceArr}));
					console.log('before',announceArr)
					announceArr = _this.removalArr(announceArr);
					console.log('after',announceArr)
				}else{
					var arr = [];//临时数组
					$.each(announceArr,function(index,value){
						if(value.userId != userId){
							arr.push(value);
						}
					});
					announceArr = arr;
					$dom.find(".choosed-person-wp").html(template.render(tpl.chooseTpl)({list: announceArr}));
					if(announceArr.length==0){
						$dom.find(".choosed-person-wp").html("")
					}
				};
				//删除选择用户
				$(".peoject-del-btn").on("click",function(){
					var userId = $(this).data("userid");
					$(this).closest(".person-item").remove();
					var arr = [];//临时数组
					$.each(announceArr,function(index,value){
						if(value.userId != userId){
							arr.push(value);
						}
					});
					announceArr = arr;
					$("#announcement #project-"+userId).prop("checked", false);
					if(announceArr.length==0){
						$dom.find(".choosed-person-wp").html("")
					}
				})
			})
		},
		 /**
	     * 对象数组去重
	     */
		removalArr: function  (arrData){
			var hash = {};
			arrData = arrData.reduce(function(item, next) {
			    hash[next.name] ? '' : hash[next.name] = true && item.push(next);
			    return item
			}, [])
			return arrData;
		},  
		/**
		 * 公告新增绑定事件
		 * 
		 */
		noticeAddEvent:function(){
			var _this = this;
			
			_this.switchEvent($(".small-notice-item"));
			_this.moveEvent($(".small-notice-item"));
			_this.inputEvent($(".announcement-item .title-con"));
			//small-notice-list
			//新增公告
			$(".add-notice-btn").on("click",function(){
				
				_this.addNoticeEvent(1)
			})
		},
			//调用项目列表接口，如果是1个的话就显示审核
			getProjectList(){
				var _this = this
				$.ajax({
					type: "post",
					url: contextPath+ "/admin/templ/getOrgList",
					success: function (data) {
						if (data.code == 200) {
							if(data.data.length==1){
								_this.getIfCanApproval(data.data[0].id)
							}
						} 
					},
					error: function (error) {
						layer.msg('error')
					}
				});
			},
			getApprovalTypeList(orgId){
				var _this=this
				$.ajax({
					type: "post",
					url: contextPath+ "/notice/approval/getApprovalType",
					data: {
						"orgId": orgId
					},
					success: function (data) {
						if (data.code == 200) {
							$("#approvalType").html(template.render(tpl.typeTpl)(data));
							$("#approvalType").val(_this.detailApproveTyp)
						} else {
							layer.msg(data.msg)
						}
					},
					error: function (error) {
						layer.msg('error')
					}
				});
			},
			getIfCanApproval(orgId){
				var _this=this
				$.ajax({
					type: "post",
					url: contextPath+ "/notice/approval/getSetByOrgId",
					data: {
						"orgId":orgId
					},
					success: function (data) {
						if (data.code == 200) {
							if(data.data.isOpen==1){//显示审核下拉列表
								$(".approvalStyle").show();
								_this.getApprovalTypeList(orgId)
							}else{////不显示审核下拉列表
								$(".approvalStyle").hide();
	
							}
						} else {
							layer.msg(data.msg)
						}
					},
					error: function (error) {
						layer.msg('error')
					}
				});
			},
		/**
		 * //上移下移
		 * @param $dom 每个item
		 * 1. 获取元素  $downBtn $upBtn
		 * 2.上移： 循环给每个$upBtn添加点击事件
		 * 3.下移： 循环给每个$downBtn加点击事件
		 */
		moveEvent($dom){
			var _this = this;
			//获取元素oList $upBtn $downBtn
			
			var $upBtn = $dom.find(".n-up-bnt");
			var $downBtn = $dom.find(".n-down-bnt");
			//上移
			$upBtn.on("click",function(e){
				var $item = $(this).closest(".small-notice-item");
				var $index = $(this).closest(".small-notice-item").index();
				var $announcementItem = $(".announcement-item").eq($index);
				$item.prev().before($item);
				$announcementItem.prev().before($announcementItem);
			});
			//下移
			$downBtn.on("click",function(e){
				var $item = $(this).closest(".small-notice-item");
				var $index = $(this).closest(".small-notice-item").index();
				var $announcementItem = $(".announcement-item").eq($index);
				$item.next().after($item);
				$announcementItem.next().after($announcementItem);
			});
		},
		/**
		 * //各个公告切换选中样式，上移和下移
		 * * @param $dom 每个item
		 * 
		 */
		
		switchEvent: function($dom){
			$dom.on("click",function(){
				var index = $dom.index();
				$(this).addClass("current").siblings().removeClass("current");
				$(".announcement-item").hide();
				$(".announcement-item").eq(index).show();
			});
		},
		/**
		 * 新增公告右侧的事件
		 * @param $dom 子元素
		 * @param content 
		 */
		renderRightEvent: function($dom,content){
			//公告编辑器
		 editorObj["myeditor_a_"+num] = new UE.ui.Editor({
				imageActionName: 'ueAction',
				imageFieldName: "uploadfile",
				fileActionName: "ueAction",
				fileFieldName: "uploadfile",
				fileAllowFiles: [
					".png", ".jpg", ".jpeg", ".gif", ".bmp",
					".flv", ".swf", ".mkv", ".avi", ".rm", ".rmvb", ".mpeg", ".mpg",
					".ogg", ".ogv", ".mov", ".wmv", ".mp4", ".webm", ".mp3", ".wav", ".mid",
					".rar", ".zip", ".tar", ".gz", ".7z", ".bz2", ".cab", ".iso",
					".doc", ".docx", ".xls", ".xlsx", ".ppt", ".pptx", ".pdf", ".txt", ".md", ".xml"
				],
				imageAllowFiles: [".png", ".jpg", ".jpeg", ".gif", ".bmp"],
				/* 上传图片格式显示 */
				imageUrlPrefix: '' //contextPath
			});
		 editorObj["myeditor_a_"+num].render("myeditor_a_"+num);
		 $("#myeditor_a_"+num).data("content",content);
		 if(content){
			 for(let k in editorObj){
				if(!!$("#"+k).data("content")){
					 editorObj[k].ready(function () {
			   			 editorObj[k].setHeight(400);
			   			  var ue = UE.getEditor(k);
			   			  ue.setContent($("#"+k).data("content"));
			   			});
				}
	         }		
		 }
		 
		 if(!content){
			 editorObj["myeditor_a_"+num].ready(function () {
				 editorObj["myeditor_a_"+num].setHeight(400);
			});
		 }
		  
		},
		/**
		 * 主题输入
		 * @param $dom
		 */
		inputEvent: function($dom){
			$dom.on("input",function(){
				//if()
				$(".small-notice-item.current .s-notice-title").addClass("white-font")
				$(".small-notice-item.current .s-notice-title").html($(this).val())
			})
		},
		//渲染搜索列表
		renderSearchList: function(){
			var _this = this;
			projectOrgId = '';
			//var orgId = '';
			var singleDom = $('.single-orgid')
			if(singleDom.length){
				projectOrgId = $("#orgId").val();
				if (!orgId) {
					layer.msg("请选择项目");
					return false;
				};
			}else{
				if(!orgArr.length){
					layer.msg("请选择项目");
					return
				}
				$.each(orgArr,function(index, el) {
					if(index==orgArr.length-1){
						projectOrgId += el._org_id;
					}else{
						projectOrgId += el._org_id + ',' 
					}
				});	
			};
		},
		/**
		 * 新增事件
		 * @param type 1-点击新增 2-复现新增
		 * @param detailList 素材列表
		 */
		addNoticeEvent: function(type,detailList){// 
			var _this = this;
			if(type==1){
				//添加左侧
				var length = $(".small-notice-item").length;
					num++;
				if(length==8){
					layer.alert('公告最多添加8个!');
					return false;
				}
				var $dom = $(template.render(tpl.addNoticeTpl)({length: length}))
				$(".small-notice-list").append($dom);
				$dom.find(".n-del-bnt").on("click",function(){
					var $this = $(this)
					_this.removeNotice($(this).data("id"),$this)
					
				});
				$(".small-notice-item").removeClass("current");
				$dom.addClass("current");
				_this.switchEvent($dom);
				_this.moveEvent($dom);
				
				//添加右侧
				var $rightDom = $(template.render(tpl.noticeModeTpl)({num: num}));
				$(".announcement-list").append($rightDom);
				$(".announcement-item").hide();
				$rightDom.show();
				_this.renderRightEvent($rightDom);
				_this.inputEvent($rightDom.find(".title-con"));
			}else{
				$.each(detailList,function(index,data){
					if(index !=0){
						//添加左侧
						var length = $(".small-notice-item").length;
							num++;
						if(length==8){
							layer.alert('公告最多添加8个!');
							return false;
						}
						var $dom = $(template.render(tpl.addAgainNoticeTpl)({data: data}))
						$(".small-notice-list").append($dom);
						$dom.find(".n-del-bnt").on("click",function(){
							var $this = $(this)
							_this.removeNotice($(this).data("id"),$this)
						});
//						$(".small-notice-item").removeClass("current");
//						$dom.addClass("current");
						_this.switchEvent($dom);
						_this.moveEvent($dom);
						
						//添加右侧
						var $rightDom = $(template.render(tpl.noticeAgainModeTpl)({num: num,data:data}));
						
						$(".announcement-list").append($rightDom);
						//$(".announcement-item").hide();
						$rightDom.hide();
						_this.renderRightEvent($rightDom,data.content);
						_this.inputEvent($rightDom.find(".title-con"));
//						setTimeout(function () {
//							for(k in editorObj){
//								if(!!$("#"+k).data("content")){
//									 editorObj[k].ready(function () {
//							   			 editorObj[k].setHeight(400);
//							   			  var ue = UE.getEditor(k);
//							   			  ue.setContent($("#"+k).data("content"));
//							   			});
//								}
////					            console.log("姓名："+k+";"+"对应值："+editorObj[k]);
//					         }			
//						}, 600)
					}
				});
			}
			
		},
		/**
		 * 刪除素材
		 * @param id
		 * @param $this 刪除按鈕dom
		 */
		removeNotice: function(id,$this){
			if(id){
				$.ajax({
					url: contextPath + '/notice/publicno/delDetaile',
					type: "POST",
					dataType: "json",
					data: {
						noticeDetailId: id,//素材id
						
					},
					success: function (data) {
						if(data.code == 200 ){
							var $index = $this.closest(".small-notice-item").index();
							$(".announcement-item").eq($index).remove();
							$this.closest(".small-notice-item").remove();
							var $currentIndex = $(".small-notice-item.current").index();
							$(".announcement-item").eq($currentIndex).show();
						}else{
							layer.msg(data.msg);
						}
					},
					error: function(err){

					}
				});
			}else{
				var $index = $this.closest(".small-notice-item").index();
				$(".announcement-item").eq($index).remove();
				$this.closest(".small-notice-item").remove();
				var $currentIndex = $(".small-notice-item.current").index();
				$(".announcement-item").eq($currentIndex).show();
//				$(".announcement-item")
			}
		}
		
	};
	appPublish.init();

	
	// 图片裁剪
	$("#imgCutConfirm").bind("click", function () {
		
		var typeImg = "image/" + '';
		setTimeout(function () {
			 //控制图片大小不大于1M
			if(($("#state").val()==2 || $("#state").val()==5) && $("#content").val()==1 ){//图文
				if((upload($("#graphic #showImg").attr('src'), typeImg || "image/png").get("pictures")).size>1024*1024*1024){
					layer.alert('图片大小须在1M以内!');
					return false;
				};
			}else if(($("#state").val()==2 || $("#state").val()==5) && $("#content").val()==2 ){//跳转链接
				if(( upload($("#link #showImg").attr('src'), typeImg || "image/png").get("pictures")).size>1024*1024*1024){
					layer.alert('图片大小须在1M以内!');
					return false;
				};
			}
			if($("#state").val()!=1){
				$("#containerDiv").hide();
				$("#imgEdit").hide();
				$("#getCroppedCanvasModal").modal("hide");
			}
//			picture = $("#showImg").attr('src');
		}, 500)
		// submitForm()
	})
})