portal html css js resource

articalShow.js 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860
  1. /*文章预览*/
  2. var articleId = GetQueryString("articleId");
  3. var userid = $.cookie("userid");
  4. var zjreturnId;
  5. var wzreturnId;
  6. var experarray = [];
  7. var createTime,orderKey;
  8. $(function() {
  9. loginStatus();//判断个人是否登录
  10. articleshow();
  11. relevantExperts();
  12. relevantResources();
  13. //判断是否登录转态
  14. if(userid && userid != "null" && userid != null){
  15. $(".ifLoginOn").removeClass("displayNone");
  16. }else{
  17. $(".ifLoginUn").removeClass("displayNone");
  18. }
  19. //初始化文章内容
  20. function articleshow(){
  21. $.ajax({
  22. "url" : "/ajax/article/query",
  23. "type" : "GET" ,
  24. "dataType" : "json",
  25. "data" :{"articleId":articleId},
  26. "success" : function(data) {
  27. if (data.success){
  28. $("#articleTitle").text(data.data.articleTitle);
  29. $("#pageViews").text("阅读量 "+data.data.pageViews);
  30. $("#publishTime").text(commenTime(data.data.publishTime));
  31. $("#articleContent").html(data.data.articleContent);
  32. $("#articleImg").attr("style", "background-image: url(/data/article/" + data.data.articleImg + ");");
  33. $("#tagList").text(industryShow(data.data.subject));
  34. if (userid && userid != "null" && userid != null) {
  35. isAgree(data.data.articleAgree)//文章点赞
  36. }else{
  37. $(".thumbBtn").html("赞 <span>"+data.data.articleAgree+"</span>");
  38. }
  39. ifCollection(articleId,2);//文章收藏
  40. if(data.data.articleType==1){
  41. $("#expert").removeClass("displayNone");
  42. relevantarticalList(data.data.professorId,1);
  43. expert(data.data.professorId);
  44. }
  45. if(data.data.articleType==2){
  46. $("#enterprise").removeClass("displayNone");
  47. relevantarticalList(data.data.orgId,2);
  48. cmpFun(data.data.orgId);
  49. }
  50. var weibotitle = data.data.articleTitle;
  51. var weibourl =window.location.href;
  52. var weibopic ="http://"+window.location.host+"/data/article/" + data.data.articleImg;
  53. $("#weibo").attr("href","http://service.weibo.com/share/share.php?appkey=3677230589&title="+weibotitle+"&url="+weibourl+"&pic="+weibopic+"&ralateUid=6242830109&searchPic=false&style=simple");
  54. }
  55. },
  56. "error":function(){
  57. $.MsgBox.Alert('提示','链接服务器超时')
  58. }
  59. });
  60. }
  61. //专家信息
  62. function expert(professorId){
  63. $.ajax({
  64. "url" : "/ajax/professor/baseInfo/"+professorId,
  65. "type" : "GET" ,
  66. "dataType" : "json",
  67. "success" : function(data) {
  68. if (data.success && data.data){
  69. if(data.data.hasHeadImage==1) {
  70. $("#Zimg,.userimg").attr("style", "background-image: url(/images/head/" + data.data.id + "_l.jpg);");
  71. }
  72. if(data.data.title==""){
  73. var title = data.data.office;
  74. }else{
  75. var title = data.data.title;
  76. }
  77. $("#Zname,.username").text(data.data.name);
  78. $("#Zname").attr("dataid",data.data.id);
  79. $(".hrefgo,.useurl").attr("href", "information-brow.html?professorId="+data.data.id);
  80. $("#Ztitle").text(title);
  81. $("#ZorgName").text(data.data.orgName);
  82. var userType = autho(data.data.authType, data.data.orgAuth, data.data.authStatus);
  83. $("#ZauthFlag,.labels").attr("title", userType.title);
  84. $("#ZauthFlag,.labels").addClass(userType.sty);
  85. if(data.data.id!=userid){
  86. $(".goSpan").removeClass("displayNone");
  87. ifCollection(data.data.id,1)//判断是否关注专家
  88. }
  89. }
  90. },
  91. "error":function(){
  92. $.MsgBox.Alert('提示','链接服务器超时')
  93. }
  94. });
  95. }
  96. /*企业用户信息*/
  97. function cmpFun(orgId) {
  98. $.ajax({
  99. "url": "/ajax/org/" + orgId,
  100. "type": "get",
  101. "dataType" : "json",
  102. "success": function(data) {
  103. if(data.success && data.data) {
  104. $(".userimg").removeClass("useHead");
  105. $("#Qname,.username").text(data.data.name);
  106. $(".qiyego,.useurl").attr("href", "companybrowinfor.html?orgId="+data.data.id);
  107. if(data.data.hasOrgLogo) {
  108. $("#Qimg,.userimg").attr("style", "background-image: url(/images/org/" + data.data.id + ".jpg);");
  109. }
  110. if(data.data.authStatus==3){
  111. $("#QauthFlag,.labels").addClass("authicon-com-ok").attr("title", "认证企业");;
  112. }
  113. $("#Qindustry").text(QindustryShow(data.data.industry));
  114. if(data.data.orgType==2){
  115. $("#QorgType").text("上市企业");
  116. }else if(data.data.orgType==3){
  117. $("#QorgType").text("国有企业");
  118. }else if(data.data.orgType==4){
  119. $("#QorgType").text("合资企业");
  120. }else if(data.data.orgType==5){
  121. $("#QorgType").text("私人企业");
  122. }else if(data.data.orgType==6){
  123. $("#QorgType").text("外资企业");
  124. }else if(data.data.orgType==7){
  125. $("#QorgType").text("初创企业");
  126. }else{
  127. $("#QorgType").text("");
  128. }
  129. }
  130. },
  131. "error": function() {
  132. $.MsgBox.Alert('提示', '链接服务器超时')
  133. }
  134. });
  135. }
  136. //相关专家
  137. function relevantExperts(){
  138. $.ajax({
  139. "url": "/ajax/article/ralatePro",
  140. "type": "get",
  141. "dataType" : "json",
  142. "data" :{"articleId":articleId},
  143. "success": function(data) {
  144. if(data.success && data.data) {
  145. for(var i = 0; i < data.data.length; i++) {
  146. var professorId = data.data[i].professorId;
  147. relevantExpertsList(professorId)
  148. }
  149. }
  150. },
  151. "error": function() {
  152. $.MsgBox.Alert('提示', '链接服务器超时')
  153. }
  154. });
  155. }
  156. //相关专家信息
  157. function relevantExpertsList(professorId){
  158. $.ajax({
  159. "url" : "/ajax/professor/info/"+professorId,
  160. "type" : "GET" ,
  161. "dataType" : "json",
  162. "success" : function(data) {
  163. if (data.success && data.data){
  164. var itemlist = '';
  165. $("#trelevantExperts").html("");
  166. var itemlist = '<li><a href="" class="flexCenter urlgo" style="min-height:80px;">';
  167. itemlist += '<div class="madiaHead useHead" id="userimg"></div>';
  168. itemlist += '<div class="madiaInfo">';
  169. itemlist += '<p><span class="h1Font" id="userName"></span><em class="authiconNew" title=""></em></p>';
  170. itemlist += '<p class="ellipsisSty h2Font" id="usertitle"></p>';
  171. itemlist += '<p class="h2Font ellipsisSty" id="researchAreas"></p>';
  172. itemlist += '</div></a></li>';
  173. $itemlist = $(itemlist);
  174. $("#relevantExperts").append($itemlist);
  175. var title = data.data.title || "";
  176. var office = data.data.office || "";
  177. if(title != "") {
  178. title = title + " , ";
  179. }
  180. $itemlist.find("#userName").text(data.data.name);
  181. $itemlist.find("#usertitle").text(title + office);
  182. $itemlist.find(".urlgo").attr("href", "information-brow.html?professorId="+data.data.id);
  183. /*获取研究方向信息*/
  184. var researchAreas = data.data.researchAreas;
  185. if(researchAreas != ""){
  186. var rlist = '研究方向:';
  187. }else{
  188. var rlist = '';
  189. }
  190. for(var n = 0; n < researchAreas.length; n++) {
  191. //console.log(researchAreas[n].caption);
  192. rlist += researchAreas[n].caption
  193. if(n < researchAreas.length - 1) {
  194. rlist += ";"
  195. }
  196. }
  197. $itemlist.find("#researchAreas").text(rlist);
  198. if(data.data.hasHeadImage == 1) {
  199. $itemlist.find("#userimg").attr("style", "background-image: url(/images/head/" + data.data.id + "_l.jpg);");
  200. }
  201. var userType = autho(data.data.authType, data.data.orgAuth, data.data.authStatus);
  202. $itemlist.find(".authiconNew").attr("title", userType.title);
  203. $itemlist.find(".authiconNew").addClass(userType.sty);
  204. }
  205. },
  206. "error":function(){
  207. $.MsgBox.Alert('提示','链接服务器超时')
  208. }
  209. });
  210. }
  211. //相关资源
  212. function relevantResources(){
  213. $.ajax({
  214. "url": "/ajax/article/ralateRes",
  215. "type": "get",
  216. "dataType" : "json",
  217. "data" :{"articleId":articleId},
  218. "success": function(data) {
  219. if(data.success && data.data) {
  220. for(var i = 0; i < data.data.length; i++) {
  221. var resourceId = data.data[i].resourceId;
  222. relevantResourcesList(resourceId)
  223. }
  224. }
  225. },
  226. "error": function() {
  227. $.MsgBox.Alert('提示', '链接服务器超时')
  228. }
  229. });
  230. }
  231. //相关资源信息
  232. function relevantResourcesList(resourceId){
  233. $.ajax({
  234. "url" : "/ajax/resource/resourceInfo",
  235. "type" : "GET" ,
  236. "dataType" : "json",
  237. "data" :{"resourceId":resourceId},
  238. "success" : function(data) {
  239. console.log(data);
  240. if (data.success && data.data){
  241. var itemlist = '<li><a href="" class="flexCenter urlgo">';
  242. itemlist += '<div class="madiaHead resouseHead" id="userimg"></div>';
  243. itemlist += '<div class="madiaInfo">';
  244. itemlist += '<p class="h1Font" id="resourceName"></p>';
  245. itemlist += '<p class="h2Font ellipsisSty" id="name"></p>';
  246. itemlist += '<p><span class="h2Font uname"></span><em class="authiconNew" title="科袖认证专家"></em></p>';
  247. itemlist += '</div></a></li>';
  248. $itemlist = $(itemlist);
  249. $("#resources").append($itemlist);
  250. var datalist = data.data;
  251. $itemlist.find("#resourceName").text(datalist.resourceName);
  252. $itemlist.find("#name").text("用途:"+datalist.supportedServices);
  253. $itemlist.find(".uname").text(datalist.editProfessor.name);
  254. $itemlist.find(".urlgo").attr("href", "resourceShow.html?resourceId="+datalist.resourceId);
  255. var userType = autho(datalist.editProfessor.authType, datalist.editProfessor.orgAuth, datalist.editProfessor.authStatus);
  256. $itemlist.find(".authiconNew").attr("title", userType.title);
  257. $itemlist.find(".authiconNew").addClass(userType.sty);
  258. if(datalist.images.length > 0) {
  259. $itemlist.find("#userimg").attr("style", "background-image: url(/data/resource/" + datalist.images[0].imageSrc + ");");
  260. }
  261. }
  262. },
  263. "error":function(){
  264. $.MsgBox.Alert('提示','链接服务器超时')
  265. }
  266. });
  267. }
  268. function keysli() {
  269. $("#tagList li").each(function(i) {
  270. var liid = $(this).text();
  271. experarray.push(liid);
  272. });
  273. return $.unique(experarray);
  274. }
  275. //相关文章信息
  276. function relevantarticalList(id,num){
  277. keysli();
  278. if(num==1){
  279. var data = {"keys":experarray,"professorId":id,"articleId":articleId,"rows":10}
  280. }
  281. if(num==2){
  282. var data = {"keys":experarray,"orgId":id,"articleId":articleId,"rows":10}
  283. }
  284. $.ajax({
  285. "url" : "/ajax/article/ralateArticles",
  286. "type" : "GET" ,
  287. "dataType" : "json",
  288. "data" :data,
  289. //"async":false,
  290. "traditional": true, //传数组必须加这个
  291. "success" : function(data) {
  292. console.log(data);
  293. if (data.success && data.data){
  294. var itemlist = '';
  295. $("#abutartical").html("");
  296. for(var i = 0; i < data.data.length; i++) {
  297. var itemlist = '<li><a href="" class="flexCenter urlgo">';
  298. itemlist += '<div class="madiaHead artHead" id="userimg"></div>';
  299. itemlist += '<div class="madiaInfo">';
  300. itemlist += '<p class="h1Font ellipsisSty" id="resourceName"></p>';
  301. itemlist += '<p><span class="h1Font username2"></span><em class="authiconNew" id="relatedLabels" title="科袖认证专家"></em></p>';
  302. itemlist += '</div></a></li>';
  303. $itemlist = $(itemlist);
  304. $("#abutartical").append($itemlist);
  305. var datalist = data.data[i];
  306. $itemlist.find("#resourceName").text(datalist.articleTitle);
  307. $itemlist.find(".urlgo").attr("href", "articalShow.html?articleId="+datalist.articleId);
  308. if(datalist.articleImg!=undefined){
  309. $itemlist.find("#userimg").attr("style", "background-image: url(/data/article/" + datalist.articleImg + ");");
  310. }
  311. if(datalist.articleType==1){
  312. $.ajax({
  313. "url" : "/ajax/professor/baseInfo/"+datalist.professorId,
  314. "type" : "GET" ,
  315. "dataType" : "json",
  316. "async":false,
  317. "success" : function($data) {
  318. if ($data.success && $data.data){
  319. $itemlist.find(".username2").text($data.data.name);
  320. var userType = autho($data.data.authType, $data.data.orgAuth, $data.data.authStatus);
  321. $itemlist.find("#relatedLabels").attr("title", userType.title);
  322. $itemlist.find("#relatedLabels").addClass(userType.sty);
  323. }
  324. },
  325. "error":function(){
  326. $.MsgBox.Alert('提示','链接服务器超时')
  327. }
  328. });
  329. }
  330. if(datalist.articleType==2){
  331. $.ajax({
  332. "url" : "/ajax/org/"+datalist.orgId,
  333. "type" : "GET" ,
  334. "dataType" : "json",
  335. "async":false,
  336. "success" : function($data) {
  337. console.log($data)
  338. if ($data.success && $data.data){
  339. $itemlist.find(".username2").text($data.data.name);
  340. $itemlist.find("#relatedLabels").addClass("authicon-com-ok").attr("title", "认证企业");
  341. }
  342. },
  343. "error":function(){
  344. $.MsgBox.Alert('提示','链接服务器超时')
  345. }
  346. });
  347. }
  348. }
  349. }
  350. },
  351. "error":function(){
  352. $.MsgBox.Alert('提示','链接服务器超时')
  353. }
  354. });
  355. }
  356. /*时间转换*/
  357. function Time(dealtime) {
  358. var s = dealtime;
  359. var m = s.substr(4, 2);
  360. var d = s.substr(6, 2);
  361. var h = s.substr(8, 2);
  362. var minute = s.substr(10, 2);
  363. var formatTime = m.replace(/\b(0+)/gi, "") + "月" + d + "日 " + h + ":" + minute;
  364. return formatTime;
  365. }
  366. //拆解关键字
  367. function industryShow(data){
  368. if(data != undefined && data.length != 0 ){
  369. var subs = new Array();
  370. if(data.indexOf(',')){
  371. subs = data.split(',');
  372. }else{
  373. subs[0] = data;
  374. }
  375. if(subs.length>0){
  376. for (var i = 0; i < subs.length; i++)
  377. {
  378. $("#tagList").append('<li class="delkeylist"><p class="h2Font">'+ subs[i] +'</p></li>');
  379. };
  380. }
  381. }
  382. }
  383. //拆解企业应用行业
  384. function QindustryShow(data){
  385. if(data != undefined && data.length != 0 ){
  386. var subs = new Array();
  387. subs = data.replace(',',' | ');
  388. if(subs.length>0){
  389. for (var i = 0; i < subs.length; i++)
  390. {
  391. $("#Qindustry").append(subs[i]);
  392. };
  393. }
  394. }
  395. }
  396. });
  397. //文章点击点赞
  398. $('.thumbBlock').on("click",".thunbgo",function(){
  399. if (userid && userid != "null" && userid != null) {
  400. addAgree();
  401. }else{
  402. $.MsgBox.Alert('提示',"请先登录再进行关注");
  403. $("#mb_btn_ok").val("去登录");
  404. var aele = document.createElement('a');
  405. $("#mb_btnbox").append(aele);
  406. $("#mb_btnbox a").css({
  407. 'display': "block",
  408. 'width': '100%',
  409. 'height': '40px',
  410. 'position': 'absolute',
  411. 'bottom': '-6px',
  412. 'left': '0'
  413. });
  414. aele.setAttribute('href', '../login.html');
  415. }
  416. })
  417. /*判断文章是否被赞*/
  418. function isAgree(articleAgree) {
  419. var data = {"operateId": userid,"articleId": articleId}
  420. $.ajax({
  421. url:"/ajax/article/isAgree",
  422. data:data,
  423. dataType: 'json', //数据格式类型
  424. type: 'get', //http请求类型
  425. timeout: 10000,
  426. async: false,
  427. success: function(data) {
  428. if(data.success){
  429. if(data.data!= null){
  430. $(".thumbBtn").html("已赞 <span>"+articleAgree+"</span>");
  431. $(".thumbBtn").addClass("thumbedBtn");
  432. }else{
  433. $(".thumbBtn").html("赞 <span>"+articleAgree+"</span>");
  434. $(".thumbBtn").addClass("thunbgo");
  435. }
  436. }
  437. },
  438. error: function() {
  439. $.MsgBox.Alert('提示',"服务器链接超时");
  440. }
  441. });
  442. }
  443. /*点赞*/
  444. function addAgree() {
  445. var data = {"operateId": userid,"articleId": articleId}
  446. $.ajax({
  447. url:"/ajax/article/agree",
  448. data:data,
  449. dataType: 'json', //数据格式类型
  450. type: 'POST', //http请求类型
  451. timeout: 10000,
  452. async: false,
  453. success: function(data) {
  454. if(data.success){
  455. var articleAgreeval = $(".thumbBtn span").text();
  456. $(".thumbBtn").html("已赞 <span>"+parseInt(articleAgreeval+1)+"</span>");
  457. $(".thumbBtn").addClass("thumbedBtn");
  458. $(".thumbBtn").removeClass("thunbgo");
  459. }
  460. },
  461. error: function() {
  462. $.MsgBox.Alert('提示',"服务器链接超时");
  463. }
  464. });
  465. }
  466. //点击专家关注
  467. $('.attenSpan').click(function(){
  468. if (userid && userid != "null" && userid != null) {
  469. if($(this).is('.attenSpanyes')){
  470. cancelCollectionExpert($("#Zname").attr("dataid"),1)
  471. }else{
  472. collectionExpert($("#Zname").attr("dataid"),1);
  473. }
  474. }else{
  475. $.MsgBox.Alert('提示',"请先登录再进行关注");
  476. $("#mb_btn_ok").val("去登录");
  477. var aele = document.createElement('a');
  478. $("#mb_btnbox").append(aele);
  479. $("#mb_btnbox a").css({
  480. 'display': "block",
  481. 'width': '100%',
  482. 'height': '40px',
  483. 'position': 'absolute',
  484. 'bottom': '-6px',
  485. 'left': '0'
  486. });
  487. aele.setAttribute('href', '../login.html');
  488. }
  489. })
  490. //点击文章收藏
  491. $('#attention em').click(function(){
  492. if (userid && userid != "null" && userid != null) {
  493. if($(this).is('.icon-collected')){
  494. cancelCollectionExpert(articleId,2)
  495. }else{
  496. collectionExpert(articleId,2);
  497. }
  498. }else{
  499. $.MsgBox.Alert('提示',"请先登录再进行收藏");
  500. $("#mb_btn_ok").val("去登录");
  501. var aele = document.createElement('a');
  502. $("#mb_btnbox").append(aele);
  503. $("#mb_btnbox a").css({
  504. 'display': "block",
  505. 'width': '100%',
  506. 'height': '40px',
  507. 'position': 'absolute',
  508. 'bottom': '-6px',
  509. 'left': '0'
  510. });
  511. aele.setAttribute('href', '../login.html');
  512. }
  513. })
  514. /*判断是非关注专家*/
  515. function ifCollection(getid,num) {
  516. var data = {"professorId": userid,"watchObject": getid}
  517. //alert(JSON.stringify(data))
  518. $.ajax({
  519. url:"/ajax/watch/hasWatch",
  520. data:data,
  521. dataType: 'json', //数据格式类型
  522. type: 'get', //http请求类型
  523. timeout: 10000,
  524. async: false,
  525. success: function(data) {
  526. if(num==1){
  527. if(data.success && data.data != null) {
  528. $('.attenSpan').addClass("attenSpanyes");
  529. $('.attenSpan').text('已关注');
  530. zjreturnId = data.data.watchObject;
  531. } else {
  532. $('.attenSpan').removeClass("attenSpanyes");
  533. $('.attenSpan').text('关注');
  534. }
  535. }
  536. if(num==2){
  537. if(data.success && data.data != null) {
  538. $('#attention em').addClass("icon-collected");
  539. wzreturnId = data.data.watchObject;
  540. } else {
  541. $('#attention em').removeClass("icon-collected");
  542. }
  543. }
  544. },
  545. error: function() {
  546. $.MsgBox.Alert('提示',"服务器链接超时");
  547. }
  548. });
  549. }
  550. /*关注专家*/
  551. function collectionExpert(watchObject,num) {
  552. if(num==1){
  553. var data = {"professorId": userid,"watchObject": watchObject,"watchType": 1}
  554. }else{
  555. var data = {"professorId": userid,"watchObject": watchObject,"watchType": 2}
  556. }
  557. $.ajax({
  558. url:"/ajax/watch",
  559. data:data,
  560. dataType: 'json', //数据格式类型
  561. type: 'POST', //http请求类型
  562. timeout: 10000,
  563. async: false,
  564. success: function(data) {
  565. console.log(data.success)
  566. if(num==1){
  567. if(data.success) {
  568. $('.attenSpan').addClass("attenSpanyes");
  569. $('.attenSpan').text('已关注');
  570. zjreturnId = data.data.watchObject;
  571. }
  572. }
  573. if(num==2){
  574. if(data.success) {
  575. $('#attention em').addClass("icon-collected");
  576. wzreturnId = data.data.watchObject;
  577. }
  578. }
  579. },
  580. error: function() {
  581. $.MsgBox.Alert('提示',"服务器链接超时");
  582. }
  583. });
  584. }
  585. /*取消收藏专家*/
  586. function cancelCollectionExpert(watchObject,num) {
  587. $.ajax({
  588. url:"/ajax/watch/delete",
  589. data: {
  590. professorId: userid,
  591. watchObject: watchObject
  592. },
  593. dataType: 'json', //数据格式类型
  594. type: 'post', //http请求类型
  595. timeout: 10000,
  596. async: true,
  597. success: function(data) {
  598. console.log(data.success)
  599. if(num==1){
  600. if(data.success) {
  601. $('.attenSpan').removeClass("attenSpanyes");
  602. $('.attenSpan').text('关注');
  603. }
  604. }
  605. if(num==2){
  606. if(data.success) {
  607. $('#attention em').removeClass("icon-collected");
  608. }
  609. }
  610. },
  611. error: function(data) {
  612. $.MsgBox.Alert('提示',"服务器链接超时");
  613. }
  614. });
  615. }
  616. //文章浏览量
  617. function pageViewsVal(){
  618. $.ajax({
  619. "url" : "/ajax/article/pageViews",
  620. "type" : "POST" ,
  621. "dataType" : "json",
  622. "data" :{"articleId":articleId},
  623. "success" : function(data) {
  624. console.log(data);
  625. if (data.success){
  626. }
  627. },
  628. "error":function(){
  629. $.MsgBox.Alert('提示','链接服务器超时')
  630. }
  631. });
  632. }
  633. ArticleMessagesNumbe();
  634. //文章留言条数
  635. function ArticleMessagesNumbe(){
  636. $.ajax({
  637. "url" : "/ajax/leaveWord/lwCount",
  638. "type" : "GET" ,
  639. "dataType" : "json",
  640. "data" :{"articleId":articleId},
  641. "success" : function(data) {
  642. console.log(data);
  643. if (data.success){
  644. $(".message").text(data.data);
  645. }
  646. },
  647. "error":function(){
  648. $.MsgBox.Alert('提示','链接服务器超时')
  649. }
  650. });
  651. }
  652. /*留言模块*/
  653. $(".msgCont").on("keyup", function() {
  654. $(".msgconNum span").text($(this).val().length);
  655. if($(this).val().length > 200) {
  656. $(this).val($(this).val().substr(0, 200));
  657. }
  658. if($(this).val().length <= 0){
  659. $("#meSendtt").css("background", "#ccc");
  660. }else{
  661. $("#meSendtt").css("background", "#ff9900");
  662. }
  663. })
  664. $("#meSendtt").on("click", function() {
  665. article();
  666. })
  667. //查看更多留言
  668. $("#moreArtical").on("click",function(){
  669. vcreateTime = $(".commentList li").last().attr("data-time");
  670. orderKey = $(".commentList li").last().attr("data-key");
  671. message(5,1);
  672. })
  673. //删除留言
  674. $(".commentList").on("click",".messageDel",function(){
  675. var commenid = $(this).attr("data-id");
  676. articledel(commenid)
  677. })
  678. //发布留言
  679. function article() {
  680. $.ajax({
  681. url:"/ajax/leaveWord",
  682. dataType: 'json', //数据格式类型
  683. type: 'POST', //http请求类型
  684. data: {
  685. "articleId": articleId,
  686. "sender": userid,
  687. "content": $(".msgCont").val(),
  688. },
  689. timeout: 10000, //超时设置
  690. success: function(data) {
  691. var $info = data.data || {};
  692. if(data.success && data.data) {
  693. message(5,2);
  694. }
  695. },
  696. error: function() {
  697. $.MsgBox.Alert('提示', '服务器请求失败')
  698. }
  699. });
  700. }
  701. message(5,2);
  702. function message(rows,num) {
  703. if(num==1){
  704. var data = {"articleId": articleId,"createTime": vcreateTime,"orderKey": orderKey,"rows": rows}
  705. }else{
  706. var data = {"articleId": articleId,"rows": rows}
  707. }
  708. $.ajax({
  709. url: "/ajax/leaveWord/ql",
  710. dataType: 'json', //数据格式类型
  711. type: 'GET', //http请求类型
  712. data: data,
  713. timeout: 10000, //超时设置
  714. success: function(data) {
  715. if(data.success) {
  716. if(data.data != ""){
  717. if(num==2){
  718. $(".commentList").html("");
  719. }
  720. if(data.data.length > 4){
  721. $("#moreArtical").removeClass("displayNone");
  722. }else{
  723. $("#moreArtical").addClass("displayNone");
  724. }
  725. for(var i = 0; i < data.data.length; i++) {
  726. var itemlist = '<li data-time="" data-key="">';
  727. itemlist += '<a href class="userhref"> <div class="madiaHead useHead"></div></a>';
  728. itemlist += '<div class="madiaInfo">';
  729. itemlist += '<p><a href class="userhref"><span class="h1Font messageName">张某某</span></a><em class="authiconNew" title="科袖认证专家"></em><span class="commenttime">9月30号 12:00</span></p>';
  730. itemlist += '<p class="h2Font messageContent">sdfsdfs</p>';
  731. itemlist += '<div class="operateSpan"><span class="callBack">回复</span><span class="messageDel">删除</span></div>';
  732. itemlist += '</div></li>';
  733. $itemlist = $(itemlist);
  734. $(".commentList").append($itemlist);
  735. var datalist = data.data[i];
  736. $itemlist.find(".messageName").text(datalist.professor.name);
  737. $itemlist.find(".messageContent").text(datalist.content);
  738. var userType = autho(datalist.professor.authType, datalist.professor.orgAuth, datalist.professor.authStatus);
  739. $itemlist.find(".authiconNew").attr("title", userType.title);
  740. $itemlist.find(".authiconNew").addClass(userType.sty);
  741. if(datalist.professor.hasHeadImage==1) {
  742. $(".useHead").attr("style", "background-image: url(/images/head/" + datalist.professor.id + "_l.jpg);");
  743. }
  744. if(datalist.professor.id!=userid){
  745. $(".messageDel").hide();
  746. }
  747. $itemlist.attr("data-time", datalist.createTime);
  748. $itemlist.attr("data-key", datalist.orderKey);
  749. $itemlist.find(".messageDel").attr("data-id", datalist.id);
  750. $itemlist.find(".userhref").attr("href", "information-brow.html?professorId="+datalist.professor.id);
  751. var createtime = datalist.createTime;
  752. $itemlist.find(".commenttime").text(commenTime(createtime));
  753. }
  754. }else{
  755. if(num==2){
  756. $(".commentList").html("");
  757. }else{
  758. $("#moreArtical").addClass("displayNone");
  759. }
  760. }
  761. }
  762. },
  763. error: function() {
  764. $.MsgBox.Alert('提示', '服务器请求失败')
  765. }
  766. });
  767. }
  768. //删除自己的留言
  769. function articledel(commenid) {
  770. $.ajax({
  771. url:"/ajax/leaveWord/delete",
  772. dataType: 'json', //数据格式类型
  773. type: 'POST', //http请求类型
  774. data: {
  775. "id": commenid,
  776. },
  777. timeout: 10000, //超时设置
  778. success: function(data) {
  779. if(data.success) {
  780. message(5,2);
  781. }
  782. },
  783. error: function() {
  784. $.MsgBox.Alert('提示', '服务器请求失败')
  785. }
  786. });
  787. }
  788. function commenTime(startTime){
  789. var nowTimg = new Date();
  790. var startdate = new Date();
  791. startdate.setFullYear(parseInt(startTime.substring(0,4)));
  792. startdate.setMonth(parseInt(startTime.substring(4,6))-1);
  793. startdate.setDate(parseInt(startTime.substring(6,8)));
  794. startdate.setHours(parseInt(startTime.substring(8,10)));
  795. startdate.setMinutes(parseInt(startTime.substring(10,12)));
  796. startdate.setSeconds(parseInt(startTime.substring(12,14)));
  797. var date3=nowTimg.getTime()-startdate.getTime(); //时间差的毫秒数
  798. var hours = parseInt((date3 % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
  799. var minutes = parseInt((date3 % (1000 * 60 * 60)) / (1000 * 60));
  800. if(date3 < 60000){
  801. return "刚刚";
  802. }else if(date3 > 60000 && date3 < 3600000){
  803. return minutes + "分钟前";
  804. }else if(date3 > 3600000 && date3 < 86400000){
  805. return hours + "小钟前";
  806. }else if(date3 > 86400000 && date3 < 172800000){
  807. return "昨天 " + startTime.substring(10,12) + ":" +startTime.substring(12,14);
  808. }else{
  809. return startTime.substring(4,6) + "月" + startTime.substring(6,8) + "日 " + startTime.substring(8,10) + ":" + startTime.substring(10,12);
  810. }
  811. }
  812. window.onload=function(){
  813. pageViewsVal();//文章浏览量
  814. }