notice.js 14.8 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504
var currentDetails = null;
var currentPage=1;//当前页
var pageNum = 5;//最多显示页数
var selectedbgcolor = "rgb(238, 249 ,255)";
var isExpand = false;
var gid;
var contentpath=null;
var condition=null;
var thePlaceholder=null;
var curserver;
var newNewsType = null;
/* LXJ 释放此处注释*/
var arrType=new Array();
arrType[0]="信息快报";
arrType[1]="党团建设";
$(document).ready(function () {
	// 获取权限
	newNewsType = getPrivalige("新闻公告");
	var startTime = new Date().getTime();
	curserver = CONF_BACK_SERVERURL
	contentpath=$("#contentpath").val();
	thePlaceholder=$("#searchInput").attr("placeholder");
	focusAndOnblur(thePlaceholder);
	getRoleChildrenPrivilege("新闻公告");
	load();
	//添加通知公告
    $("#btnNoticeAdd").click(addNotice);
    var endTime = new Date().getTime();
    endTime = endTime-startTime;
    console.info('notice-inside执行时间:'+endTime);
   
    
    /********************hyh  新增 当没有公告在列表上时,将分页隐藏 2017、9、21***********************/
    var NewsLenght=$("#dealedData").find(".col-xs-12");
    if(NewsLenght.length<=0){
    	$("#dealedData").next(".nav-page").css("display","none");
    }
    
    
/*	//hyh 新增    分页框回车事件   2017/10/31
	$("body").on("keyup keykeypress","[id='targetPage']",function(evt){
		 if (evt.keyCode == 13) {
		var page=parseInt($("#targetPage").val());
		if(page==NaN){return}
		if(page<-1||page>totalpage){
			$("#targetPage").val("");
			layer.msg("目标页超出页码范围!");
			return}
		currentPage = page;
		getdealedlist(currentPage);
		 }
	});*/
	
	$('#searchInput').bind('keypress', function (event) {
        if (event.keyCode == "13") {
        	condition=$("#searchInput").val();
        	getdealedlist(1);
        }
    });
	/* LXJ 释放此处注释*/
	clickAction();
	setTimeout(function() {parent.window.NProgress.done()}, 500);
});
// 按类型的查找   /* LXJ 释放此处注释*/
function clickAction(){
	$("#allselected, #jrkb, #dtjs").click(function(e) {
		condition = '';
		console.log(e.currentTarget.id);
		var id=e.currentTarget.id;
		if(id=="allselected"){
			var doctype = $("#allselected");
			if(doctype[0].className!="div-checkbox-selected"){
				$("#allselected").attr("class", "div-checkbox-selected");
				$("#allselected").find("img").attr("src", global.contextPath+"/image/officedocument/32x32/menu-document-selected.png");
			}
		}else if(id=="jrkb"){
			var doctype = $("#jrkb");
			if(doctype[0].className=="div-checkbox-selected"){
				$("#jrkb").attr("class", "div-checkbox");
				$("#jrkb").find("img").attr("src", global.contextPath+"/image/officedocument/32x32/menu-document-checkbox.png"); 
			}else{
				$("#jrkb").attr("class", "div-checkbox-selected");
				$("#jrkb").find("img").attr("src", global.contextPath+"/image/officedocument/32x32/menu-document-selected.png");
				$("#allselected").attr("class", "div-checkbox");
				$("#allselected").find("img").attr("src", global.contextPath+"/image/officedocument/32x32/menu-document-checkbox.png");
			}
		}else if(id=="dtjs"){
			var doctype = $("#dtjs");
			if(doctype[0].className=="div-checkbox-selected"){
				$("#dtjs").attr("class", "div-checkbox");
				$("#dtjs").find("img").attr("src", global.contextPath+"/image/officedocument/32x32/menu-document-checkbox.png"); 
			}else{
				$("#dtjs").attr("class", "div-checkbox-selected");
				$("#dtjs").find("img").attr("src", global.contextPath+"/image/officedocument/32x32/menu-document-selected.png"); 
				$("#allselected").attr("class", "div-checkbox");
				$("#allselected").find("img").attr("src", global.contextPath+"/image/officedocument/32x32/menu-document-checkbox.png");
		}
		}
    	var doctype = $("#doctype-selecttype .div-checkbox-selected");
    	if(doctype.length == 1 || doctype.length == 2) {
    		arrType.length = 0;
    		for(var i=0; i<doctype.length; i++){
    			arrType[i] = doctype[i].innerText;
    		}
    		if(doctype.length == 1){
    			condition = doctype[0].innerText;
    		} else {
    			$("#jrkb").attr("class", "div-checkbox");
				$("#jrkb").find("img").attr("src", global.contextPath+"/image/officedocument/32x32/menu-document-checkbox.png"); 
    			$("#dtjs").attr("class", "div-checkbox");
    			$("#dtjs").find("img").attr("src", global.contextPath+"/image/officedocument/32x32/menu-document-checkbox.png"); 
				$("#allselected").attr("class", "div-checkbox-selected");
				$("#allselected").find("img").attr("src", global.contextPath+"/image/officedocument/32x32/menu-document-selected.png");
				condition = '';
    		}
    	}else {
    		arrType.length = 0;
    		arrType[0] = "全部";
    		condition = null;
    	}
    	getdealedlist(1);
    });
}
function event(){
	$("#searchbtninfo").click(function () {    	
    	condition=$("#searchInput").val();
    	thePlaceholder=$("#searchInput").attr("placeholder");
    	if(condition==thePlaceholder){
    		condition="";
    		}
    		getdealedlist(1);
    }); 
    //编辑事件
    $(".div-notice-edit").click(editNotice);
    //删除事件
    $(".div-notice-remove").click(removeNotice);
}


