var permDelete = $("#perm-delete").val(); //删除权限
var permEdit = $("#perm-edit").val(); //编辑权限
var permApprove = $("#perm-approve").val(); //审核权限
var userType = $("#userType").val();
var companyArr = []; // 运营中心列表
var companyId = '';
var orgArr = []; // 项目列表
/**
 * 邮件消息 邮件审核
 * 2018/4/20 by liufang
 */
$(function() {
	var table
	var detailApproveTyp=""
	var auditNoticePermission = $("#auditNoticePermission").val();
	var tpl = {
		"detailTpl": '<div class="dialog-wp">\
				<div class="mask"></div>\
				<div class="dialog dialog-email-con">\
					<div class="title-wp">\
						<span>消息详情</span>\
						<span class="close-btn"></button>\
					</div>\
					<div class="dialog-email-wp clearfloat">\
						<div class="d-email-left clearfloat">\
							<span  class="tips-wp">目标邮箱<br><span class="tips">(每行一个)</span></span>\
							<div class="email-list" >\
								<%for(var i =0 ;i<recipient_email.length;i++){%>\
									<div><%= recipient_email[i] %></div>\
								<% } %>\
							</div>\
						</div>\
						<div class="d-email-right clearfloat">\
							<div class="e-right-top clearfloat">\
								<span class="tips-wp">邮件主题</span>\
								<input type="text" class="e-theme-input" value="<%=email_theme %>" readonly/>\
							</div>\
							<div class="e-right-btm clearfloat">\
								<span class="tips-wp">邮件内容</span>\
								<div class="e-content-wp">\
									<div class="e-content-textarea" readonly><%= email_centent%></div>\
									<div class="e-attachment-wp clearfloat">\
										<span class="attach-tips">附件：</span>\
										<% for(var j =0;j<attach_ment.length;j++){%>\
											<a href="<%=attach_ment[j].url%>" class="attach-btn" download="<%=attach_ment[j].name%>"><%=attach_ment[j].name%></a>\
										<%}%>\
									</div>\
								</div>\
							</div>\
						</div>\
					</div>\
				</div>\
			</div>	',
		shTpl: '<div class="mask">\
							<div class="pop_wrap">\
								<div class="pop_title">邮件审核<span class="pop_close"></span></div>\
								<div class="pop_content pop_content_email">\
										<div class="part_ clearfloat">\
										<div class="part_title float-left">审核类型</div>\
										<div class="part_content float-left">\
											<select name="city" class="pop_select" id="approvalTApprovel">\
											<option value="">请选择审核类型</option>\
								  			</select>\
										</div>\
									</div>\
									<div class="part_ clearfloat">\
										<div class="part_title float-left">发件邮箱</div>\
										<div class="part_content float-left">\
											<select name="" class="pop_select eamil_select">\
												<% for(var i=0;i<emailList.length;i++){%>\
													<% if(emailList[i].id == res.accountId ){ %>\
														<option selected value="<%=emailList[i].id%>" email="<%=emailList[i].email_address%>"><%=emailList[i].email_address%></option>\
													<%}else{%>\
														<option value="<%=emailList[i].id%>" email="<%=emailList[i].email_address%>"><%=emailList[i].email_address%></option>\
													<%}%>\
												<%}%>\
											</select>\
										</div>\
									</div>\
									<div class="part_ clearfloat">\
										<div class="part_title float-left">目标用户</div>\
										<div class="part_content float-left">\
											<div class="target_wrap">\
												<%for(var i=0;i<personList.length;i++){%>\
													<label><input type="checkbox" name="account" value="<%=personList[i].id%>"  class="account_info" contactWay="<%=personList[i].contactWay%>"checked="checked"><span><%=personList[i].name%></span><span><%=personList[i].contactWay%></span><span class="dots_span"><%=personList[i].virName%></span></label>\
												<%}%>\
											</div>\
										</div>\
									</div>\
									<div class="part_ clearfloat">\
										<div class="part_title float-lefts">&nbsp</div>\
										<div class="part_content float-left">\
											共计: <span class="blue current_email_user_len txt_blue"><%=personLen%>人</span>\
										</div>\
									</div>\
									<div class="part_ clearfloat">\
										<div class="part_title float-left">邮件主题</div>\
										<div class="part_content float-left">\
											<input id="email_title" class="pop_input" type="text" value="<%=res.title%>"/>\
										</div>\
									</div>\
									<div class="part_ clearfloat">\
										<div class="part_title float-left">邮件内容</div>\
										<div class="part_content float-left">\
											<div class="part_content_wrap">\
												<div class="email-inform-con">\
									 				<div class="email-inform" id="myeditor"></div>\
									 			</div>\
											</div>\
										</div>\
									</div>\
									<div class="part_ clearfloat">\
										<div class="part_title float-left">附件</div>\
										<div class="part_content float-left">\
											<div class="add-attach-wp">\
							 					<div class="add-attach-btn">\
							 						<button class="btn-white-width90 btn">添加附件</button>\
							 						<input type="file" class="file-input" id="attach_File" name="uploadfile"/>\
							 					</div>\
							 					<div class="attach-list clearfloat">\
							 					</div>\
							 				</div>\
										</div>\
									</div>\
									<div class="part_ clearfloat">\
										<div class="part_title float-left">编辑时间</div>\
										<div class="part_content float-left"><%=res.editTime%></div>\
									</div>\
									<div class="part_ clearfloat">\
										<div class="part_title float-left">编辑人</div>\
										<div class="part_content float-left"><%=res.editUser%></div>\
									</div>\
									<div class="part_ clearfloat">\
										<div class="part_title float-left">发布状态</div>\
										<div class="part_content float-left"><%=stateStr%></div>\
									</div>\
									<div class="part_ part_state clearfloat">\
										<div class="part_title float-left">审核结果</div>\
										<div class="part_content float-left">\
											<div class="radio-wp">\
											   <span class="radio-input">\
												 <input type="radio" id="status1" class="radio-item status" data-status="1" name="status" checked/>\
												  <span class="radio-inner"></span>\
											   </span>\
											   <label class="radio-con" for="status1">通过</label>\
											</div>\
											<div class="radio-wp">\
											   <span class="radio-input">\
												 <input type="radio" id="status2" class="radio-item status" data-status="0" name="status" />\
												  <span class="radio-inner"></span>\
											   </span>\
											   <label class="radio-con" for="status2">不通过</label>\
											</div>\
										</div>\
									</div>\
									<div class="part_ part_suggest clearfloat">\
										<div class="part_title float-left">审核意见</div>\
										<div class="part_content float-left">\
											<div class="part_content_wrap">\
												<textarea id="contnet_suggest" class="pop_textarea"></textarea>\
											</div>\
										</div>\
									</div>\
									<div class="part_ part_btn clearfloat">\
										<span class="btn-red pop_sure_btn">确定</span>\
									</div>\
								</div>\
							</div>\
						</div>',
		xqTpl: '<div class="mask">\
							<div class="pop_wrap">\
								<div class="pop_title">邮件详情<span class="pop_close"></span></div>\
								<div class="pop_content pop_content_email">\
									<% if(res.isApproval==1 && res.approvalTypeName){ %>\
										<div class="part_ clearfloat" >\
										<div class="part_title float-left">审核类型</div>\
										<div class="part_content float-left">\
											<%=res.approvalTypeName%>\
										</div>\
										</div>\
										<%}%>\
									<div class="part_ clearfloat">\
										<div class="part_title float-left">发件邮箱</div>\
										<div class="part_content float-left">\
											<%=res.sendEmail%>\
										</div>\
									</div>\
									<div class="part_ clearfloat">\
									<div class="part_title float-left">发送对象</div>\
									<div class="part_content float-left">\
									<%=res.receiveType==2?"按部门/分组发送":"按邮箱发送"%>\
									</div>\
								</div>\
								<% if(res.receiveType==2){ %>\
									<div class="part_ clearfloat">\
									<div class="part_title float-left">项目/分组名称</div>\
									<div class="part_content float-left">\
										<%=depListStr%>\
									</div>\
								</div>\
									<%}%>\
									<div class="part_ clearfloat">\
										<div class="part_title float-left">目标用户</div>\
										<div class="part_content float-left">\
											<div class="target_wrap">\
												<%for(var i=0;i<personList.length;i++){%>\
													<label><span><%=personList[i].name%></span><span><%=personList[i].contactWay%></span><span class="dots_span"><%=personList[i].virName%></span></label>\
												<%}%>\
											</div>\
										</div>\
									</div>\
									<div class="part_ clearfloat">\
										<div class="part_title float-lefts">&nbsp</div>\
										<div class="part_content float-left">\
											共计: <span class="blue current_email_user_len txt_blue"><%=personLen%>人</span>\
										</div>\
									</div>\
									<div class="part_ clearfloat">\
										<div class="part_title float-left">邮件主题</div>\
										<div class="part_content float-left">\
											<%=res.title%>\
										</div>\
									</div>\
									<div class="part_ clearfloat">\
										<div class="part_title float-left">邮件内容</div>\
										<div class="part_content float-left">\
											<div class="part_content_wrap">\
												<div class="email-inform-con">\
									 				<div class="email-inform" id="myeditor"></div>\
									 			</div>\
											</div>\
										</div>\
									</div>\
									<div class="part_ clearfloat">\
										<div class="part_title float-left">附件</div>\
										<div class="part_content float-left">\
							 				<div class="attach-list clearfloat"></div>\
										</div>\
									</div>\
									<div class="part_ clearfloat">\
										<div class="part_title float-left">编辑时间</div>\
										<div class="part_content float-left"><%=res.editTime%></div>\
									</div>\
									<div class="part_ clearfloat">\
										<div class="part_title float-left">编辑人</div>\
										<div class="part_content float-left"><%=res.editUser%></div>\
									</div>\
									<div class="part_ clearfloat">\
										<div class="part_title float-left">发布状态</div>\
										<div class="part_content float-left"><%=stateStr%></div>\
									</div>\
									<ul class="dialog-wx-list">\
									<% for(var i=0;i<res.auditList.length;i++){%>\
									<li class=" clearfloat">\
										<span class="w-i-tips">审核人</span>\
										<span class="w-i-approve"><%=res.auditList[i].approvalUser%></span>\
									</li>\
									<li class=" clearfloat">\
										<span class="w-i-tips">审核时间</span>\
										<span class="w-i-approve"><%=res.auditList[i].approvalTime%></span>\
									</li>\
									<li class=" clearfloat">\
										<span class="w-i-tips">审核结果</span>\
										<span class="w-i-approve"><%=res.auditList[i].approvalResult==1?"通过":"不通过"%></span>\
									</li>\
									<li class="clearfloat">\
										<span class="w-i-tips">审核意见</span>\
										<span class="w-i-approve"><%=res.auditList[i].approvalOpinion%></span>\
									</li>\
									<%}%>\
								</ul>\
									<div class="part_ part_btn clearfloat">\
										<span class="btn-red pop_sure_btn">确定</span>\
									</div>\
								</div>\
							</div>\
						</div>',

						newShenHeTpl: '<div class="mask">\
						<div class="pop_wrap">\
							<div class="pop_title">邮件审核<span class="pop_close"></span></div>\
							<div class="pop_content pop_content_email">\
								<% if(res.isApproval==1){ %>\
								<div class="part_ clearfloat" >\
								<div class="part_title float-left">审核类型</div>\
								<div class="part_content float-left">\
									<%=res.approvalTypeName%>\
								</div>\
								</div>\
								<%}%>\
								<div class="part_ clearfloat">\
									<div class="part_title float-left">发件邮箱</div>\
									<div class="part_content float-left">\
										<%=res.sendEmail%>\
									</div>\
								</div>\
								<div class="part_ clearfloat">\
									<div class="part_title float-left">发送对象</div>\
									<div class="part_content float-left">\
										<%=res.receiveType==2?"按部门/分组发送":"按邮箱发送"%>\
									</div>\
								</div>\
								<% if(res.receiveType==2){ %>\
									<div class="part_ clearfloat">\
									<div class="part_title float-left">项目/分组名称</div>\
									<div class="part_content float-left">\
										<%=depListStr%>\
									</div>\
								</div>\
									<%}%>\
								<div class="part_ clearfloat">\
									<div class="part_title float-left">目标用户</div>\
									<div class="part_content float-left">\
										<div class="target_wrap">\
											<%for(var i=0;i<personList.length;i++){%>\
												<label><span><%=personList[i].name%></span><span><%=personList[i].contactWay%></span><span class="dots_span"><%=personList[i].virName%></span></label>\
											<%}%>\
										</div>\
									</div>\
								</div>\
								<div class="part_ clearfloat">\
									<div class="part_title float-lefts">&nbsp</div>\
									<div class="part_content float-left">\
										共计: <span class="blue current_email_user_len txt_blue"><%=personLen%>人</span>\
									</div>\
								</div>\
								<div class="part_ clearfloat">\
									<div class="part_title float-left">邮件主题</div>\
									<div class="part_content float-left">\
										<%=res.title%>\
									</div>\
								</div>\
								<div class="part_ clearfloat">\
									<div class="part_title float-left">邮件内容</div>\
									<div class="part_content float-left">\
										<div class="part_content_wrap">\
											<div class="email-inform-con">\
												 <div class="email-inform" id="myeditor"></div>\
											 </div>\
										</div>\
									</div>\
								</div>\
								<div class="part_ clearfloat">\
									<div class="part_title float-left">附件</div>\
									<div class="part_content float-left">\
										 <div class="attach-list clearfloat"></div>\
									</div>\
								</div>\
								<div class="part_ clearfloat">\
									<div class="part_title float-left">编辑时间</div>\
									<div class="part_content float-left"><%=res.editTime%></div>\
								</div>\
								<div class="part_ clearfloat">\
									<div class="part_title float-left">编辑人</div>\
									<div class="part_content float-left"><%=res.editUser%></div>\
								</div>\
								<% if(res.auditor){ %>\
									<div class="part_ clearfloat">\
										<div class="part_title float-left">审核人</div>\
										<div class="part_content float-left"><%=res.auditor%></div>\
									</div>\
								<%}%>\
								<% if(res.auditTime){ %>\
									<div class="part_ part_state clearfloat">\
										<div class="part_title float-left">审核时间</div>\
										<div class="part_content float-left">\
												<span><%=res.auditTime%></span>\
										</div>\
									</div>\
								<%}%>\
								<% if(res.isPass !== null){ %>\
									<div class="part_ part_state clearfloat">\
										<div class="part_title float-left">审核结果</div>\
										<div class="part_content float-left">\
											<% if(res.isPass === 0){ %>\
												<span>未通过</span>\
											<%}else if(res.isPass === 1){%>\
												<span>通过</span>\
											<%}%>\
										</div>\
									</div>\
								<%}%>\
								<ul class="dialog-wx-list">\
								<% for(var i=0;i<res.auditList.length;i++){%>\
								<li class=" clearfloat">\
									<span class="w-i-tips">审核人</span>\
									<span class="w-i-approve"><%=res.auditList[i].approvalUser%></span>\
								</li>\
								<li class=" clearfloat">\
									<span class="w-i-tips">审核时间</span>\
									<span class="w-i-approve"><%=res.auditList[i].approvalTime%></span>\
								</li>\
								<li class=" clearfloat">\
									<span class="w-i-tips">审核结果</span>\
									<span class="w-i-approve"><%=res.auditList[i].approvalResult==1?"通过":"不通过"%></span>\
								</li>\
								<li class="clearfloat">\
									<span class="w-i-tips">审核意见</span>\
									<span class="w-i-approve"><%=res.auditList[i].approvalOpinion%></span>\
								</li>\
								<%}%>\
							</ul>\
							<div class="part_ part_state clearfloat">\
										<div class="part_title float-left">审核结果</div>\
										<div class="part_content float-left">\
											<div class="radio-wp">\
											   <span class="radio-input">\
												 <input type="radio" id="status1" class="radio-item status" data-status="1" name="status" checked/>\
												  <span class="radio-inner"></span>\
											   </span>\
											   <label class="radio-con" for="status1">通过</label>\
											</div>\
											<div class="radio-wp">\
											   <span class="radio-input">\
												 <input type="radio" id="status2" class="radio-item status" data-status="0" name="status" />\
												  <span class="radio-inner"></span>\
											   </span>\
											   <label class="radio-con" for="status2">不通过</label>\
											</div>\
										</div>\
									</div>\
									<div class="part_ part_suggest clearfloat">\
										<div class="part_title float-left">审核意见</div>\
										<div class="part_content float-left">\
											<div class="part_content_wrap">\
												<textarea id="contnet_suggest" class="pop_textarea"></textarea>\
											</div>\
										</div>\
									</div>\
								<div class="part_ part_btn clearfloat">\
								<span class="btn-cancle-blue pop_btn_sh_cancle">取消</span>\
									<span class="btn-red pop_sure_btn_sh">确定</span>\
								</div>\
							</div>\
						</div>\
					</div>',
		"attachTpl": '\
						<div class="attach-item" data-url="<%= url %>" data-name="<%= name%>">\
 							<span class="attach-item-name"><%= name%></span>\
 							<span class="a-item-del-btn"></span>\
 						</div>\
						',
		"attachListTpl": '<% for(var i=0;i<list.length;i++){%>\
							<div class="attach-item" data-url="<%= list[i] %>" data-name="<%= list[i].split(";")[1]%>">\
								<span class="attach-item-name"><%= list[i].split(";")[1]%></span>\
								<span class="a-item-del-btn"></span>\
							</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 contextPath = $("#contextPath").val()
	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);
				}
			})
			// 关闭公共弹层
			$('body').on('click', '.pop_close', function(event) {
				event.preventDefault();
				/* Act on the event */
				$('.mask').remove()
			});
			//添加附件
			$('body').on("change", ".file-input", function () {
				var name = $(this)[0].files[0].name;
				_this.addAttach(name);
			});

			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){
							_this.getIfCanApproval(data.data[0].value)
						}
					} 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(orgid){
			var _this=this
			  $.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));
						  $("#approvalTApprovel").html(template.render(tpl.typeTpl)(data));
						  $("#approvalTApprovel").val(_this.detailApproveTyp)
					  } else {
						  layer.msg(data.msg)
					  }
				  },
				  error: function (error) {
					  layer.msg('error')
				  }
			  });
		  },

	getIfCanApproval(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;
			layui.use('table', function() {
			table = layui.table;

				//方法级渲染
				table.render({
					elem: '#LAY_table_user',
					url: contextPath + "/notice/emailSend/getList",
					skin: 'nob' //行边框风格
						,
					even: true //开启隔行背景
						,
					size: 'lg' //小尺寸的表格
						,
					cols: [
						[{
							title: '序号',
							templet: '#indexTpl',
							width: 80
						}, {
							field: 'createTime',
							title: '时间',
							minWidth: 200
						}, {
							field: 'fullName',
							title: '发件人',
							width: 200
						}, {
							field: 'sendEmail',
							title: '发件邮箱',
							minWidth: 230
						}, {
							field: 'email_theme',
							title: '主题',
							minWidth: 200
						}, {
							field: 'contentTxt',
							title: '内容',
							minWidth: 200
						}, {
							field: 'fullName',
							title: '编辑人',
							width: 100
						}, {
							field: 'roleName',
							title: '当前审核角色',
							width: 100
						}, {
							field: 'state',
							title: '发布状态',
							width: 100,
							templet: function(data) {
								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 '原文链接'
								}
							}
						}, {
							field: 'approval_user',
							title: '审核人',
							width: 100
						}, {
							field: 'approval_time',
							title: '审核时间',
							minWidth: 200
						}, {
							field: 'id',
							title: '可操作',
							fixed: 'right',
							width: 260,
							align: 'center',
							templet: function(data) {
								var str = '';
								if (data.state == 0) {
									if(data.isApproval==1 || data.approvalType==0){
										str += '<button class="t-btn t-red-btn t-sh-btn" data-id=' + data.id + ' data-type="1">审核</button>';
									}
								}
								str += '<button class="t-btn t-red-btn t-xq-btn" data-id=' + data.id + ' data-type="3">详情</button>';
								// if (data.state == 0) {
								//     if (permApprove == 1) {
								//         str += '<button class="t-btn t-red-btn t-publish-btn" data-id=' + data.id + ' data-type="1">发布</button>';
								//         str += '<button class="t-btn t-white-btn t-reject-btn" data-id=' + data.id + ' data-type="2">驳回</button>';
								//     }
								//     if (permEdit == 1) {
								//         str += '<button class="t-btn t-red-btn t-edit-btn" data-id=' + data.id + ' data-type="2">编辑</button>';
								//     }
								// }
								if (permDelete == 1) {
									str += '<button class="t-btn t-white-btn t-delete-btn" data-id=' + data.id + ' 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) {
						// 详情
						$('.t-xq-btn').on('click', function(event) {
							event.preventDefault();
							var id = $(this).attr('data-id')
							$.ajax({
								type: "post",
								url: $("#contextPath").val() + "/notice/emailSend/getDetailInfo",
								data: {
									id: id,
									type:2,
								},
								success: function(data) {
									var res = data.data
									var orgId = res.orgId
									var emailList = _this.getUserEmail(orgId)
									if(res.state == '0'){
										var stateStr = '未审核'
									}else if(res.state == '1'){
										var stateStr = '已发布'
									}else if(res.state == '2'){
										var stateStr = '已驳回'
									}
									var  depListStr=''
									if(res.deptGroupList && res.deptGroupList.length>0){
										for (const key in res.deptGroupList) {
											depListStr+=res.deptGroupList[key].name+','
										}

									}
									$("body").append(template.render(tpl.xqTpl)({
										res: res,
					            		personList: res.userList,
					            		personLen: res.userList.length,
					            		stateStr: stateStr,
					            		emailList: emailList,
										depListStr:depListStr.substring(0,depListStr.length-1)
									}));
									// 渲染邮件内容
									editor = 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 //contextPath
									});
									editor.render("myeditor");
									editor.ready(function() {
										editor.setHeight(270);
										var ue = UE.getEditor('myeditor');
										ue.setContent(res.emailCentent);
									});
									// 渲染附件内容
									_this.renderExtraFile(res.attachment)
									// 确定
									$('.pop_sure_btn').on('click', function(event) {
										event.preventDefault();
										/* Act on the event */
										$('.mask').remove()
									});
								},
								error: function(error) {
									layer.msg('error')
								}
							});
						});

						// 审核
						$('.t-sh-btn').on('click', function(event) {
							event.preventDefault();
							var id = $(this).attr('data-id')
							$.ajax({
								type: "post",
								url: $("#contextPath").val() + "/notice/emailSend/getDetailInfo",
								data: {
									id: id,
									type:2,
								},
								success: function(data) {
									var res = data.data
									var orgId = res.orgId
									var emailList = _this.getUserEmail(orgId)
									if(res.state == '0'){
										var stateStr = '未审核'
									}else if(res.state == '1'){
										var stateStr = '已发布'
									}else if(res.state == '2'){
										var stateStr = '已驳回'
									}
									var  depListStr=''
									if(res.deptGroupList && res.deptGroupList.length>0){
										for (const key in res.deptGroupList) {
											depListStr+=res.deptGroupList[key].name+','
										}

									}
									$("body").append(template.render(tpl.newShenHeTpl)({
										res: res,
					            		personList: res.userList,
					            		personLen: res.userList.length,
					            		stateStr: stateStr,
					            		emailList: emailList,
										depListStr:depListStr.substring(0,depListStr.length-1)
									}));
									// 渲染邮件内容
									editor = 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 //contextPath
									});
									editor.render("myeditor");
									editor.ready(function() {
										editor.setHeight(270);
										var ue = UE.getEditor('myeditor');
										ue.setContent(res.emailCentent);
									});
									// 渲染附件内容
									_this.renderExtraFile(res.attachment)
									// 确定
									$('.pop_sure_btn_sh').on('click', function(event) {
										event.preventDefault();
										/* Act on the event */
										_this.eve_sure_sh(res)

									});
									//取消
									$('.pop_btn_sh_cancle').on('click', function(event) {
										event.preventDefault();
										/* Act on the event */
										$('.mask').remove()
									});

								},
								error: function(error) {
									layer.msg('error')
								}
							});
						});
						// 审核  此功能类似编辑  留着以后用
						// $('.t-sh-btn').on('click', function(event) {
						// 	event.preventDefault();
						// 	var id = $(this).attr('data-id')
						// 	$.ajax({
						// 		type: "post",
						// 		url: $("#contextPath").val() + "/notice/emailSend/getDetailInfo",
						// 		data: {
						// 			id: id,
						// 			type:2,
						// 		},
						// 		success: function(data) {
						// 			// 同步获取一波发件人邮箱列表
						// 			var res = data.data
						// 			var orgId = res.orgId
						// 			_this.detailApproveTyp=res.approvalType
						// 			_this.getProjectList();
						// 			var emailList = _this.getUserEmail(orgId)
						// 			if(res.state == '0'){
						// 				var stateStr = '未审核'
						// 			}else if(res.state == '1'){
						// 				var stateStr = '已发布'
						// 			}else if(res.state == '2'){
						// 				var stateStr = '已驳回'
						// 			}
						// 			$("body").append(template.render(tpl.shTpl)({
						// 				res: res,
					    //         		personList: res.userList,
					    //         		personLen: res.userList.length,
					    //         		stateStr: stateStr,
					    //         		emailList: emailList
						// 			}));
						// 			// 渲染邮件内容
						// 			editor = 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 //contextPath
						// 			});
						// 			editor.render("myeditor");
						// 			editor.ready(function() {
						// 				editor.setHeight(270);
						// 				var ue = UE.getEditor('myeditor');
						// 				ue.setContent(res.emailCentent);
						// 			});
						// 			// 渲染附件内容
						// 			_this.renderExtraFile(res.attachment)
						// 			// 确定审核事件
						// 			$('.pop_sure_btn_sh').on('click', function(event) {
						// 				event.preventDefault();
						// 				/* Act on the event */
						// 				_this.eve_sure_edit(res)
						// 			});
						// 			// 目标用户选中监听
						// 			$('.account_info').on('change', function(event) {
						// 				event.preventDefault();
						// 				var domCheckedlen = $('.account_info:checked').length
						// 				$('.current_email_user_len').text(domCheckedlen+'人')
						// 			});
						// 		},
						// 		error: function(error) {
						// 			layer.msg('error')
						// 		}
						// 	});
						// });
						//如果是异步请求数据方式，res即为你接口返回的信息。
						//查看详情
						$(".check-blue-btn").on("click", function() {
							var id = $(this).data("id");
							//显示详情弹窗
							_this.showDetailDialog(id)
						});
						//发布
						$(".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 + "/notice/emailSend/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(),
										"approvalType": $("#approvalType").val(),
										"orgId": $("#conditionform #orgId").attr('org__id')
									},
									page: {
										curr: 1 //重新从第 1 页开始
									}
								});
							});
						});
						//删除
						$(".t-delete-btn").on("click", function() {
							var id = $(this).data("id");
							_this.delete(id, function() {
								table.reload('testReload', {
									url: contextPath + "/notice/emailSend/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(),
										"noticeType": $("#noticeType").val(),
										"approvalType": $("#approvalType").val(),
										"orgId": $("#conditionform #orgId").attr('org__id')
									},
									page: {
										curr: 1 //重新从第 1 页开始
									}
								});
							});
						});
						$(".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 + "/notice/emailSend/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(),
										"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/emailPublish?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 + "/notice/emailSend/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(),
							"approvalType": $("#approvalType").val(),
							"orgId": $("#conditionform #orgId").attr('org__id')
						},
						page: {
							curr: 1 //重新从第 1 页开始
						}
					});
				});
			});
		},

		// 请求收件人邮箱
		getUserEmail: function(orgId){
				var emailArr = []
				if(!orgId){layer.msg("请选择项目");return}
				$.ajax({
					type: "post",
					url: contextPath + "/notice/emailSend/getUserEmail",
					data: {
						orgIds:orgId
					},
					async: false,
					success: function (data) {
						var obj =  JSON.parse(data)
						emailArr = obj.data['items']
					},
					error: function (error) {
						layer.msg('error')
					}
				});
				return emailArr
		},
		// 确定审核事件
		eve_sure_sh: function(res){
			console.log("确定审核",res)
			//邮箱内容
			var emailCentent = res.emailCentent
			var content = res.content
			//附件地址
			var attach_ment = res.attachment

			// 用户信息
			var userList = res.userList

			// 其他
			var title =  res.title

			//审核
			var isPass = $(".radio-item.status:checked").data("status")
			var auditOpinion = $('#contnet_suggest').val()

			var accountId = res.accountId
			var sendEmail = res.sendEmail


			var formdata = new FormData();
			formdata.append("id", res.id)
			formdata.append("orgId", res.orgId)
			formdata.append("type", 2)

			formdata.append("accountId", accountId)
			formdata.append("sendEmail", sendEmail)
			formdata.append("usersList", JSON.stringify(userList))
			formdata.append("title", title)
			formdata.append("content", content)
			formdata.append("emailCentent", emailCentent)
			formdata.append("isPass", isPass)
			formdata.append("attachment", attach_ment)
			formdata.append("auditOpinion", auditOpinion)

			$.ajax({
        type: "post",
        url: $("#contextPath").val() + "/notice/emailSend/approvalSendNew",
        data: formdata,
        cache: false, // 不缓存
        processData: false, // 告诉jQuery不要去处理发送的数据
        contentType: false, // 告诉jQuery不要去设置Content-Type请求头
        success: function (data) {
          if (data.code == 200) {
          	layer.msg('审核完成')
          	$('.mask').remove()
          	table.reload('testReload', {
							url: contextPath + "/notice/emailSend/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(),
								"noticeType": $("#noticeType").val(),
								"approvalType": $("#approvalType").val(),
								"orgId": $("#conditionform #orgId").attr('org__id')
							},
							page: {
								curr: 1 //重新从第 1 页开始
							}
						});
          } else if(data.code == 400){
			layer.msg('审核完成'+data.msg)
			$('.mask').remove()
			table.reload('testReload', {
						  url: contextPath + "/notice/emailSend/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(),
							  "noticeType": $("#noticeType").val(),
							  "approvalType": $("#approvalType").val(),
							  "orgId": $("#conditionform #orgId").attr('org__id')
						  },
						  page: {
							  curr: 1 //重新从第 1 页开始
						  }
					  });
		  }else {
            layer.msg(data.msg)
          }
        },
        error: function () {
          // layer.msg('系统繁忙.....')
        }
      });
		},

		// 确定编辑事件
		eve_sure_edit: function(res){
			console.log("eve_sure_edith",res)
			//邮箱内容
			var ue = UE.getEditor('myeditor');
			var emailCentent = ue.getContent();
			var content = ue.getContentTxt();;
			//附件地址
			var urlList = [];
			$(".attach-item").each(function (index, ele) {
				var str = $(ele).data("url")
				urlList.push(str)
			})

			// 用户信息
			var userList = res.userList
			var contactwayArr = []
			var dom = $('.account_info')
			$.each(dom,function(index, el) {
				if($(el).is(':checked')){
					contactwayArr.push($(el).attr('contactway'))
				}
			});
			var realUserList = userList.filter(function(item, index, arr) {
				return (contactwayArr.indexOf(item.contactWay) >- 1)
			})
			// 其他
			var title =  $('#email_title').val()
			var isPass = $(".radio-item.status:checked").data("status")
			var auditOpinion = $('#contnet_suggest').val()
			var accountId = $('.eamil_select').val()
			var sendEmail = $('.eamil_select').find("option:selected").attr("email");
			var attach_ment = urlList.join(",");

			var formdata = new FormData();
			formdata.append("id", res.id)
			formdata.append("orgId", res.orgId)
			formdata.append("type", 2)

			formdata.append("accountId", accountId)
			formdata.append("sendEmail", sendEmail)
			formdata.append("usersList", JSON.stringify(realUserList))
			formdata.append("title", title)
			formdata.append("content", content)
			formdata.append("emailCentent", emailCentent)
			formdata.append("isPass", isPass)
			formdata.append("attachment", attach_ment)
			formdata.append("auditOpinion", auditOpinion)

			$.ajax({
        type: "post",
        url: $("#contextPath").val() + "/notice/emailSend/approvalSendNew",
        data: formdata,
        cache: false, // 不缓存
        processData: false, // 告诉jQuery不要去处理发送的数据
        contentType: false, // 告诉jQuery不要去设置Content-Type请求头
        success: function (data) {
          if (data.code == 200) {
          	layer.msg('审核完成')
          	$('.mask').remove()
          	table.reload('testReload', {
							url: contextPath + "/notice/emailSend/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(),
								"noticeType": $("#noticeType").val(),
								"approvalType": $("#approvalType").val(),
								"orgId": $("#conditionform #orgId").attr('org__id')
							},
							page: {
								curr: 1 //重新从第 1 页开始
							}
						});
          } else {
            layer.msg(data.msg)
          }
        },
        error: function () {
          // layer.msg('系统繁忙.....')
        }
      });
		},
		/**
		 * 添加附件
		 * @param name
		 */
		addAttach: function (name) {
			var _this = this;
			$.ajaxFileUpload({
				url: contextPath + "/notice/emailSend/uploadFile", //用于文件上传的服务器端请求地址
				secureuri: false, //是否需要安全协议，一般设置为false
				fileElementId: 'attach_File', //文件上传域的ID
				dataType: 'String', //返回值类型 一般设置为json
				success: function (data, status) //服务器成功响应处理函数
				{
					// console.log(data,222);
					var data = JSON.parse(data);
					if (data.code == '200') {
						var name = data.data.split(";")[1];
						$(".attach-list").append(template.render(tpl.attachTpl)({
							name: name,
							url: data.data
						}));
						//删除附件
						$(".a-item-del-btn").on("click", function () {
							$(this).closest(".attach-item").remove();
						})
					} else {
						alert(data.msg);

					}
				}
			})
		},
		/**
		 * 渲染附件
		 * @param attach_ment
		 */
		renderExtraFile: function (attach_ment) {
			if (!!attach_ment) {
				var attachList = attach_ment.split(",");
				$(".attach-list").append(template.render(tpl.attachListTpl)({
					list: attachList
				}));
				//删除附件
				$(".a-item-del-btn").on("click", function () {
					$(this).closest(".attach-item").remove();
				})
			}
		},
		/**
		 * 显示详情弹窗
		 * @param id
		 */
		showDetailDialog: function(id) {
			var _this = this;
			_this.ajaxDetail(id, function(data) {
				var attachList = data.attach_ment.split(",");
				var aList = [];
				for (var i = 0; i < attachList.length; i++) {
					var obj = {
						name: attachList[i].split(";")[1],
						url: attachList[i].split(";")[0]
					}
					aList.push(obj)
				};
				var data = {
					email_theme: data.email_theme,
					email_centent: data.email_centent,
					recipient_email: data.recipient_email.split(";"),
					attach_ment: aList
				};
				data.baseUrl = contextPath;
				$("body").append(template.render(tpl.detailTpl)(data));
				//关闭弹窗
				$(".close-btn").on("click", function() {
					$(".dialog-wp").remove();
				});
				//					$(".attach-btn").on("click",function(){
				//						var url = $(this).data("url");
				//						window.location.href = contextPath+"/upload/"+url;
				//					})
			})
		},
		ajaxDetail: function(id, callback) {
			var _this = this;
			$.ajax({
				type: "post",
				url: contextPath + "/notice/emailSend/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) {

				});
			}
		},
		/**
		 * 删除
		 * @param type
		 * @param id
		 * @param callback
		 */
		delete: function(id, callback) {
			var _this = this;
			layer.confirm('确定删除?', {
				btn: ['确定', '取消']
			}, function(index, layero) {
				layer.close(index); //如果设定了yes回调，需进行手工关闭
				_this.ajaxDelete(id, callback);
			}, function(index) {

			});

		},

		/**
		 * 删除公告
		 * @param id 数据id
		 */
		ajaxDelete: function(id, callback) {
			$.ajax({
				type: "post",
				url: contextPath + "/notice/emailSend/deleteNotice",
				data: {
					"id": id
				},
				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 type 1为发布 2为驳回
		 * @param id 数据id
		 */
		ajaxPublish: function(type, id, callback) {
			$.ajax({
				type: "post",
				url: contextPath + "/notice/emailSend/approval",
				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 {
						layer.msg(data.msg)
					}
				},
				error: function(error) {
					layer.msg('error')
				}
			});
		}
	};
	appSend.init();
})
