notice-add.js 7.97 KB
var selectedbg = "rgb(238, 249 ,249)";
var contentpath ;
var  gid="";
var status="";
var action =null;
var noticetype=null;
var attachpath=null;
var newNewsType = null;
$(document).ready(function () {	
	// 获取权限
	newNewsType = getPrivalige("新闻公告");
	init();
	loadSeleted(noticetype);
//	addEvent();
});

function init(){
	$.cookie("uuid", uuid());
	action = $("#action").val();//获取url中的action参数	
	contentpath = $("#contentpath").val();
	gid=$("#gid").val();
	if(action=="edit"){
		
		$.ajax({
	        type: 'POST',
	        dataType: 'json',
	        url: CONF_BACK_SERVERURL + global.modelctls.homepage.homePageDetail,
	        headers:{
	    		"token":$.cookie('ftoken')
		    },
	        data: {gid : gid},
	        success: function (result) {
	        	var data=result.Data;			
				var str = JSON.stringify(data);
				for(var i=0;i<data.length;i++){
					var map_result = data[i];
					var title=map_result["公告标题"];
					var content=map_result["公告内容"];
					noticetype=map_result["公告类型"];
					var createtime= new Date(map_result["创建时间"]);
					var unit=map_result["创建单位"];
					if(unit==null){unit="暂无单位";}
					var docattachmentpath = map_result["附件路径"]==null?"":map_result["附件路径"];							
					loadSeleted(noticetype)
					$("#title").val(title);
					$("#content").val(content);
					if(docattachmentpath==""||docattachmentpath==null){continue;}
					attachpath=docattachmentpath;
					var docpaths = docattachmentpath.split("/");
					$.cookie("uuid",docpaths[docpaths.length-1]);
					//listFiles(docattachmentpath,"列表编辑");
					loadAttachment2(docattachmentpath,null,"edit");
	        }
	     }
	  });
		
	}
}

/**
 * 生成UUID
 * 
 * @returns uuid
 */
function uuid(){
	var s = [];
	var hexDigits = "0123456789abcdef";
	for (var i = 0; i < 36; i++) {
	s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
	}
	s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010
	s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the
														// clock_seq_hi_and_reserved
														// to 01
	s[8] = s[13] = s[18] = s[23] = "-";

	var uuid = s.join("");
	return uuid;
}
function setSelect(noticetype){
	if(noticetype=="其他"){
		$("#Select1 #other").attr("selected",true);
	}else if(noticetype=="路网更新"){
		$("#Select1 #update").attr("selected",true);
	}else if(noticetype=="通知"){
		$("#Select1 #notice	").attr("selected",true);
	}
}

function loadSeleted(noticetype){
	$("#Select1").html("");
	$.ajaxSetup({
		async : false // 取消以下异步请求 即执行会按顺序执行,不会跳出最后再执行function(result)内的代码
	});
	$.ajax({
        type: 'POST',
        dataType: 'json',
        url: CONF_BACK_SERVERURL + global.modelctls.kvtree.all,
        headers:{
    		"token":$.cookie('ftoken')
	    },
	    data:{name :"公告类型" }, 
        success: function (result) {
        	// 从结果中去除不可新建的类型
        	result = removeCanNotEsta(result);
        	var selected="";
    		var type=null;
    		for(var i=0;i<result.length;i++){
    			type=result[i];
    			if(noticetype==type.name){
    				selected=" selected='true'";
    			}else{
    				selected="";
    			}
    			$("#Select1").append("<option "+selected+" >"+type.name+"</option>" );
    		}
    		selectChange();
        }
	
	});

}