//打开时加载页面数据
function load(){
	getdealedlist(1);
}
/**
 * 获取公告列表
 */
function getdealedlist(pageIndex) {
	$(this).ajaxStart(function(){   //公告栏详情的加载loading
		parent.window.$.showLoading();
	});
	
	$(this).ajaxStop(function(){
		parent.window.$.hideLoading();
	});
	currentPage = pageIndex;
	if(condition==null){condition="";}
	$.ajax({
        type: 'POST',
        dataType: 'json',
        url: curserver + global.modelctls.homepage.list,
        headers:{
    		"token":$.cookie('ftoken')
	    },
        data: {pageIndex : pageIndex,pageSize : 16,listtype:"公告",condition:condition},
        success: function (result) {
        	var totalre = result["total"];
    		dataList(result.Data);
    		pageWidget(totalre);
    		if(totalre > 0) {
    			$("#msg").css("display", "none");
    			$("#nvaTab").css("display", "block");
    		}else {
    			$("#nvaTab").css("display", "none");
    			$("#msg").css("display", "block")
    		}
        },
        error: function (error, status, text) {
        	parent.window.$.hideLoading();
        }
	});
}

//获取登录用户信息(角色、单位)
function getUserDetail(){
	var user =null;
	$.ajaxSetup({
		async : false //取消异步
	});	
	 $.post(curserver + global.modelctls.document.getUserDetail, function (result) {
       user=result;
     });
	 return user;
}

//添加
function addNotice() {
	action("add");
}
function  isManager(){
	var user =getUserDetail();
	var role="通知公告管理员";
	var roles=user.role;
	var rolename=null;
	var roleObj=null;
	var isManager=false;
	for(var i=0;i<roles.length;i++){
		roleObj=roles[i];
		rolename=roleObj["角色"];
		if(rolename==role){
			isManager=true;
			break;
		}
	}
	if(!isManager){
		$("#btnNoticeAdd,.glyphicon-trash,.glyphicon-edit").remove();
	}
	return isManager;
}
/**
 * 编辑公告
 */
