
var permDelete = $("#perm-delete").val();//删除权限
var permEdit = $("#perm-edit").val();//编辑权限
var permApprove = $("#perm-approve").val();//审核权限
var userType = $("#userType").val();
var roleMoreApprove=$("#perm-roleMore-approve").val();//多级审核权限
var companyArr = []; // 运营中心列表
var companyId = '';
var orgArr = []; // 项目列表
/**
 * app公告发布公告审核
 * 2018/4/20 by liufang
 */
$(function () {
	var contextPath=$("#contextPath").val()
	var auditNoticePermission = $("#auditNoticePermission").val();
	var orgid= $("#conditionform #orgId").attr('org__id')
	localStorage.setItem("projectOrgId",orgid)
	localStorage.setItem("contextPath",contextPath)
	console.log("orgid",orgid)
	var tpl = {
		"xq_detailTpl_notice": '<div class="dialog-wp">\
				<div class="mask"></div>\
				<div class="dialog dialog-detail-con">\
					<div class="title-wp">\
						<span>公告详情</span>\
						<span class="close-btn"></button>\
					</div>\
					<div class="dialog-detail-wp">\
							<div class="detail-title-detail clearfloat">\
							<span class="tips-title">发布类型</span>\
							<span class="dialog-desc" >公告</span>\
						   </div>\
						<div class="detail-title-detail clearfloat">\
							<span class="tips-title">封面图片</span>\
							<img type="text" class="dialog-image" src="<%=coverUrl%>" \>\
						</img>\
						<div class="detail-title-detail clearfloat">\
							<span class="tips-title">主题</span>\
							<span class="dialog-desc"><%=title%></span>\
						</div>\
						<div class="detail-title-detail clearfloat">\
							<span class="tips-title">正文</span>\
							<div class="dialog-textarea-desc" readonly="readonly"><%=content%></div >\
						</div>\
						<div class="detail-title-detail clearfloat">\
							<span class="tips-title">摘要</span>\
							<span class="dialog-desc"><%=summaryInfo%></span>\
						</div>\
						<div class="detail-title-detail clearfloat">\
							<span class="tips-title">审核类型</span>\
							<span class="dialog-desc"><%=approvalTypeName%></span>\
						</div>\
						<ul class="dialog-wx-list">\
							<% for(var i=0;i<auditList.length;i++){%>\
							<li class=" clearfloat">\
								<span class="w-i-tips">审核人:</span>\
								<span class="w-i-approve"><%=auditList[i].approvalUser%></span>\
							</li>\
							<li class=" clearfloat">\
								<span class="w-i-tips">审核时间:</span>\
								<span class="w-i-approve"><%=auditList[i].approvalTime%></span>\
							</li>\
							<li class=" clearfloat">\
								<span class="w-i-tips">审核结果:</span>\
								<span class="w-i-approve"><%=auditList[i].approvalResult==1?"通过":"不通过"%></span>\
							</li>\
							<li class="clearfloat">\
								<span class="w-i-tips">审核意见:</span>\
								<span class="w-i-approve"><%=auditList[i].approvalOpinion%></span>\
							</li>\
							<%}%>\
						</ul>\
					</div>\
				</div>\
			</div>	',
			"xq_detailTpl_banner_msg": '<div class="dialog-wp">\
				<div class="mask"></div>\
				<div class="dialog dialog-detail-con">\
					<div class="title-wp">\
						<span>公告详情</span>\
						<span class="close-btn"></button>\
					</div>\
					<div class="dialog-detail-wp">\
							<div class="detail-title-detail clearfloat">\
							<span class="tips-title">发布类型</span>\
							<span class="dialog-desc" >banner</span>\
						   </div>\
						   <div class="detail-title-detail clearfloat">\
							<span class="tips-title">发布内容</span>\
							<span class="dialog-desc" >图文消息</span>\
						   </div>\
						<div class="detail-title-detail clearfloat">\
							<span class="tips-title">banner图片</span>\
							<img type="text" class="dialog-image" src="<%=coverUrl%>" \>\
						</img>\
						<div class="detail-title-detail clearfloat">\
							<span class="tips-title">主题</span>\
							<span class="dialog-desc"><%=title%></span>\
						</div>\
						<div class="detail-title-detail clearfloat">\
							<span class="tips-title">正文</span>\
							<div class="dialog-textarea-desc" readonly="readonly"><%=content%></div >\
						</div>\
						<div class="detail-title-detail clearfloat">\
							<span class="tips-title">审核类型</span>\
							<span class="dialog-desc"><%=approvalTypeName%></span>\
						</div>\
						<ul class="dialog-wx-list">\
							<% for(var i=0;i<auditList.length;i++){%>\
							<li class=" clearfloat">\
								<span class="w-i-tips">审核人:</span>\
								<span class="w-i-approve"><%=auditList[i].approvalUser%></span>\
							</li>\
							<li class=" clearfloat">\
								<span class="w-i-tips">审核时间:</span>\
								<span class="w-i-approve"><%=auditList[i].approvalTime%></span>\
							</li>\
							<li class=" clearfloat">\
								<span class="w-i-tips">审核结果:</span>\
								<span class="w-i-approve"><%=auditList[i].approvalResult==1?"通过":"不通过"%></span>\
							</li>\
							<li class="clearfloat">\
								<span class="w-i-tips">审核意见:</span>\
								<span class="w-i-approve"><%=auditList[i].approvalOpinion%></span>\
							</li>\
							<%}%>\
						</ul>\
					</div>\
				</div>\
			</div>	',
			"xq_detailTpl_banner_link": '<div class="dialog-wp">\
				<div class="mask"></div>\
				<div class="dialog dialog-detail-con">\
					<div class="title-wp">\
						<span>公告详情</span>\
						<span class="close-btn"></button>\
					</div>\
					<div class="dialog-detail-wp">\
							<div class="detail-title-detail clearfloat">\
							<span class="tips-title">发布类型</span>\
							<span class="dialog-desc" >banner</span>\
						   </div>\
						   <div class="detail-title-detail clearfloat">\
						   <span class="tips-title">发布内容</span>\
						   <span class="dialog-desc" >跳转链接</span>\
						  </div>\
						<div class="detail-title-detail clearfloat">\
							<span class="tips-title">banner图片</span>\
							<img type="text" class="dialog-image" src="<%=coverUrl%>" \>\
						</img>\
						<div class="detail-title-detail clearfloat">\
							<span class="tips-title">跳转链接</span>\
							<span class="dialog-desc"><%=urlAddress%></span>\
						</div>\
						<div class="detail-title-detail clearfloat">\
							<span class="tips-title">审核类型</span>\
							<span class="dialog-desc"><%=approvalTypeName%></span>\
						</div>\
						<ul class="dialog-wx-list">\
							<% for(var i=0;i<auditList.length;i++){%>\
							<li class=" clearfloat">\
								<span class="w-i-tips">审核人:</span>\
								<span class="w-i-approve"><%=auditList[i].approvalUser%></span>\
							</li>\
							<li class=" clearfloat">\
								<span class="w-i-tips">审核时间:</span>\
								<span class="w-i-approve"><%=auditList[i].approvalTime%></span>\
							</li>\
							<li class=" clearfloat">\
								<span class="w-i-tips">审核结果:</span>\
								<span class="w-i-approve"><%=auditList[i].approvalResult==1?"通过":"不通过"%></span>\
							</li>\
							<li class="clearfloat">\
								<span class="w-i-tips">审核意见:</span>\
								<span class="w-i-approve"><%=auditList[i].approvalOpinion%></span>\
							</li>\
							<%}%>\
						</ul>\
					</div>\
				</div>\
			</div>	',
			"xq_detailTpl_link": '<div class="dialog-wp">\
				<div class="mask"></div>\
				<div class="dialog dialog-detail-con">\
					<div class="title-wp">\
						<span>公告详情</span>\
						<span class="close-btn"></button>\
					</div>\
					<div class="dialog-detail-wp">\
							<div class="detail-title-detail clearfloat">\
							<span class="tips-title">发布类型</span>\
							<span class="dialog-desc" >生成链接</span>\
						   </div>\
						<div class="detail-title-detail clearfloat">\
							<span class="tips-title">主题</span>\
							<span class="dialog-desc"><%=title%></span>\
						</div>\
						<div class="detail-title-detail clearfloat">\
							<span class="tips-title">正文</span>\
							<div class="dialog-textarea-desc" readonly="readonly"><%=content%></div >\
						</div>\
						<div class="detail-title-detail clearfloat">\
							<span class="tips-title">审核类型</span>\
							<span class="dialog-desc"><%=approvalTypeName%></span>\
						</div>\
						<span class="tips-title-1">审核信息</span>\
						<ul class="dialog-wx-list">\
							<% for(var i=0;i<auditList.length;i++){%>\
							<li class=" clearfloat">\
								<span class="w-i-tips">审核人:</span>\
								<span class="w-i-approve"><%=auditList[i].approvalUser%></span>\
							</li>\
							<li class=" clearfloat">\
								<span class="w-i-tips">审核时间:</span>\
								<span class="w-i-approve"><%=auditList[i].approvalTime%></span>\
							</li>\
							<li class=" clearfloat">\
								<span class="w-i-tips">审核结果:</span>\
								<span class="w-i-approve"><%=auditList[i].approvalResult==1?"通过":"不通过"%></span>\
							</li>\
							<li class="clearfloat">\
								<span class="w-i-tips">审核意见:</span>\
								<span class="w-i-approve"><%=auditList[i].approvalOpinion%></span>\
							</li>\
							<%}%>\
						</ul>\
					</div>\
				</div>\
			</div>	',
        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>\
					  		<iframe class="notice-detail-con-wp" style="width: 100%;height: calc(100% - 64px);" src="<%=previewUrl%>"></iframe>\
					  </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">\
										<div class="notice-item-wp">\
									 		<div class="banner-wp" style="background-image: url( <%=banner%>)"></div>\
									 		<div class="banner-descript"><%=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>',
			 "typeTpl": '<option value="">选择审核类型</option>\
						  <% for(i=0;i<data.length;i++){%> \
							  <option value="<%=data[i].id%>"><%=data[i].name%></option>\
						   <%}%>'
	}
	template.config("escape", false);
	var appSend = {
		init: function () {
			this.render();
			this.bindEvent();
		},
		render: function () {
			this.rendertable();
		},
		bindEvent: function () {
			var _this = this;
			layui.use('laydate', function () {
				var laydate = layui.laydate;

				//执行一个laydate实例
				laydate.render({
					elem: '#c_startTime' //提交开始时间

				});
				laydate.render({
					elem: '#c_endTime' //提交结束时间

				});
				laydate.render({
					elem: '#a_startTime' //审核开始时间

				});
				laydate.render({
					elem: '#a_endTime' //审核结束时间

				});
			});
			//重置
			$(".set-btn").on("click", function () {
				$("#conditionform select").val("");

				let contextPathURL = window.location.hostname === 'localhost' ? '//wx.palmnest.com/super_cloud' : "/super_cloud"
				if (userType == -1||userType == 1 || userType == 2|| userType == 6) {
					$("#conditionform input").val("");
					$('#comdId').val(companyArr[0].label).attr('comd__id', companyArr[0].value).attr('meetCode', companyArr[0].meetCode);
					companyId = $("#conditionform #comdId").attr('comd__id');
					_this.setOrgData(contextPathURL);
				} else {
					$("#conditionform input:not('#orgId')").val("");
					companyId = localStorage.getItem("companyId")
					_this.setOrgData(contextPathURL);
				}
			})
			let contextPathURL = window.location.hostname === 'localhost' ? '//wx.palmnest.com/super_cloud' : "/super_cloud"
			if (userType == -1 || userType == 1 || userType == 2|| userType == 6) {
				_this.getCompanyList({}, contextPathURL)
				$('body').on("focus", '#comdId', function (event) {
					_this.setOrgCompanyData($('#comdId'), 'comd__id', 'comd__span' , companyArr);
				});
				$('body').on('blur', '#comdId', function (event) {
					var _that = $(this)
					cjqt.search_fuzzy.event_blur(_that, 'comd__id')
				});
				$('body').on('click', '.select_wrap>.comd__span', function (event) {
					event.preventDefault();
					event.stopPropagation();
					/* Act on the event */
					var _that = $(this)
					cjqt.search_fuzzy.event_click(_that, 'comd__id', '#comdId')
					companyId = $("#conditionform #comdId").attr('comd__id')
					_this.setOrgData(contextPathURL);
				});
				$('body').on("input",'#comdId',function(event){ // input内容变化执行
					_this.setFuzzyFilter($('#comdId').val(), companyArr, backData => {
						_this.setOrgCompanyData($('#comdId'), 'comd__id', 'comd__span' , backData);
					})
				});
			} else {
				companyId = localStorage.getItem("companyId")
				_this.setOrgData(contextPathURL);
			}
    },
		setOrgData: function (contextPathURL) {
			var _this = this;
			_this.getOrgList({
				pageNo: 1,
				pageSize: 9999,
				"conditions[companyId]": companyId
			}, contextPathURL)
			$('body').on("focus", '#orgId', function (event) {
				_this.setOrgCompanyData($('#orgId'), 'org__id', 'org__span', orgArr);
			});
			$('body').on('blur', '#orgId', function (event) {
				var _that = $(this)
				cjqt.search_fuzzy.event_blur(_that, 'org__id')
			});
			$('body').on('click', '.select_wrap>.org__span', function (event) {
				event.preventDefault();
				event.stopPropagation();
				/* Act on the event */
				var _that = $(this)
				cjqt.search_fuzzy.event_click(_that, 'org__id', '#orgId')
			});
			$('body').on("input", '#orgId', function (event) {
				_this.setFuzzyFilter($('#orgId').val(), orgArr, backData => {
					_this.setOrgCompanyData($('#orgId'), 'org__id', 'org__span', backData);
				})
			});
		},
		// 获取运营中心数据
		getCompanyList: function (obj, contextPathURL) {
			var _this = this;
			companyArr = [];
			$.ajax({
				url: contextPathURL + '/api/organisation/company/getselectlist',
				type: "POST",
				dataType: "json",
				data: obj,
				success: function (data) {
					if (data.code == 200 && data.data) {
						companyArr = data.data;
						_this.setInputData($('#comdId'), 'comd__id', 'comd__span', companyArr);
						companyId = $("#conditionform #comdId").attr('comd__id')
						_this.setOrgData(contextPathURL);
					} else {
						layer.msg(data.msg);
					}
				}
			});
		},
		// 获取项目数据
		getOrgList(obj, contextPathURL) {
			var _this = this;
			orgArr = [];
			$.ajax({
				url: contextPathURL + '/api/organisation/organization/getselectlist',
				type: "POST",
				dataType: "json",
				data: obj,
				success: function (data) {
					if (data.code == 200 && data.data) {
						orgArr = data.data;
						_this.setInputData($('#orgId'), 'org__id', 'org__span', orgArr);
						if (orgArr.length == 1) {
							if (roleMoreApprove == 1) {
								$(".add-verifty-btn").show();
							} else {
								$(".add-verifty-btn").hide();
							}
							_this.getIfCanApproval(orgArr[0].value)
						} else {
							$(".add-verifty-btn").hide();
						}
					} else {
						layer.msg(data.msg);
					}
				}
			});
		},
		setInputData: function (_this, attrName, liClassName, dataArr) {
			// 先清空
			_this.attr(attrName, '')
			var html = ''
			if (dataArr.length) {
				_this.val(dataArr[0].label).attr(attrName, dataArr[0].value).attr('meetCode', dataArr[0].meetCode);
				if (attrName == 'org__id') {
					$('#conditionform  .search-btn').click();
				}
				$.each(dataArr, function (index, el) {
					var meetCode = el.meetCode || ''
					html += '<span class="' + liClassName + '" id="' + el.value + '" meetCode="' + meetCode + '">'
					html += el.label
					html += '</span>'
				});
				_this.parent().find('.select_wrap').empty().append(html);
			} else {
				_this.val('').attr(attrName, '').attr('meetCode', '');
				_this.parent().find('.select_wrap').empty().hide()
			}
		},
		setOrgCompanyData: function (_this, attrName, liClassName, dataArr) {
			var html = ''
			if (dataArr.length) {
				_this.parent().find('.select_wrap').show()
				$.each(dataArr, function (index, el) {
					var meetCode = el.meetCode || ''
					html += '<span class="' + liClassName + '" id="' + el.value + '" meetCode="' + meetCode + '">'
					html += el.label
					html += '</span>'
				});
				_this.parent().find('.select_wrap').empty().append(html)
			} else {
				_this.parent().find('.select_wrap').empty().hide()
			}
		},
		setFuzzyFilter: function (strLabel, dataArr, backData) {
			const fuzzyArr = dataArr; // 内容省略
			const objArr = [];
			fuzzyArr.forEach(item => {
				if (item.label.includes(strLabel)) {
					objArr.push(item);
				}
			});
			backData(objArr);
		},
		getApprovalTypeList: function(orgid){
			$.ajax({
				type: "post",
				url: $("#contextPath").val() + "/notice/approval/getApprovalType",
				data: {
					"orgId": orgid
				},
				success: function (data) {
					if (data.code == 200) {
						$("#approvalType").html(template.render(tpl.typeTpl)(data));
					} else {
						layer.msg(data.msg)
					}
				},
				error: function (error) {
					layer.msg('error')
				}
			});
		},
		getIfCanApproval: function(orgid){
			console.log('orgId == ', orgid);
			var _this=this
			$.ajax({
				type: "post",
				url: $("#contextPath").val() + "/notice/approval/getSetByOrgId",
				data: {
					"orgId":  orgid
				},
				success: function (data) {
					if (data.code == 200) {
						if(data.data==1){//显示审核下拉列表
							$(".approvalStyle").show();
							_this.getApprovalTypeList(orgid)
						}else{////不显示审核下拉列表
							$(".approvalStyle").hide();
						}
					} else {
						layer.msg(data.msg)
					}
				},
				error: function (error) {
					layer.msg('error')
				}
			});
		},
		rendertable: function () {
			var _this = this;
			console.log("roleMoreApprove",roleMoreApprove)
			layui.use('table', function () {
				var table = layui.table;

				//方法级渲染
				table.render({
					elem: '#LAY_table_user',
					url: $("#contextPath").val() + "/notice/appNotice/getList",
					skin: 'nob' //行边框风格
					,even: true //开启隔行背景
					,size: 'lg' //小尺寸的表格
					,cols: [
						[ {
              title: '序号',
              templet: '#indexTpl',
              width: 70
          } ,{
							field: 'createTime',
							title: '时间',
							minWidth: 180
						}, {
              field: 'notice_type',
              title: '发布类型',
              minWidth: 110,
              templet: function (data) {
                  if (data.notice_type == 1) {
                      return '公告'
                  } else if (data.notice_type == 2) {
                      return 'banner'
                  } else if (data.notice_type == 3) {
                      return '生成链接'
                  } else if (data.notice_type == 5) {
                      return '楼闪送banner'
                  } else if (data.notice_type == 6) {
					  return '周边商户banner'
				  } else if (data.notice_type == 7) {
					  return '企业云卡banner'
				  } else {
                  	return ''
				  }
              }
            },{
							field: 'title',
							title: '标题',
							minWidth: 200
						}, {
							field: 'content_txt',
							title: '内容',
							minWidth: 200
						}, {
							field: 'fullName',
							title: '编辑人',
							width: 100
						}, {
							field: 'roleName',
							title: '当前审核角色',
							width: 120
						}, {
							field: 'state',
							title: '发布状态',
							width: 100,
							templet: function (data) {
								if(data.isEnabled==0){
									return '已下线';
								}else if (data.state == 0) {
									return "<span class='red'>未审核<span>"
								} else if (data.state == 1) {
									return '已发布'
								} else if (data.state == 2) {
									return '已驳回'
								} else if (data.state == 3) {
									return '原文链接'
								} else if (data.state == -1) {
									return '草稿'
								} else {
									return ''
								}
							}
						},  {
							field: 'isEnabled',
							title: '状态',
							width: 90,
							templet: function (data) {//isEnabled原先0为删除 1代表下线,2代表上线
								if(data.isEnabled==1){
									return '下线';
								}else if (data.isEnabled == 2) {
									return '上线';
								}
							}
						},{
							field: 'approval_user',
							title: '审核人',
							width: 100
						}, {
							field: 'approval_time',
							title: '审核时间',
							minWidth: 180
						},
						// {
						// 	field: 'id',
						// 	title: '详情',
						// 	width: 120,
						// 	templet: function (data) {
						// 		return "<div data-id=" + data.id + "  class='check-blue-btn'>查看详情</div>"
						// 	}
						// },
						{
							field: 'id',
							title: '可操作',
							fixed: 'right',
							width: 480,
							align: 'center',
							templet: function (data) {
								var str = '';
								str += '<button class="t-btn t-red-btn t-copy-btn" data-id=' + data.id + ' data-type="2">复制</button>';
								if(data.orderNum==0){
									str += '<button class="t-btn t-top-btn t-red-btn " data-id=' + data.id + ' data-isTop= '+( data.orderNum ==0 ?1:0)+'  data-type="2">置顶</button>';
								} else {
									str += '<button class="t-btn t-top-btn t-red-btn " data-id=' + data.id + '  data-isTop= '+ ( data.orderNum ==0 ?1:0) +' data-type="2">取消置顶</button>';
								}
								if (permApprove == 1) {
                                    if (data.state == 0) {
                                    	if(data.isEnabled==1){
                                    		if(data.isApproval==1){
                                    			str += '<button class="t-btn t-red-btn t-copy-vertify" data-id=' + data.id + ' data-type="2">审核</button>';
                                    		}else if(data.approvalType==0){
                                    			str += '<button class="t-btn t-red-btn t-publish-btn" data-id=' + data.id + ' data-type="1">发布</button>';
                                    		}
                                    	}
                                    	if(data.isApproval == 0 && data.approvalType==0){
                                    		str += '<button class="t-btn t-white-btn t-reject-btn" data-id=' + data.id + ' data-type="2">驳回</button>';
                                    	}
                                    }
								}
								if (permEdit == 1) {
                                    if (data.state == 0 || data.state == 1 || data.state == -1) {
                                    	if(!(userType > 2 && data.orgIds)){
                                    		str += '<button class="t-btn t-red-btn t-edit-btn" data-id=' + data.id + ' data-type="2">编辑</button>';
										}
                                    }
								}
								if (permDelete == 1){
									if(!(userType > 2 && data.orgIds)){
										if (data.state == 1) {
											 if(data.isEnabled==1){//isEnabled原先0为删除 1代表下线,2代表上线
												 str += '<button class="t-btn t-white-btn t-delete-btn" data-id=' + data.id + ' data-type="2" data-isDelete=2 data-isenabled="2">上线</button>';
											 }else if(data.isEnabled==2){
												 str += '<button class="t-btn t-white-btn t-delete-btn" data-id=' + data.id + ' data-type="2" data-isDelete=1 data-isenabled="1">下线</button>';
											 }
										}
									}
								}
								str += '<button class="t-btn t-white-btn t-delete-btn" data-id=' + data.id + ' data-type="2"  data-isDelete=0 data-isenabled="0">删除</button>';
								str += '<button class="t-btn t-red-btn check-blue-btn" data-id=' + data.id + ' data-type="2">预览</button>';
								str += '<button class="t-btn t-red-btn check-blue-detail" data-id=' + data.id + ' data-type="2">详情</button>';
								if(data.notice_type==1){
									str += '<button class="t-btn t-red-btn check-blue-urllink" data-url=' + data.url_address + ' data-type="2">复制链接</button>';
								}

								return str;
							}
						}]
					],
					id: 'testReload',
					page: true,
					where: { //设定异步数据接口的额外参数，任意设
						"orgId": $("#conditionform #orgId").attr('org__id')
					},
					response: {
						statusName: 'code' //数据状态的字段名称，默认：code
							,
						statusCode: 200 //成功的状态码，默认：0
							,
						countName: "count" //数据总数的字段名称，默认：count
							,
						dataName: "data" //数据列表的字段名称，默认：data
					},
					done: function (res, curr, count) {
						//如果是异步请求数据方式，res即为你接口返回的信息。
						//预览
						$(".check-blue-btn").on("click", function () {
							var id = $(this).data("id");
							//显示详情弹窗
							_this.showDetailDialog(id)
						});
						$(".check-blue-detail").on("click", function () {
							var id = $(this).data("id");
							//显示详情弹窗
							_this.showAppVerifyDetailDialog(id)
						});

						$(".check-blue-urllink").on("click", function () {
							//复制链接  ---by南山
							var text = $(this).data("url");
							var protocolStr = document.location.protocol;

							if(text ){
								if(text.indexOf(protocolStr)==-1 || text.indexOf(protocolStr)==-1){
									text=protocolStr +text
								}

							}
							console.log("url",text)
							var flag = _this.copyText(text);
							layer.msg(flag ? "复制成功！" : "复制失败！")

						});
						//发布
						$(".t-publish-btn").on("click", function () {
							var id = $(this).data("id");
							var type = $(this).data("type")
							_this.publish(type, id, function () {
								table.reload('testReload', {
									url: $("#contextPath").val() + "/notice/appNotice/getList",
									where: { //设定异步数据接口的额外参数，任意设
                                        "c_beginTime": $("#c_startTime").val(),
                                        "c_endTime": $("#c_endTime").val(),
                                        "a_beginTime": $("#a_startTime").val(),
                                        "a_endTime": $("#a_endTime").val(),
										"state": $("#state").val(),
                                        "isEnabled": $("#enabledId").val(),
                                        "title": $("#title").val(),
										"noticeType": $("#noticeType").val(),
										"approvalType": $("#approvalType").val(),
										"orgId": $("#conditionform #orgId").attr('org__id')
									},
									page: {
										curr: 1 //重新从第 1 页开始
									}
								});
							});
						});
						// 复制
                        $('.t-copy-btn').on('click', function () {
                            var id = $(this).data("id");
                          	location.href= $("#contextPath").val() + "/notice/appNotice/redirectToEdit?id="+id;
                        });

						// 置顶 or 取消置顶
						$('.t-top-btn').on('click', function () {
							var id = $(this).data("id");
							var isTop = $(this).attr("data-isTop");
							console.log('isTop', isTop)
							_this.setTop(id,isTop,function () {
								table.reload('testReload', {
									url: $("#contextPath").val() + "/notice/appNotice/getList",
									where: { //设定异步数据接口的额外参数，任意设
										"c_beginTime": $("#c_startTime").val(),
										"c_endTime": $("#c_endTime").val(),
										"a_beginTime": $("#a_startTime").val(),
										"a_endTime": $("#a_endTime").val(),
										"state": $("#state").val(),
                                        "isEnabled": $("#enabledId").val(),
                                        "title": $("#title").val(),
										"noticeType": $("#noticeType").val(),
										"approvalType": $("#approvalType").val(),
										"orgId": $("#conditionform #orgId").attr('org__id')
									},
									page: {
										curr: 1 //重新从第 1 页开始
									}
								});
							});

						})
                        // 上下线 删除
                        $(".t-delete-btn").on("click", function () {
                            var id = $(this).data("id");
                            var isEnabled = $(this).data("isenabled");
                            var isDelete = $(this).attr('data-isDelete')
							console.log('isDelete', isDelete)
                            _this.delete(id,isEnabled, function () {
                                table.reload('testReload', {
									url: $("#contextPath").val() + "/notice/appNotice/getList",
                                    where: { //设定异步数据接口的额外参数，任意设
                                        "c_beginTime": $("#c_startTime").val(),
                                        "c_endTime": $("#c_endTime").val(),
                                        "a_beginTime": $("#a_startTime").val(),
                                        "a_endTime": $("#a_endTime").val(),
                                        "state": $("#state").val(),
                                        "isEnabled": $("#enabledId").val(),
                                        "title": $("#title").val(),
                                        "noticeType": $("#noticeType").val(),
                                        "approvalType": $("#approvalType").val(),
                                        "orgId": $("#conditionform #orgId").attr('org__id')
                                    },
                                    page: {
                                        curr: 1 //重新从第 1 页开始
                                    }
                                });
                            }, isDelete);
                        });
						$(".t-reject-btn").on("click", function () {
							var id = $(this).data("id");
							var type = $(this).data("type")
							_this.publish(type, id, function () {
								table.reload('testReload', {
									url: $("#contextPath").val() + "/notice/appNotice/getList",
									where: { //设定异步数据接口的额外参数，任意设
                                        "c_beginTime": $("#c_startTime").val(),
                                        "c_endTime": $("#c_endTime").val(),
                                        "a_beginTime": $("#a_startTime").val(),
                                        "a_endTime": $("#a_endTime").val(),
										"state": $("#state").val(),
                                        "title": $("#title").val(),
                                        "isEnabled": $("#enabledId").val(),
										"noticeType": $("#noticeType").val(),
										"approvalType": $("#approvalType").val(),
                                        "orgId": $("#conditionform #orgId").attr('org__id')
									},
									page: {
										curr: 1 //重新从第 1 页开始
									}
								});
							});
						});
						//编辑
						$(".t-edit-btn").on("click",function(){
							var id = $(this).data("id");
							window.location.href= contextPath+ '/notice/noticeAppPublish?id='+id;
						})
							// 审核
						$('.t-copy-vertify').on('click', function () {
							var id = $(this).data("id");
							var approveId=1
							window.location.href= contextPath+ '/notice/noticeAppPublish?id='+id+"&approveId="+approveId;
							// location.href= $("#contextPath").val() + "/notice/appNotice/redirectToSH?id="+id;
						});
					}
				});
				//查询
				$('#conditionform  .search-btn').on('click', function () {
					var org_Id = $("#conditionform #orgId").attr('org__id');
					if (!org_Id&&userType!=1&&userType!=2&&userType != -1) {
						layer.msg('请选择项目')
						return;
					}
					table.reload('testReload', {
						url: $("#contextPath").val() + "/notice/appNotice/getList",
						where: { //设定异步数据接口的额外参数，任意设
							"c_beginTime": $("#c_startTime").val(),
							"c_endTime": $("#c_endTime").val(),
							"a_beginTime": $("#a_startTime").val(),
							"a_endTime": $("#a_endTime").val(),
							"state": $("#state").val(),
							"isEnabled": $("#enabledId").val(),
							"title": $("#title").val(),
							"noticeType": $("#noticeType").val(),
							"approvalType": $("#approvalType").val(),
							"orgId": $("#conditionform #orgId").attr('org__id')
						},
						page: {
							curr: 1 //重新从第 1 页开始
						}
					});
				});

				// 审核按钮操作
				$('.add-verifty-btn').on('click', function () {
					localStorage.setItem("projectOrgId", $("#conditionform #orgId").attr('org__id'))
					window.location.href= $("#contextPath").val() + "/notice/appNotice/redirectToMultilevelClassification"
				});
				//状态筛选
				$(".filter-btn-item").on("click", function () {
					var org_Id = $("#conditionform #orgId").attr('org__id');
					if (!org_Id) {
						layer.msg('请先选择项目');
						return;
					}
					$(this).addClass("active").siblings().removeClass("active");
					table.reload('testReload', {
						url: $("#contextPath").val() + "/notice/appNotice/getList",
						where: { //设定异步数据接口的额外参数，任意设
							"c_beginTime": $("#c_startTime").val(),
                            "c_endTime": $("#c_endTime").val(),
                            "a_beginTime": $("#a_startTime").val(),
                            "a_endTime": $("#a_endTime").val(),
							"state": $("#state").val(),
                            "isEnabled": $("#enabledId").val(),
                            "title": $("#title").val(),
							"noticeType": $("#noticeType").val(),
							"approvalType": $("#approvalType").val(),
                            "orgId": $("#conditionform #orgId").attr('org__id')
						},
						page: {
							curr: 1 //重新从第 1 页开始
						}
					});
				})
			});
		},

		copyText :function (text) {
			var textarea = document.createElement("textarea");
			var currentFocus = document.activeElement;
			document.body.appendChild(textarea);
			textarea.value = text;
			textarea.focus();
			if (textarea.setSelectionRange)
				textarea.setSelectionRange(0, textarea.value.length);
			else
				textarea.select();
			try {
				var flag = document.execCommand("copy");
			} catch(eo){
				var flag = false;
			}
			document.body.removeChild(textarea);
			currentFocus.focus();
			return flag;
		},


		/**
		 *  //noticeType 公告类型： 1 公告 ；2 banner图；3 跳转链接
             //contentType 图文类型： 1 图文消息 ；2 跳转链接
		 * 显示详情弹窗 noticeType 创建公告类型 1 公告 2 banner图文链接 3 banner跳转链接 4 生成链接
		 * @param id
		 */
		 showAppVerifyDetailDialog: function (id) {
			var _this = this;
			window.location.href= $("#contextPath").val() + "/notice/appNotice/redirectToNoticeDetail?id="+id
			// _this.ajaxDetail(id, function (data) {
			// 	if(data.noticeType==1){
			// 		$("body").append(template.render(tpl.xq_detailTpl_notice)(data));
			// 	}else if(data.noticeType==2){
			// 		if(data.contentType==1){
			// 			$("body").append(template.render(tpl.xq_detailTpl_banner_msg)(data));
			// 		}else if(data.contentType==2){
			// 			$("body").append(template.render(tpl.xq_detailTpl_banner_link)(data));
			// 		}

			// 	}else if(data.noticeType==3){
			// 		$("body").append(template.render(tpl.xq_detailTpl_link)(data));
			// 	}

			// 	//关闭弹窗
			// 	$(".close-btn").on("click", function () {
			// 		$(".dialog-wp").remove();
			// 	})
			// })
		},
		/**
		 * 显示预览弹窗
		 * @param id
		 */
		showDetailDialog: function (id) {
			var _this = this;
			_this.ajaxDetail(id, function (data) {
                //noticeType 公告类型： 1 公告 ；2 banner图；3 跳转链接
                //contentType 图文类型： 1 图文消息 ；2 跳转链接
                _this.ajaxDetail(id, function (data) {
                    _this.previewPhone(data)
                })
			})
		},
		ajaxDetail: function (id, callback) {
			$.ajax({
				type: "post",
				url: $("#contextPath").val() + "/notice/appNotice/getDetail",
				data: {
					"id": id
				},
				success: function (data) {
//					var data = JSON.parse(data);
					if (data.code == 200) {
						callback(data.data);
					} else {
						layer.msg(data.msg)
					}
				},
				error: function (error) {
					layer.msg('error')
				}
			});
		},
		/**
		 * 发布弹窗
		 * @param type 1为发布 2为驳回
		 * @param id 数据id
		 */
		publish: function (type, id, callback) {

			var _this = this;
			if (type == 1) {
				layer.confirm('确定发布?', {
					btn: ['确定', '取消']
				}, function (index, layero) {
					layer.close(index); //如果设定了yes回调，需进行手工关闭
					_this.ajaxPublish(type, id, callback);
				}, function (index) {

				});
			} else {
				layer.confirm('确定驳回?', {
					btn: ['确定', '取消']
				}, function (index, layero) {
					layer.close(index); //如果设定了yes回调，需进行手工关闭
					_this.ajaxPublish(type, id, callback);

				}, function (index) {

				});
			}
		},
		/**
		 * 置顶 or 取消置顶
		 * @param type
		 * @param id
		 * @param callback
		 */
        setTop: function (id, isTop, callback) {
			$.ajax({
				type: "post",
				url: $("#contextPath").val() + "/notice/appNotice/setTop",
				data: {
					"id": id,
                    'isTop': isTop
				},
				success: function (data) {
					var data = JSON.parse(data);
					if (data.code == '200') {
						layer.msg(isTop==0 ? '取消置顶成功！':'置顶成功！')
						callback();
					} else {
						layer.msg(data.msg)
					}
				},
				error: function (error) {
					layer.msg('error')
				}
			});
		},
		/**
		 * 删除
		 * @param type
		 * @param id
		 * @param callback
		 */
		delete: function (id, isEnabled,callback, isDelete) {
            var _this = this;
            console.log('dasdsa', isDelete === '1')
			console.log('dfdg', typeof isDelete)
            if (isDelete === '0') {
				layer.confirm( '确定删除', {
					btn: ['确定', '取消']
				}, function (index, layero) {
					layer.close(index); //如果设定了yes回调，需进行手工关闭
					_this.deleteNotice(id, isEnabled,callback);
				}, function (index) {

				});
			} else {
				layer.confirm(isEnabled==1 ? '确定下线?' : '确定上线?', {
					btn: ['确定', '取消']
				}, function (index, layero) {
					layer.close(index); //如果设定了yes回调，需进行手工关闭
					_this.ajaxDelete(id, isEnabled,callback);
				}, function (index) {

				});
			}

        },
		/**
		 * 删除公告
		 * @param id 数据id
		 */
		deleteNotice: function(id, isEnabled, callback) {
			$.ajax({
				type: "post",
				url: $("#contextPath").val() + "/notice/appNotice/deleteNotice",
				data: {
					"id": id,
					isEnabled: isEnabled
				},
				success: function (data) {
					var data = JSON.parse(data);
					if (data.code == '200') {
						layer.msg('删除成功')
						callback();
					} else {
						layer.msg(data.msg)
					}
				},
				error: function (error) {
					layer.msg('error')
				}
			});
		},
		/**
         * 上下线公告
         * @param id 数据id
         */
        ajaxDelete: function (id,isEnabled, callback) {
            $.ajax({
                type: "post",
                url: $("#contextPath").val() + "/notice/appNotice/deleteNotice",
                data: {
                    "id": id,
                    isEnabled: isEnabled
                },
                success: function (data) {
                    var data = JSON.parse(data);
                    if (data.code == '200') {
						layer.msg(isEnabled==1 ? '下线成功！':'上线成功！')
                        callback();
                    } else {
                        layer.msg(data.msg)
                    }
                },
                error: function (error) {
                    layer.msg('error')
                }
            });
        },

		/**
		 * 发布请求
		 * @param type 1为发布 2为驳回
		 * @param id 数据id
		 */
		ajaxPublish: function (type, id, callback) {
			$.ajax({
				type: "post",
				url: $("#contextPath").val() + "/notice/appNotice/approvalAppNotice",
				data: {
					"id": id,
					"state": type
				},
				success: function (data) {
					var data = JSON.parse(data);
					if (data.code == '200') {
						if (type == 1) {
							layer.msg('发布成功！')
						} else {
							layer.msg('驳回成功！')
						}
						callback();

					} else if(data.code == '400'){
						layer.msg('发布成功!'+data.msg)
					}else {
						layer.msg(data.msg)
					}
				},
				error: function (error) {
					layer.msg('error')
				}
			});
		},
        /**
         * 预览
         * @param type  noticeType 创建公告类型 1 公告 2 banner图文链接 3 banner跳转链接 4 生成链接
         * @param data 详情数据
         */
        previewPhone: function(data){
            if(data.noticeType==1){
                var notice = {
                    banner: data.coverUrl,
                    title: data.title,
                    con: data.content,
                    showTip: true,
					previewUrl: data.urlAddress
                };
                var noticeDetail = {
                    type: 'detail',
                    title: data.title,
                    con: data.content,
                    showTip: true,
					previewUrl: data.urlAddress
                }
                var app = {
                    type: 'main',
                    title: data.title,
                    con: data.content,
					previewUrl: data.urlAddress
                }
                //公告微信端
                $("body").append(template.render(tpl.noticeListTpl)(notice));

                //公告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(data.noticeType==2 && data.contentType==1){
                var wx = {
                    banner: data.coverUrl,
                    title: data.title,
                    con: data.content,
                    showTip: true,
					previewUrl: data.urlAddress
                };
                var wxDetail = {
                    type: 'detail',
                    title: data.title,
                    con: data.content,
                    showTip: true,
					previewUrl: data.urlAddress
                }
                var app = {
                    banner: data.coverUrl,
                    title: data.title,
                    con: data.content,
                    showTip: true,
					previewUrl: data.urlAddress
                }
                var appDetail = {
                    type: 'main',
                    title: data.title,
                    con: data.content,
                    showTip: true,
					previewUrl: data.urlAddress
                };
                //图文微信端
                $("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(data.noticeType==2 && data.contentType==2){
                var wx = {
                    banner: data.coverUrl
                };
                var app = {
                    banner: data.coverUrl
                }
                //图文微信端
                $("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(data.noticeType==3){
                var noticeDetail = {
                    type: 'detail',
                    title: data.title,
                    con: data.content,
                    showTab: true,
					previewUrl: data.urlAddress
                };
                //公告详情
                $("body").append(template.render(tpl.noticeDetailTpl)(noticeDetail));
            };
            $(".notice-mask,.notice-close-btn").on("click",function(){
                $(".notice-wrapper").remove();
            })
        }
	};
	appSend.init();
})
