/*文章预览*/ var articleId = GetQueryString("articleId"); var userid = $.cookie("userid"); var zjreturnId; var wzreturnId; var experarray = []; var createTime,orderKey; $(function() { loginStatus();//判断个人是否登录 articleshow(); relevantExperts(); relevantResources(); //判断是否登录转态 if(userid && userid != "null" && userid != null){ $(".ifLoginOn").removeClass("displayNone"); }else{ $(".ifLoginUn").removeClass("displayNone"); } //初始化文章内容 function articleshow(){ $.ajax({ "url" : "/ajax/article/query", "type" : "GET" , "dataType" : "json", "data" :{"articleId":articleId}, "success" : function(data) { if (data.success){ $("#articleTitle").text(data.data.articleTitle); $("#pageViews").text("阅读量 "+data.data.pageViews); $("#publishTime").text(commenTime(data.data.publishTime)); $("#articleContent").html(data.data.articleContent); $("#articleImg").attr("style", "background-image: url(/data/article/" + data.data.articleImg + ");"); $("#tagList").text(industryShow(data.data.subject)); if (userid && userid != "null" && userid != null) { isAgree(data.data.articleAgree)//文章点赞 }else{ $(".thumbBtn").html("赞 "+data.data.articleAgree+""); } ifCollection(articleId,2);//文章收藏 if(data.data.articleType==1){ $("#expert").removeClass("displayNone"); relevantarticalList(data.data.professorId,1); expert(data.data.professorId); } if(data.data.articleType==2){ $("#enterprise").removeClass("displayNone"); relevantarticalList(data.data.orgId,2); cmpFun(data.data.orgId); } var weibotitle = data.data.articleTitle; var weibourl =window.location.href; var weibopic ="http://"+window.location.host+"/data/article/" + data.data.articleImg; $("#weibo").attr("href","http://service.weibo.com/share/share.php?appkey=3677230589&title="+weibotitle+"&url="+weibourl+"&pic="+weibopic+"&ralateUid=6242830109&searchPic=false&style=simple"); } }, "error":function(){ $.MsgBox.Alert('提示','链接服务器超时') } }); } //专家信息 function expert(professorId){ $.ajax({ "url" : "/ajax/professor/baseInfo/"+professorId, "type" : "GET" , "dataType" : "json", "success" : function(data) { if (data.success && data.data){ if(data.data.hasHeadImage==1) { $("#Zimg,.userimg").attr("style", "background-image: url(/images/head/" + data.data.id + "_l.jpg);"); } if(data.data.title==""){ var title = data.data.office; }else{ var title = data.data.title; } $("#Zname,.username").text(data.data.name); $("#Zname").attr("dataid",data.data.id); $(".hrefgo,.useurl").attr("href", "information-brow.html?professorId="+data.data.id); $("#Ztitle").text(title); $("#ZorgName").text(data.data.orgName); var userType = autho(data.data.authType, data.data.orgAuth, data.data.authStatus); $("#ZauthFlag,.labels").attr("title", userType.title); $("#ZauthFlag,.labels").addClass(userType.sty); if(data.data.id!=userid){ $(".goSpan").removeClass("displayNone"); ifCollection(data.data.id,1)//判断是否关注专家 } } }, "error":function(){ $.MsgBox.Alert('提示','链接服务器超时') } }); } /*企业用户信息*/ function cmpFun(orgId) { $.ajax({ "url": "/ajax/org/" + orgId, "type": "get", "dataType" : "json", "success": function(data) { if(data.success && data.data) { $(".userimg").removeClass("useHead"); $("#Qname,.username").text(data.data.name); $(".qiyego,.useurl").attr("href", "companybrowinfor.html?orgId="+data.data.id); if(data.data.hasOrgLogo) { $("#Qimg,.userimg").attr("style", "background-image: url(/images/org/" + data.data.id + ".jpg);"); } if(data.data.authStatus==3){ $("#QauthFlag,.labels").addClass("authicon-com-ok").attr("title", "认证企业");; } $("#Qindustry").text(QindustryShow(data.data.industry)); if(data.data.orgType==2){ $("#QorgType").text("上市企业"); }else if(data.data.orgType==3){ $("#QorgType").text("国有企业"); }else if(data.data.orgType==4){ $("#QorgType").text("合资企业"); }else if(data.data.orgType==5){ $("#QorgType").text("私人企业"); }else if(data.data.orgType==6){ $("#QorgType").text("外资企业"); }else if(data.data.orgType==7){ $("#QorgType").text("初创企业"); }else{ $("#QorgType").text(""); } } }, "error": function() { $.MsgBox.Alert('提示', '链接服务器超时') } }); } //相关专家 function relevantExperts(){ $.ajax({ "url": "/ajax/article/ralatePro", "type": "get", "dataType" : "json", "data" :{"articleId":articleId}, "success": function(data) { if(data.success && data.data) { for(var i = 0; i < data.data.length; i++) { var professorId = data.data[i].professorId; relevantExpertsList(professorId) } } }, "error": function() { $.MsgBox.Alert('提示', '链接服务器超时') } }); } //相关专家信息 function relevantExpertsList(professorId){ $.ajax({ "url" : "/ajax/professor/info/"+professorId, "type" : "GET" , "dataType" : "json", "success" : function(data) { if (data.success && data.data){ var itemlist = ''; $("#trelevantExperts").html(""); var itemlist = '
  • '; itemlist += '
    '; itemlist += '
    '; itemlist += '

    '; itemlist += '

    '; itemlist += '

    '; itemlist += '
  • '; $itemlist = $(itemlist); $("#relevantExperts").append($itemlist); var title = data.data.title || ""; var office = data.data.office || ""; if(title != "") { title = title + " , "; } $itemlist.find("#userName").text(data.data.name); $itemlist.find("#usertitle").text(title + office); $itemlist.find(".urlgo").attr("href", "information-brow.html?professorId="+data.data.id); /*获取研究方向信息*/ var researchAreas = data.data.researchAreas; if(researchAreas != ""){ var rlist = '研究方向:'; }else{ var rlist = ''; } for(var n = 0; n < researchAreas.length; n++) { //console.log(researchAreas[n].caption); rlist += researchAreas[n].caption if(n < researchAreas.length - 1) { rlist += ";" } } $itemlist.find("#researchAreas").text(rlist); if(data.data.hasHeadImage == 1) { $itemlist.find("#userimg").attr("style", "background-image: url(/images/head/" + data.data.id + "_l.jpg);"); } var userType = autho(data.data.authType, data.data.orgAuth, data.data.authStatus); $itemlist.find(".authiconNew").attr("title", userType.title); $itemlist.find(".authiconNew").addClass(userType.sty); } }, "error":function(){ $.MsgBox.Alert('提示','链接服务器超时') } }); } //相关资源 function relevantResources(){ $.ajax({ "url": "/ajax/article/ralateRes", "type": "get", "dataType" : "json", "data" :{"articleId":articleId}, "success": function(data) { if(data.success && data.data) { for(var i = 0; i < data.data.length; i++) { var resourceId = data.data[i].resourceId; relevantResourcesList(resourceId) } } }, "error": function() { $.MsgBox.Alert('提示', '链接服务器超时') } }); } //相关资源信息 function relevantResourcesList(resourceId){ $.ajax({ "url" : "/ajax/resource/resourceInfo", "type" : "GET" , "dataType" : "json", "data" :{"resourceId":resourceId}, "success" : function(data) { console.log(data); if (data.success && data.data){ var itemlist = '
  • '; itemlist += '
    '; itemlist += '
    '; itemlist += '

    '; itemlist += '

    '; itemlist += '

    '; itemlist += '
  • '; $itemlist = $(itemlist); $("#resources").append($itemlist); var datalist = data.data; $itemlist.find("#resourceName").text(datalist.resourceName); $itemlist.find("#name").text("用途:"+datalist.supportedServices); $itemlist.find(".uname").text(datalist.editProfessor.name); $itemlist.find(".urlgo").attr("href", "resourceShow.html?resourceId="+datalist.resourceId); var userType = autho(datalist.editProfessor.authType, datalist.editProfessor.orgAuth, datalist.editProfessor.authStatus); $itemlist.find(".authiconNew").attr("title", userType.title); $itemlist.find(".authiconNew").addClass(userType.sty); if(datalist.images.length > 0) { $itemlist.find("#userimg").attr("style", "background-image: url(/data/resource/" + datalist.images[0].imageSrc + ");"); } } }, "error":function(){ $.MsgBox.Alert('提示','链接服务器超时') } }); } function keysli() { $("#tagList li").each(function(i) { var liid = $(this).text(); experarray.push(liid); }); return $.unique(experarray); } //相关文章信息 function relevantarticalList(id,num){ keysli(); if(num==1){ var data = {"keys":experarray,"professorId":id,"articleId":articleId,"rows":10} } if(num==2){ var data = {"keys":experarray,"orgId":id,"articleId":articleId,"rows":10} } $.ajax({ "url" : "/ajax/article/ralateArticles", "type" : "GET" , "dataType" : "json", "data" :data, //"async":false, "traditional": true, //传数组必须加这个 "success" : function(data) { console.log(data); if (data.success && data.data){ var itemlist = ''; $("#abutartical").html(""); for(var i = 0; i < data.data.length; i++) { var itemlist = '
  • '; itemlist += '
    '; itemlist += '
    '; itemlist += '

    '; itemlist += '

    '; itemlist += '
  • '; $itemlist = $(itemlist); $("#abutartical").append($itemlist); var datalist = data.data[i]; $itemlist.find("#resourceName").text(datalist.articleTitle); $itemlist.find(".urlgo").attr("href", "articalShow.html?articleId="+datalist.articleId); if(datalist.articleImg!=undefined){ $itemlist.find("#userimg").attr("style", "background-image: url(/data/article/" + datalist.articleImg + ");"); } if(datalist.articleType==1){ $.ajax({ "url" : "/ajax/professor/baseInfo/"+datalist.professorId, "type" : "GET" , "dataType" : "json", "async":false, "success" : function($data) { if ($data.success && $data.data){ $itemlist.find(".username2").text($data.data.name); var userType = autho($data.data.authType, $data.data.orgAuth, $data.data.authStatus); $itemlist.find("#relatedLabels").attr("title", userType.title); $itemlist.find("#relatedLabels").addClass(userType.sty); } }, "error":function(){ $.MsgBox.Alert('提示','链接服务器超时') } }); } if(datalist.articleType==2){ $.ajax({ "url" : "/ajax/org/"+datalist.orgId, "type" : "GET" , "dataType" : "json", "async":false, "success" : function($data) { console.log($data) if ($data.success && $data.data){ $itemlist.find(".username2").text($data.data.name); if($data.data.authStatus==3){ $itemlist.find("#relatedLabels").addClass("authicon-com-ok").attr("title", "认证企业"); } } }, "error":function(){ $.MsgBox.Alert('提示','链接服务器超时') } }); } } } }, "error":function(){ $.MsgBox.Alert('提示','链接服务器超时') } }); } /*时间转换*/ function Time(dealtime) { var s = dealtime; var m = s.substr(4, 2); var d = s.substr(6, 2); var h = s.substr(8, 2); var minute = s.substr(10, 2); var formatTime = m.replace(/\b(0+)/gi, "") + "月" + d + "日 " + h + ":" + minute; return formatTime; } //拆解关键字 function industryShow(data){ 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++) { $("#tagList").append('
  • '+ subs[i] +'

  • '); }; } } } //拆解企业应用行业 function QindustryShow(data){ if(data != undefined && data.length != 0 ){ var subs = new Array(); subs = data.replace(',',' | '); if(subs.length>0){ for (var i = 0; i < subs.length; i++) { $("#Qindustry").append(subs[i]); }; } } } }); //文章点击点赞 $('.thumbBlock').on("click",".thunbgo",function(){ if (userid && userid != "null" && userid != null) { addAgree(); }else{ $.MsgBox.Alert('提示',"请先登录再进行关注"); $("#mb_btn_ok").val("去登录"); var aele = document.createElement('a'); $("#mb_btnbox").append(aele); $("#mb_btnbox a").css({ 'display': "block", 'width': '100%', 'height': '40px', 'position': 'absolute', 'bottom': '-6px', 'left': '0' }); aele.setAttribute('href', '../login.html'); } }) /*判断文章是否被赞*/ function isAgree(articleAgree) { var data = {"operateId": userid,"articleId": articleId} $.ajax({ url:"/ajax/article/isAgree", data:data, dataType: 'json', //数据格式类型 type: 'get', //http请求类型 timeout: 10000, async: false, success: function(data) { if(data.success){ if(data.data!= null){ $(".thumbBtn").html("已赞 "+articleAgree+""); $(".thumbBtn").addClass("thumbedBtn"); }else{ $(".thumbBtn").html("赞 "+articleAgree+""); $(".thumbBtn").addClass("thunbgo"); } } }, error: function() { $.MsgBox.Alert('提示',"服务器链接超时"); } }); } /*点赞*/ function addAgree() { var data = {"operateId": userid,"articleId": articleId} $.ajax({ url:"/ajax/article/agree", data:data, dataType: 'json', //数据格式类型 type: 'POST', //http请求类型 timeout: 10000, async: false, success: function(data) { if(data.success){ var articleAgreeval = $(".thumbBtn span").text(); $(".thumbBtn").html("已赞 "+parseInt(articleAgreeval+1)+""); $(".thumbBtn").addClass("thumbedBtn"); $(".thumbBtn").removeClass("thunbgo"); } }, error: function() { $.MsgBox.Alert('提示',"服务器链接超时"); } }); } //点击专家关注 $('.attenSpan').click(function(){ if (userid && userid != "null" && userid != null) { if($(this).is('.attenSpanyes')){ cancelCollectionExpert($("#Zname").attr("dataid"),1) }else{ collectionExpert($("#Zname").attr("dataid"),1); } }else{ $.MsgBox.Alert('提示',"请先登录再进行关注"); $("#mb_btn_ok").val("去登录"); var aele = document.createElement('a'); $("#mb_btnbox").append(aele); $("#mb_btnbox a").css({ 'display': "block", 'width': '100%', 'height': '40px', 'position': 'absolute', 'bottom': '-6px', 'left': '0' }); aele.setAttribute('href', '../login.html'); } }) //点击文章收藏 $('#attention em').click(function(){ if (userid && userid != "null" && userid != null) { if($(this).is('.icon-collected')){ cancelCollectionExpert(articleId,2) }else{ collectionExpert(articleId,2); } }else{ $.MsgBox.Alert('提示',"请先登录再进行收藏"); $("#mb_btn_ok").val("去登录"); var aele = document.createElement('a'); $("#mb_btnbox").append(aele); $("#mb_btnbox a").css({ 'display': "block", 'width': '100%', 'height': '40px', 'position': 'absolute', 'bottom': '-6px', 'left': '0' }); aele.setAttribute('href', '../login.html'); } }) /*判断是非关注专家*/ function ifCollection(getid,num) { var data = {"professorId": userid,"watchObject": getid} //alert(JSON.stringify(data)) $.ajax({ url:"/ajax/watch/hasWatch", data:data, dataType: 'json', //数据格式类型 type: 'get', //http请求类型 timeout: 10000, async: false, success: function(data) { if(num==1){ if(data.success && data.data != null) { $('.attenSpan').addClass("attenSpanyes"); $('.attenSpan').text('已关注'); zjreturnId = data.data.watchObject; } else { $('.attenSpan').removeClass("attenSpanyes"); $('.attenSpan').text('关注'); } } if(num==2){ if(data.success && data.data != null) { $('#attention em').addClass("icon-collected"); wzreturnId = data.data.watchObject; } else { $('#attention em').removeClass("icon-collected"); } } }, error: function() { $.MsgBox.Alert('提示',"服务器链接超时"); } }); } /*关注专家*/ function collectionExpert(watchObject,num) { if(num==1){ var data = {"professorId": userid,"watchObject": watchObject,"watchType": 1} }else{ var data = {"professorId": userid,"watchObject": watchObject,"watchType": 3} } $.ajax({ url:"/ajax/watch", data:data, dataType: 'json', //数据格式类型 type: 'POST', //http请求类型 timeout: 10000, async: false, success: function(data) { console.log(data.success) if(num==1){ if(data.success) { $('.attenSpan').addClass("attenSpanyes"); $('.attenSpan').text('已关注'); zjreturnId = data.data.watchObject; } } if(num==2){ if(data.success) { $('#attention em').addClass("icon-collected"); wzreturnId = data.data.watchObject; } } }, error: function() { $.MsgBox.Alert('提示',"服务器链接超时"); } }); } /*取消收藏专家*/ function cancelCollectionExpert(watchObject,num) { $.ajax({ url:"/ajax/watch/delete", data: { professorId: userid, watchObject: watchObject }, dataType: 'json', //数据格式类型 type: 'post', //http请求类型 timeout: 10000, async: true, success: function(data) { console.log(data.success) if(num==1){ if(data.success) { $('.attenSpan').removeClass("attenSpanyes"); $('.attenSpan').text('关注'); } } if(num==2){ if(data.success) { $('#attention em').removeClass("icon-collected"); } } }, error: function(data) { $.MsgBox.Alert('提示',"服务器链接超时"); } }); } //文章浏览量 function pageViewsVal(){ $.ajax({ "url" : "/ajax/article/pageViews", "type" : "POST" , "dataType" : "json", "data" :{"articleId":articleId}, "success" : function(data) { console.log(data); if (data.success){ } }, "error":function(){ $.MsgBox.Alert('提示','链接服务器超时') } }); } ArticleMessagesNumbe(); //文章留言条数 function ArticleMessagesNumbe(){ $.ajax({ "url" : "/ajax/leaveWord/lwCount", "type" : "GET" , "dataType" : "json", "data" :{"articleId":articleId}, "success" : function(data) { console.log(data); if (data.success){ $(".message").text(data.data); } }, "error":function(){ $.MsgBox.Alert('提示','链接服务器超时') } }); } /*留言模块*/ $(".msgCont").on("keyup", function() { $(".msgconNum span").text($(this).val().length); if($(this).val().length > 200) { $(this).val($(this).val().substr(0, 200)); } if($(this).val().length <= 0){ $("#meSendtt").css("background", "#ccc"); }else{ $("#meSendtt").css("background", "#ff9900"); } }) $("#meSendtt").on("click", function() { article(); }) //查看更多留言 $("#moreArtical").on("click",function(){ vcreateTime = $(".commentList li").last().attr("data-time"); orderKey = $(".commentList li").last().attr("data-key"); message(5,1); }) //删除留言 $(".commentList").on("click",".messageDel",function(){ var commenid = $(this).attr("data-id"); articledel(commenid) }) //发布留言 function article() { $.ajax({ url:"/ajax/leaveWord", dataType: 'json', //数据格式类型 type: 'POST', //http请求类型 data: { "articleId": articleId, "sender": userid, "content": $(".msgCont").val(), }, timeout: 10000, //超时设置 success: function(data) { var $info = data.data || {}; if(data.success && data.data) { message(5,2); } }, error: function() { $.MsgBox.Alert('提示', '服务器请求失败') } }); } message(5,2); function message(rows,num) { if(num==1){ var data = {"articleId": articleId,"createTime": vcreateTime,"orderKey": orderKey,"rows": rows} }else{ var data = {"articleId": articleId,"rows": rows} } $.ajax({ url: "/ajax/leaveWord/ql", dataType: 'json', //数据格式类型 type: 'GET', //http请求类型 data: data, timeout: 10000, //超时设置 success: function(data) { if(data.success) { if(data.data != ""){ if(num==2){ $(".commentList").html(""); } if(data.data.length > 4){ $("#moreArtical").removeClass("displayNone"); }else{ $("#moreArtical").addClass("displayNone"); } for(var i = 0; i < data.data.length; i++) { var itemlist = '
  • '; itemlist += '
    '; itemlist += '
    '; itemlist += '

    张某某9月30号 12:00

    '; itemlist += '

    sdfsdfs

    '; itemlist += '
    回复删除
    '; itemlist += '
  • '; $itemlist = $(itemlist); $(".commentList").append($itemlist); var datalist = data.data[i]; $itemlist.find(".messageName").text(datalist.professor.name); $itemlist.find(".messageContent").text(datalist.content); var userType = autho(datalist.professor.authType, datalist.professor.orgAuth, datalist.professor.authStatus); $itemlist.find(".authiconNew").attr("title", userType.title); $itemlist.find(".authiconNew").addClass(userType.sty); if(datalist.professor.hasHeadImage==1) { $(".useHead").attr("style", "background-image: url(/images/head/" + datalist.professor.id + "_l.jpg);"); } if(datalist.professor.id!=userid){ $(".messageDel").hide(); } $itemlist.attr("data-time", datalist.createTime); $itemlist.attr("data-key", datalist.orderKey); $itemlist.find(".messageDel").attr("data-id", datalist.id); $itemlist.find(".userhref").attr("href", "information-brow.html?professorId="+datalist.professor.id); var createtime = datalist.createTime; $itemlist.find(".commenttime").text(commenTime(createtime)); } }else{ if(num==2){ $(".commentList").html(""); }else{ $("#moreArtical").addClass("displayNone"); } } } }, error: function() { $.MsgBox.Alert('提示', '服务器请求失败') } }); } //删除自己的留言 function articledel(commenid) { $.ajax({ url:"/ajax/leaveWord/delete", dataType: 'json', //数据格式类型 type: 'POST', //http请求类型 data: { "id": commenid, }, timeout: 10000, //超时设置 success: function(data) { if(data.success) { message(5,2); } }, error: function() { $.MsgBox.Alert('提示', '服务器请求失败') } }); } function commenTime(startTime){ var nowTimg = new Date(); var startdate = new Date(); startdate.setFullYear(parseInt(startTime.substring(0,4))); startdate.setMonth(parseInt(startTime.substring(4,6))-1); startdate.setDate(parseInt(startTime.substring(6,8))); startdate.setHours(parseInt(startTime.substring(8,10))); startdate.setMinutes(parseInt(startTime.substring(10,12))); startdate.setSeconds(parseInt(startTime.substring(12,14))); var date3=nowTimg.getTime()-startdate.getTime(); //时间差的毫秒数 var hours = parseInt((date3 % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)); var minutes = parseInt((date3 % (1000 * 60 * 60)) / (1000 * 60)); if(date3 < 60000){ return "刚刚"; }else if(date3 > 60000 && date3 < 3600000){ return minutes + "分钟前"; }else if(date3 > 3600000 && date3 < 86400000){ return hours + "小钟前"; }else if(date3 > 86400000 && date3 < 172800000){ return "昨天 " + startTime.substring(10,12) + ":" +startTime.substring(12,14); }else{ return startTime.substring(4,6) + "月" + startTime.substring(6,8) + "日 " + startTime.substring(8,10) + ":" + startTime.substring(10,12); } } window.onload=function(){ pageViewsVal();//文章浏览量 }