function editNotice(evt) {
	evt.stopPropagation();
	var gid = this.id;
	action("edit&gid=" + gid);
}
function action(action) {
	var title = "";
	if (action == "add") {
		title = "新建通知公告";
	} else {
		title = "编辑通知公告";
	}
	var index = parent.layer.open({
		type : 2,
		title : [title,'font-size:16px; color:#FFF; background-color:#0096eb;'],
		shadeClose : true,
		shade : 0.3,// 遮罩透明度
		moveType : 0, // 拖拽风格,0是默认,1是传统拖动
		area : [ '550px', '600px' ],
		content : CONF_FRONT_SERVERURL
				+ 'view/index/homeContent/notice-add.jsp?action=' + action,
		btn : [ '确定', '取消' ],
		yes : function(index, layero) {
			$.cookie("uuid", "null");
			var iframeWin = parent.window[layero.find('iframe')[0]['name']];
			var addData = iframeWin.getdata();
			var dataString = JSON.stringify(addData);

			if (action == "add") {
				$.ajax({
					type : 'POST',
					url : curserver + global.modelctls.homepage.create,
					headers : {
						"token" : $.cookie('ftoken')
					},
					data : {
						data : dataString
					},
					success : function(result) {
						gid = result;

						updatefjlog(gid, addData.filepath);
						parent.layer.msg("操作成功", {
							icon : 1
						});
						parent.layer.close(index); // 再执行关闭
						parent.window.$.hideLoading(); // 关闭加载动画
						load();

					},
					error : function(result) {
						console.log(result);
					}
				});
			} else {
				$.ajax({
					type : 'POST',
					url : curserver + global.modelctls.homepage.alter,
					headers : {
						"token" : $.cookie('ftoken')
					},
					data : {
						data : dataString
					},
					success : function(result) {
						updatefjlog(gid, addData.filepath);
						parent.layer.msg("操作成功", {
							icon : 1
						});
						parent.layer.close(index); // 再执行关闭
						load();
					}
				});
			}
		},
		end : function(index, layero) {
			$.cookie("uuid", "null");
		}
	});
}

/**
 * 删除公告
 */
function removeNotice(evt) {
	evt.stopPropagation();
	var gid = this.id;
    //询问框
    parent.layer.confirm('是否删除?', {
        btn: ['是', '否'] //按钮
    }, function (index) {
    	deleteByGid(gid)
    	parent.layer.close(index);
    	load();	
    }, function (index) {
    });
}
function deleteByGid(gid){
	$.ajax({
        type: 'POST',
        dataType: 'json',
        url: curserver + global.modelctls.homepage.deleteByGid,
        headers:{
    		"token":$.cookie('ftoken')
	    },
        data: {gid:gid},
        success: function (result) {
        	console.log(result);
        }
  });
}

/**
 * 行按钮权限控制
 * @returns
 */
function getButtonJurisdiction() {
	var bj = {};
	bj.edit = "";
	bj.remove = ""
	if(listPrivilege) {
		for(var i=0; i<listPrivilege.length; i++) {
			listPrivilege[i].alias == "编辑" ? bj.edit="      <div class='div-notice-edit'><span class='glyphicon glyphicon-edit'></span></div>" : false;
			listPrivilege[i].alias == "删除" ? bj.remove="      <div class='div-notice-remove'><span class='glyphicon glyphicon-trash'></span></div>" : false;
		}
	}
	return bj;
}

function pageWidget(total) {
	layui.use('laypage', function(){
		var laypage = layui.laypage;
		laypage.render({
			elem: 'laypage'
			,count: total
			,curr: currentPage
		  	,theme:"#337ab7"
			,layout: ['count', 'prev', 'page', 'next', 'skip']
			,jump: function(obj, first){
				currentPage = obj.curr;
				//首次不执行
				if(!first){
					getdealedlist(currentPage);
				}
			  }
		});
	});	
}
function dataList(data) {
	var tableTop =  66;//$("#nvaTab").offset().top;
	var bodyPadding = parseInt($("body").css("padding"));
	var iframeTop = window.parent.$("#iframecontent").offset().top;
	var height = 'full-' + (iframeTop + bodyPadding + tableTop);
	layui.use('table', function() {
		var table = layui.table;
		table.render({
			elem: '#dataList',
			cols: [[
				{field: '公告标题', title: '标题',style:'cursor: pointer;', event:'titleEvent', templet:function(d){return titleTemplet(d)}},
				{field: '创建时间', title: '创建时间',style:'cursor: pointer;',width:200, event:'titleEvent', templet:function(d){return timeTemplet(d)}}
			]],
			data: data,
			limit:16,
			skin: 'line',
			height: height,
			done: function(res, curr, count){
				event();
				$("#nvaTab .layui-table-main tr").each(function() {
					isShowDelAndEdit(this)
//					$(this).mouseover(function(){
//						$(this).find(".glyphicon").css("display", "block");
//					});
//					$(this).mouseout(function(){
//						$(this).find(".glyphicon").css("display", "none");
//					});
				});
			}
		});
		table.on('tool(listEvent)', function(obj){
			var data = obj.data;
			openDetail(data);
		});
	});
}