function selectChange(){
	// 初始加载时 赋值默认值
	var selectVal = '';
	selectVal = jQuery("#Select1  option:selected").text();
	if(selectVal == "信息快报"){
		$("#title").val(new Date().format("yyyy-MM-dd")+"信息快报");
	} else {
		$("#title").val('');
	}
	// 改变时给title默认值
	$("#Select1").change(function(){
		selectVal = jQuery("#Select1  option:selected").text();
		if(selectVal == "信息快报"){
			$("#title").val(new Date().format("yyyy-MM-dd")+"信息快报");
		} else {
			$("#title").val('');
		}
	});
}
//格式化时间
Date.prototype.format = function(format) {
	var o = {
		"M+" : this.getMonth() + 1, // 月
		"d+" : this.getDate(), // 天
		"h+" : this.getHours(), // 时
		"m+" : this.getMinutes(), // 分
		"s+" : this.getSeconds(), // 秒
		"S" : this.getMilliseconds() // 毫秒
	}
	if (/(y+)/.test(format)) { // 年
		format = format.replace(RegExp.$1, (this.getFullYear() + "")
				.substr(4 - RegExp.$1.length));
	}
	for ( var k in o) {
		if (new RegExp("(" + k + ")").test(format)) {
			format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k]
					: ("00" + o[k]).substr(("" + o[k]).length));
		}
	}
	return format;
}
//function addEvent(){
//	$("#confirm").click(function () {
//		
//	      var addData=getdata();
//	      var dataString=JSON.stringify(addData);
//	      $.post(global.contextPath + global.modelctls.homepage.create,
//				     {	data:dataString					
//					  }, 
//					 function (result) {   
//						layer.msg(result,{icon: 1});
//						gid=result;
//						status="0";
//					var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
//					
//						parent.layer.close(index); //再执行关闭 
//						window.opener.location.reload();
//			       });
//	    });
//		
////	    $("#btnBrower").click(function () {
////	        $("#fileBrower").trigger("click");
////	    });
////		  
//	fujianEvent();
//	
//}
//
//function fujianEvent(){
//	//显示删除图标
//    $(".div-notice-attachment-item").mouseover(function (evt) {
//        $(evt.currentTarget).css("background-color", selectedbg);
//        $(".div-notice-add-fileremove").show("fast");
//        $(evt.currentTarget).find(".div-notice-add-fileremove span").slideDown("fast", function () {
//            if ($(this).parent().parent().css("background-color") == selectedbg) {
//                $(this).hide("fast");
//            }
//        });
//    });
//    $(".div-notice-attachment-item").mouseleave(function (evt) {
//        $(evt.currentTarget).css("background-color", "white");
//        $(evt.currentTarget).find(".glyphicon-trash").hide("fast");
//        $(evt.currentTarget).find(".glyphicon-eye-open").hide("fast");
//    });
//    //删除事件
////    $(".div-notice-add-fileremove").click(removeNotice);
//}
//获取添加的数据
function getdata(){
	var announcementtype=jQuery("#Select1  option:selected").text();
	var title =$("#title").val();
	var content=$("#content").val();
	var filepath=$("#filepath").val();
	if(filepath==""&&attachpath!=null){filepath=attachpath;}
	
	var data=null;
	if(action=="add"){
		data={
				announcementtype:announcementtype,
				title:title,
				content:content,
				filepath:filepath,
				action:action
		}
	}else{	
		gid=$("#gid").val();
		data={
				announcementtype:announcementtype,
				title:title,
				content:content,
				filepath:filepath,
				action:action,
				gid:gid
		}
		
	}
	return data;
}

//用于查找权限并返回权限值
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;
}
// 移除不可新建的类型
function removeCanNotEsta(params){
	var newData = [];
	for(var nt in newNewsType){
		for(var p in params){
			if(params[p].name == newNewsType[nt].name){
				newData.push(newNewsType[nt]);
			}
		}
	}
	return newData;
}

////删除通知公告
//function removeNotice() {
//	//alert("1");
//    //询问框
//    layer.confirm('是否删除?', {
//        btn: ['是', '否'] //按钮
//    }, function () {
//
//    }, function () {
//
//    });
//}
//function onchangeFile(){}