$(function() { $(".onlogin .headnavbtn li").eq(0).addClass("navcurrent"); loginStatus();//判断个人是否登录 var userid = $.cookie("userid"); var articleId; newslist();//科研新闻列表 $("#workmysrc").on("click", ".newsadd", function() { newsBombBox();//插入弹框 addDele();//编辑学术领域和应用行业 $("#inputb").on("click", function() { if($("#newsName").val()!=""){ newsAdd(); }else{ $(".workmsg1").text("发布文章名称不能为空"); } }); }); $("#workmysrc").on("click", ".resoumag", function() { articleId = $(this).attr("data-title"); newsBombBox();//插入弹框 addDele();//编辑学术领域和应用行业 modifyDisplay(); $("#inputb").on("click", function() { if($("#newsName").val()!=""){ $.MsgBox.Confirm("消息", "确定修改文章信息吗?", newsModify) }else{ $(".workmsg1").text("发布文章名称不能为空"); } }); }); /*科研新闻列表*/ function newslist() { $.ajax({ "url": "/ajax/article/qaPro", "type": "get", "async": true, "data": { "professorId": userid }, "beforeSend": function() { $("#newsbox").append(''); }, "success": function(data) { //console.log(data); if(data.success) { var add = ''; $("#newsbox").html(""); var addbut = '
'; $("#newsbox").append(addbut); for(var i = 0; i < data.data.length; i++) { var add = '
' add += '
' add += '
'+ data.data[i].articleTitle + '
' add += '
' add += '
'; $add = $(add); $("#newsbox").append($add); $add.find('.resoumag').attr("data-title", data.data[i].articleId); $add.find('.tagsBox span').text(data.data[i].industry); if(data.data[i].articleImg) { $add.find(".art_img").attr("style", "background: url(/data/article/"+data.data[i].articleImg+") center center no-repeat;background-size:cover;"); } $(".loading").remove(); } } else { $.MsgBox.Alert('message', "系统异常!"); } }, "error": function() { $.MsgBox.Alert('message', 'failed') } }); } /*科研新闻添加*/ function newsAdd(){ var $data = {}; $data.professorId = userid; $data.articleTitle = $("#newsName").val(); $data.subject = captiureSubInd("SubjectList .deleteSubject"); $data.industry = captiureSubInd("industryList .deleteIndustry"); $data.articleContent = ue.getContent(); if(cacheImageKey) { $data.articleImg = cacheImageKey; } $.ajax({ "url" : "/ajax/article", "type" : "post" , "dataType" : "json", "data" :$data, "success" : function(data) { //console.log(data); if (data.success){ newsname = data.data; //console.log(newsname); $.MsgBox.Alert("消息","文章发表成功!"); $("#mb_msgicon").css("background", 'url("images/sign_icon_chenggong_nor.png") 0% 0% / contain'); newslist(); $(".blackcover").remove(); UE.delEditor('editor'); } else { $.MsgBox.Alert("消息","文章发表失败!"); } }, "error":function(){ $.MsgBox.Alert('消息','链接服务器超时') } }); } /*科研新闻修改回显内容*/ function modifyDisplay(){ $.ajax({ "url" : "/ajax/article/query", "type" : "GET", "dataType" : "json", "data": { "articleId": articleId }, "success" : function($data) { //console.log($data); if ($data.success) { $("#newsName").val($data.data.articleTitle); industryShow($data.data.subject,"SubjectList","deleteSubject"); industryShow($data.data.industry,"industryList","deleteIndustry"); ue.ready(function() { if($data.data.articleContent==undefined){ var datadescp =""; }else{ var datadescp = $data.data.articleContent; } ue.setContent(datadescp); }); if($data.data.articleImg) { var $liMages = $( '
'+ ''+ '
' ) }else{ var $liMages = $( '
'+ ''+ '
' ) } $("#fileList").append($liMages); } }, "error":function(){ $.MsgBox.Alert('消息','链接服务器超时') } }) $("#deletedResource").show(); //$.MsgBox.Confirm("消息", "确定修改文章信息吗?", newsAdd()) $("#deletedResource").on("click", function() { $.MsgBox.Confirm("消息", "执行删除后文章信息将无法恢复,确定继续吗?",newsDelet) }); } /*科研新闻修改*/ function newsModify() { var $data = {}; $data.articleId = articleId; $data.articleTitle = $("#newsName").val(); $data.subject = captiureSubInd("SubjectList .deleteSubject"); $data.industry = captiureSubInd("industryList .deleteIndustry"); $data.articleContent = ue.getContent(); if(cacheImageKey) { $data.articleImg = cacheImageKey; } //console.log($data); $.ajax({ "url" : "/ajax/article/updateArt", "type" : "POST", "dataType" : "json", "data" :$data, "success" : function($data) { //console.log($data); if ($data.success) { newslist(); $(".blackcover").remove(); UE.delEditor('editor'); } }, "error":function(){ $.MsgBox.Alert('消息','链接服务器超时') } }) $("#deletedResource").show(); //$.MsgBox.Confirm("消息", "确定修改文章信息吗?", newsAdd()) $("#deletedResource").on("click", function() { $.MsgBox.Confirm("消息", "执行删除后文章信息将无法恢复,确定继续吗?",newsDelet) }); } /*科研新闻删除*/ function newsDelet() { $.ajax({ "url" : "/ajax/article/delete", "type" : "POST", "dataType" : "json", "data": { "articleId": articleId }, "success" : function($data) { if ($data.success) { $(".blackcover").remove(); UE.delEditor('editor'); newslist(); } }, "error":function(){ $.MsgBox.Alert('消息','链接服务器超时') } }) } //组合应用行业及学术领域 function captiureSubInd(subIndu) { var industrys = $("#" + subIndu + ""); var industryAll = ""; if(industrys.size() > 0) { for(var i = 0; i < industrys.size(); i++) { industryAll += industrys[i].innerText; industryAll += ','; }; industryAll = industryAll.substring(0, industryAll.length - 1); } return industryAll; } //拆解应用行业及学术领域 function industryShow(data,industryList,deleteIndustry){ if(data != undefined && data.length != 0 ){ var subs = new Array(); if(data.indexOf(',')){ subs = data.split(','); }else{ subs[0] = data; } if(subs.length>0){ for (var i = 0; i < subs.length; i++) { $("#"+industryList+"").append("
"+ subs[i] +"
"); }; } } } //添加或者删除应用行业及学术领域 function addDele() { $("#industryList").on("click", ".removeNu", function() { $(this).parent().remove(); }); $("#industryAdd").click(function() { var val = $("#industry").val(); if(val==""){ $(".workmsg4").text("请填写应用行业"); return; } var vallist = $("#industryList .deleteIndustry em"); for(var i=0;i" + val + "") $("#industry").val(""); $(".workmsg4").text(""); }); $("#SubjectList").on("click", ".removeNu", function() { $(this).parent().remove(); }); $("#subjectAdd").click(function() { var val = $("#subject").val(); if(val==""){ $(".workmsg3").text("请填写学术领域"); return; } var vallist = $("#SubjectList .deleteSubject em"); for(var i=0;i" + val + "") $("#subject").val(""); $(".workmsg3").text(""); }); } });