function titleTemplet(data) {
	var today = new Date().format("yyyy-MM-dd");
	var createDate = new Date(data.创建时间).format("yyyy-MM-dd");
	var conditions = condition.split(" ");
	var title = data.公告标题;
	if(title){
		for(var i=0;i<conditions.length;i++){
			if(title.indexOf(conditions[i]) != -1){
				title = title.replace(conditions[i],"<span style='color:red;'>"+conditions[i]+"</span>");
			}
		}
	}
	var templet = '<div ><span class="div-notice-type">['+data.公告类型+']</span>' + title;
	// 党团建设类型显示红色字体   /* LXJ 释放此处注释*/
	if(data.公告类型 == "党团建设"){
		templet = '<div ><span class="div-notice-type" style="color:red;">['+data.公告类型+']</span>' + title;	
	}
	//公告有附件, 显示附件图片
	if(data.附件路径) {
		templet = '<div ><span class="div-notice-type">['+data.公告类型+']</span>'+'<img src="../../../image/index/attachment.png" style="width:21px;height:21px;margin-right: 5px;">'+title;
	}
	//今天创建公告, 显示new图片
	if(today == createDate) {
		templet += '<img class="img-new" src="../../../image/index/new.png" style="margin-left: 12px; height: 31px;">';
	}
	if(listPrivilege) {
		for(var i=0; i<listPrivilege.length; i++) {
			listPrivilege[i].alias == "编辑" ? templet += '<div id="'+ data.GID+'" class="div-notice-edit"><span class="glyphicon glyphicon-edit" style="display: none;"></span></div>' : false;
			listPrivilege[i].alias == "删除" ? templet += '<div id="'+ data.GID+'" class="div-notice-remove" ><span class="glyphicon glyphicon-trash" style="display: none;"></span></div>' : false;
		}
	}
	templet += '</div>';
	return templet;
}

function timeTemplet(data) {
	return new Date(data.创建时间).format("yyyy-MM-dd hh:mm");
}

/**
 * 查看公告详情
 * @param data
 * @returns
 */
function openDetail(data) {
	var url=CONF_FRONT_SERVERURL+"view/index/homeContent/notice-window.jsp?gid="+data.GID;
	 var index=parent.layer.open({	
		  type: 2,
		  title: '公告详情信息',
		  shadeClose: true,
		  shade: 0.3,
		  area: ['650px', '600px'],
		  content:url,
		   yes:function(index,layero){},
		   end:function(index,layero){
		   }
		});	
}

// 控制是否显示删除和编辑按钮
function isShowDelAndEdit(param){
	for(var nt in newNewsType){
		if($(param)[0].innerText.indexOf(newNewsType[nt].name) != -1){
			$(param).mouseover(function(){
				$(param).find(".glyphicon").css("display", "block");
				$(param).find(".glyphicon").css("padding-top","7px");
			});
			$(param).mouseout(function(){
				$(param).find(".glyphicon").css("display", "none");
			});
		}
	}
}

//用于查找权限并返回权限值
function getPrivalige(parent, children){
	var userInfo=$.cookie('cookieuser');
	userInfo=JSON.parse(userInfo);
	var userid=userInfo.user.id;
	var userdetail=getUserInfoByUserid(userid);
	var role=userdetail.roles;
	var roleIds="";
	for(var i=0;i<role.length;i++){
		roleIds+=role[i].id+",";
	}
	//加入前端缓存机制 杨亦乐 20180408
	var cacheListPrivilege = null;
	if(window.parent.globalLocalCache){
		var obj = {roleid:roleIds,parent:parent};
		if(children){
			obj = {roleid:roleIds,parent:parent,children:children};
		}
		cacheListPrivilege = window.parent.globalLocalCache.GetCacheResult(
							CONF_BACK_SERVERURL +"/mvc/privilege/user/load/getChildrenPrivilegeByRoleidAndParent.do",
							obj,"");
	}
	return cacheListPrivilege;
}