portal html css js resource

articalInfo.js 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642
  1. $(document).ready(function() {
  2. var articleId = GetQueryString("articleId");
  3. var professorId = GetQueryString("professorId");
  4. var oFlag = GetQueryString("oFlag");
  5. loginStatus();//判断个人是否登录
  6. var userid = $.cookie("userid");
  7. if(userid == "null"||userid==undefined) {
  8. $(".goMsgbox").hide();
  9. } else {
  10. $("#login").hide();
  11. }
  12. /*应用行业*/
  13. var industryShow = function(data, $id) {
  14. if(data != undefined && data.length != 0) {
  15. var subs = new Array();
  16. if(data.indexOf(',')) {
  17. subs = data.split(',');
  18. } else {
  19. subs[0] = data;
  20. }
  21. if(subs.length > 0) {
  22. var html = [];
  23. for(var i = 0; i < subs.length; i++) {
  24. html.push("<li>" + subs[i] + "</li>");
  25. };
  26. document.getElementById($id).innerHTML = html.join('');
  27. }
  28. }
  29. }
  30. function proInfoMain() {
  31. $.ajax({
  32. url: "/ajax/article/query",
  33. dataType: 'json', //数据格式类型
  34. type: 'GET', //http请求类型
  35. data: {
  36. "articleId": articleId
  37. },
  38. timeout: 10000, //超时设置
  39. success: function(data) {
  40. var $info = data.data || {};
  41. if(data.success && data.data) {
  42. console.log(data);
  43. //var oTime = $info.createTime.substring(0, 4) + "." + $info.createTime.substring(4, 6) + "." + $info.createTime.substring(6, 8)
  44. var oTime=timeGeshi($info.createTime);
  45. $("#creTime").text(oTime);
  46. $("#articleName").text($info.articleTitle);
  47. $(".message1").text($info.articleAgree);
  48. if($info.subject) {
  49. industryShow($info.subject, "subjectList");
  50. } else {
  51. $("#subjectList").parent().hide();
  52. }
  53. if($info.industry) {
  54. industryShow($info.industry, "industryList");
  55. } else {
  56. $("#industryList").parent().hide();
  57. }
  58. if(!$info.subject&&!$info.industry){
  59. $(".resAbout").hide();
  60. }
  61. var proTitle = document.getElementById("proTitle");
  62. var proOffice = document.getElementById("proOffice");
  63. var proOrg = document.getElementById("proOrg");
  64. var proAddress = document.getElementById("proAddress");
  65. if($info.articleContent) {
  66. $("#main_content").html($info.articleContent);
  67. var oImg = $("#main_content").find("img");
  68. for(var i = 0; i < oImg.length; i++) {
  69. (function(n) {
  70. $("#main_content").find("img").eq(n).load(function() {
  71. var imgWidth = $("#main_content").find("img").eq(n).width();
  72. var pWidth = $("#main_content").find("p").width();
  73. if(imgWidth > pWidth) {
  74. $("#main_content").find("img").eq(n).css({
  75. "width": "100%"
  76. });
  77. }
  78. })
  79. })(i);
  80. }
  81. }
  82. var articletitle = $info.articleTitle + "-科袖网";
  83. window.setTimeout(function() {
  84. document.title = articletitle;
  85. }, 500);
  86. }
  87. },
  88. error: function() {
  89. return;
  90. }
  91. });
  92. }
  93. var proArticle = function() {
  94. var $f=new Object();
  95. if(oFlag==1){
  96. $f.orgId=professorId;
  97. }else{
  98. $f.professorId=professorId;
  99. }
  100. /*科研文章*/
  101. $.ajax({
  102. url: (oFlag==1)?"/ajax/article/qaOrg":"/ajax/article/qaPro",
  103. dataType: 'json', //数据格式类型
  104. type: 'GET', //http请求类型
  105. data: $f,
  106. timeout: 10000, //超时设置
  107. success: function(data) {
  108. if(data.success) {
  109. var $data = data.data;
  110. if($data.length == 1) {
  111. $("div:contains('相关文章')").parents(".rightBlock").hide();
  112. return;
  113. }
  114. var oNu=Math.min(data.data.length,3);
  115. for(var i = 0; i < oNu; i++) {
  116. if(articleId != $data[i].articleId) {
  117. var articleImg = $data[i].articleImg;
  118. (!articleImg) ? articleImg = "../images/default-artical.jpg": articleImg = '/data/article/' + $data[i].articleImg;
  119. if($data[i].industry) {
  120. var subs = new Array();
  121. if($data[i].industry.indexOf(',')) {
  122. subs = $data[i].industry.split(',');
  123. } else {
  124. subs[0] = $data[i].industry;
  125. }
  126. if(subs.length > 0) {
  127. var indu = "";
  128. for(var n = 0; n < subs.length; n++) {
  129. indu += "<span>" + subs[n] + "</span>";
  130. }
  131. }
  132. } else {
  133. var indu = "";
  134. }
  135. var add = '<li>'
  136. if(oFlag==1){
  137. add += '<a href="articalInfo.html?oFlag=1&articleId=' + $data[i].articleId + '&professorId=' + professorId + '">'
  138. }else{
  139. add += '<a href="articalInfo.html?articleId=' + $data[i].articleId + '&professorId=' + professorId + '">'
  140. }
  141. add += '<div class="art_topicBox">'
  142. add += '<div class="art_img"style="background-image:url(' + articleImg + ')"></div>'
  143. add += '<div class="art_tbox">'
  144. add += '<h6 id="artical_topic" >' + $data[i].articleTitle + '</h6>'
  145. add += '</div>'
  146. add += '</div>'
  147. add += '<div class="tagsBox">'
  148. add += indu
  149. add += '</div>'
  150. add += '</a>'
  151. add += '</li>'
  152. $(".otherRes").append(add);
  153. }
  154. }
  155. }
  156. },
  157. error: function() {
  158. return;
  159. }
  160. });
  161. }
  162. function message() {
  163. $.ajax({
  164. url: "/ajax/leaveWord/ql",
  165. dataType: 'json', //数据格式类型
  166. type: 'GET', //http请求类型
  167. data: {
  168. "articleId": articleId
  169. },
  170. timeout: 10000, //超时设置
  171. success: function(data) {
  172. var $info = data.data || {};
  173. if(data.success && data.data) {
  174. $(".commentList").html("");
  175. $(".message").text($info.length);
  176. for(var i = 0; i < $info.length; i++) {
  177. //var time = $info[i].createTime.substring(0, 4) + "年" + $info[i].createTime.substring(4, 6) + "月" + $info[i].createTime.substring(6, 8) + "日 " + $info[i].createTime.substring(8, 10) + ":" + $info[i].createTime.substring(10, 12);
  178. var time=timeGeshi($info[i].createTime)
  179. if($info[i].professor.hasHeadImage){
  180. var img='/images/head/' + $info[i].professor.id + '_l.jpg'
  181. }else{
  182. var img='../images/default-photo.jpg'
  183. }
  184. var string = '<li>'
  185. string += '<a class="proinfor clearfix">'
  186. string += '<div class="headblock floatL" style="width: 60px;"><img class="headimg userRadius" src="'+img+'" width="100%"></div>'
  187. string += '<div class="media-body floatL">'
  188. string += '<div><span class="listtit">'+$info[i].professor.name+'</span><span class="thistime">'+time+'</span></div>'
  189. string += '<p class="listtit3">'+$info[i].content+'</p>'
  190. if(userid==$info[i].professor.id){
  191. string += '<p class="listtit3" style="text-align:right;"><span style="cursor:pointer;" data-id="'+$info[i].id+'">删除</span></p>'
  192. }
  193. string += '</div></a></li>'
  194. $(".commentList").append(string);
  195. }
  196. }
  197. },
  198. error: function() {
  199. return;
  200. }
  201. });
  202. }
  203. function userInformation(){
  204. if(oFlag==1){
  205. $.ajax({
  206. url: "/ajax/org/" + professorId,
  207. type: "GET",
  208. timeout: 10000,
  209. dataType: "json",
  210. beforeSend: function() {},
  211. success: function(data, textState) {
  212. if(data.success) {
  213. var $data = data.data;
  214. $("#nameS").text($data.name);
  215. $("#proName").text($data.name);
  216. if($data.authStatus == 3) {
  217. $("#authFlag,#proTitle").replaceWith("<em class='authiconNew authicon-com-ok' title='认证企业'></em>");
  218. } else {
  219. $("#authFlag,#proTitle").replaceWith("");
  220. }
  221. if($data.hasOrgLogo) {
  222. $("#headImg,#proHead").attr("src", "/images/org/" + $data.id + ".jpg").addClass("headRadius").removeClass("userRadius");
  223. } else {
  224. $("#headImg,#proHead").attr("src", "images/default-icon.jpg").addClass("headRadius").removeClass("userRadius");
  225. }
  226. // if($data.foundTime) {
  227. // var oTime = $data.foundTime.substring(0,4)+"-"+$data.foundTime.substring(4,6)+"-"+$data.foundTime.substring(6,8);
  228. // $("#createTime").text(oTime);
  229. // }
  230. if($data.city) {
  231. $("#ocity").text($data.city);
  232. }
  233. if($data.orgSize) {
  234. switch($data.orgSize) {
  235. case '1':
  236. $("#qualificationList").text("50人以内")
  237. break;
  238. case '2':
  239. $("#qualificationList").text("50-100人")
  240. break;
  241. case '3':
  242. $("#qualificationList").text("100-200人")
  243. break;
  244. case '4':
  245. $("#qualificationList").text("200-500人")
  246. break;
  247. case '5':
  248. $("#qualificationList").text("500-1000人")
  249. break;
  250. default:
  251. $("#qualificationList").text("1000人以上")
  252. break;
  253. }
  254. }
  255. if($data.orgType) {
  256. switch($data.orgType) {
  257. case '2':
  258. $("#orgType").text("国有企业");
  259. break;
  260. case '3':
  261. $("#orgType").text("上市企业");
  262. break;
  263. case '4':
  264. $("#orgType").text("合资企业");
  265. break;
  266. case '5':
  267. $("#orgType").text("私人企业");
  268. break;
  269. case '6':
  270. $("#orgType").text("外资企业");
  271. break;
  272. default:
  273. $("#orgType").text("初创企业");
  274. break;
  275. }
  276. }
  277. }
  278. },
  279. error: function(XMLHttpRequest, textStats, errorThrown) {
  280. $.MsgBox.Alert('提示', '服务器请求失败')
  281. }
  282. })
  283. }else{
  284. $.ajax({
  285. url: "/ajax/professor/editBaseInfo/"+professorId,
  286. dataType: 'json', //数据格式类型
  287. type: 'GET', //http请求类型
  288. timeout: 10000, //超时设置
  289. success: function(data) {
  290. console.log(data);//
  291. if(data.success && data.data) {
  292. /*if(data.data.hasHeadImage==1){
  293. $("#limg").attr("src","/images/head/" + data.data.id + "_l.jpg")
  294. }*/
  295. var $profesor=data.data;
  296. $("#nameS,#proName").text($profesor.name);
  297. var oString = todStr($profesor.title, $profesor.office, $profesor.department);
  298. $("#proTitle").text(oString);
  299. if($profesor.title) {
  300. if($profesor.office) {
  301. $("#orgType").text($profesor.title + " , "+$profesor.office);
  302. } else {
  303. $("#orgType").text($profesor.title);
  304. }
  305. }else{
  306. if($profesor.office) {
  307. $("#orgType").text($profesor.office);
  308. }
  309. }
  310. if($profesor.department) {
  311. $("#qualificationList").text($profesor.department);
  312. }
  313. if($profesor.orgName){
  314. $("#createTime").text($profesor.orgName)
  315. }
  316. if($profesor.address) {
  317. $("#ocity").text($profesor.address);
  318. }
  319. if($profesor.hasHeadImage) {
  320. $("#headImg,#proHead").attr("src", "/images/head/" + $profesor.id + "_l.jpg").addClass("userRadius").removeClass("headRadius")
  321. }else{
  322. $("#headImg,#proHead").attr("src", "images/default-photo.jpg").addClass("userRadius").removeClass("headRadius")
  323. }
  324. }
  325. },
  326. error: function(XMLHttpRequest) {
  327. $.MsgBox.Alert('提示', '服务器请求失败')
  328. }
  329. });
  330. }
  331. }
  332. /*职位职称所属机构*/
  333. function todStr() {
  334. var arr = new Array(),
  335. i;
  336. for(i in arguments) {
  337. if(arguments[i]) {
  338. arr.push(arguments[i])
  339. }
  340. }
  341. return arr.join();
  342. }
  343. /*时间格式转换*/
  344. function timeGeshi(otm) {
  345. var ti=otm.substring(4, 5);
  346. var otme;
  347. if(ti=="0"){
  348. otme =otm.substring(5, 6) + "月" + otm.substring(6, 8)+"日 "+otm.substring(8, 10)+":"+otm.substring(10, 12);
  349. }else{
  350. otme =otm.substring(4, 6) + "月" + otm.substring(6, 8)+"日 "+otm.substring(8, 10)+":"+otm.substring(10, 12);
  351. }
  352. return otme;
  353. }
  354. function article() {
  355. $.ajax({
  356. url:"/ajax/leaveWord",
  357. dataType: 'json', //数据格式类型
  358. type: 'POST', //http请求类型
  359. data: {
  360. "articleId": articleId,
  361. "sender": userid,
  362. "content": $("textarea").val(),
  363. },
  364. timeout: 10000, //超时设置
  365. success: function(data) {
  366. var $info = data.data || {};
  367. if(data.success && data.data) {
  368. document.getElementsByTagName("textarea")[0].value = "";
  369. document.getElementById("meSend").style.background="#dadada";
  370. message();
  371. }
  372. },
  373. error: function() {
  374. $.MsgBox.Alert('提示', '服务器请求失败')
  375. }
  376. });
  377. }
  378. function trim(str) { //删除左右两端的空格
  379.   
  380. return str.replace(/(^\s*)|(\s*$)/g, "");  
  381. }
  382. document.getElementsByTagName("textarea")[0].addEventListener("keyup", function() {
  383. var valueLength = document.getElementsByTagName("textarea")[0].value;
  384. var length = trim(valueLength);
  385. if(length) {
  386. $("#meSend").addClass("colorAdd");
  387. document.getElementById("meSend").style.background="#ff9900";
  388. } else {
  389. $("#meSend").removeClass("colorAdd");
  390. document.getElementById("meSend").style.background="#dadada";
  391. }
  392. });
  393. $(".goMsgbox").on('click', '.colorAdd', function() {
  394. article();
  395. });
  396. function luser(){
  397. $.ajax({
  398. url: "/ajax/professor/editBaseInfo/"+userid,
  399. dataType: 'json', //数据格式类型
  400. type: 'GET', //http请求类型
  401. timeout: 10000, //超时设置
  402. success: function(data) {
  403. if(data.success && data.data) {
  404. if(data.data.hasHeadImage==1){
  405. $("#limg").attr("src","/images/head/" + data.data.id + "_l.jpg")
  406. }
  407. }
  408. },
  409. error: function(XMLHttpRequest) {
  410. $.MsgBox.Alert('提示', '服务器请求失败');
  411. }
  412. });
  413. }
  414. proInfoMain();
  415. proArticle();
  416. message();
  417. userInformation();
  418. luser();
  419. /*删除留言*/
  420. $(".commentList").on("click","span:contains('删除')",function(){
  421. var oDid=$(this).attr("data-id");
  422. var $this=$(this);
  423. $.ajax({
  424. url: "/ajax/leaveWord/delete",
  425. dataType: 'json', //数据格式类型
  426. type: 'POST', //http请求类型
  427. timeout: 10000, //超时设置
  428. data:{
  429. "id":oDid
  430. },
  431. success: function(data) {
  432. if(data.success) {
  433. $this.parents('li').remove();
  434. var oNum=$(".message").eq(0).text();
  435. $(".message").text(oNum-1);
  436. }
  437. },
  438. error: function(XMLHttpRequest) {
  439. $.MsgBox.Alert('提示', '服务器请求失败')
  440. }
  441. });
  442. })
  443. /*跳转详情页面专家或者企业*/
  444. $("#details").click(function(){
  445. if(oFlag==1){
  446. location.href="companybrowinfor.html?orgId="+professorId;
  447. }else{
  448. location.href="information-brow.html?professorId="+professorId;
  449. }
  450. })
  451. /*点赞模块*/
  452. var oIsGree = {
  453. /*查询登陆者是否为文章点赞*/
  454. inquiry: function() {
  455. $.ajax({
  456. url: "/ajax/article/isAgree",
  457. dataType: 'json', //数据格式类型
  458. type: 'GET', //http请求类型
  459. timeout: 10000, //超时设置
  460. data: {
  461. operateId:userid,
  462. articleId:articleId
  463. },
  464. success: function(data) {
  465. if(data.success) {
  466. if(data.data==null){
  467. $(".plus").attr("data-flag","0");
  468. }else{
  469. $(".plus").attr("data-flag","1");
  470. $(".plus").css("background-position-y","-26px");
  471. }
  472. }
  473. },
  474. error: function(XMLHttpRequest) {
  475. $.MsgBox.Alert('提示', '服务器请求失败');
  476. }
  477. });
  478. },
  479. /*点赞及取消点赞*/
  480. favour:function() {
  481. $(".plus").click(function(){
  482. if(userid == "null"||userid==undefined){
  483. location.href="login.html";
  484. return;
  485. }
  486. var isgree=$(this).attr("data-flag");
  487. if(isgree==0){
  488. oIsGree.articleIsAgree();
  489. }else{
  490. oIsGree.articleNoIsAgree();
  491. }
  492. });
  493. },
  494. /*为文章点赞*/
  495. articleIsAgree:function(){
  496. $.ajax({
  497. url: "/ajax/article/agree",
  498. dataType: 'json', //数据格式类型
  499. type: 'POST', //http请求类型
  500. timeout: 10000, //超时设置
  501. data: {
  502. operateId:userid,
  503. articleId:articleId
  504. },
  505. success: function(data) {
  506. if(data.success) {
  507. $(".plus").attr("data-flag","1");
  508. $(".plus").css("background-position-y","-26px");
  509. $(".message1").text(parseInt($(".message1").html())+1);
  510. }
  511. },
  512. error: function(XMLHttpRequest) {
  513. $.MsgBox.Alert('提示', '服务器请求失败');
  514. }
  515. });
  516. },
  517. /*为文章取消点赞*/
  518. articleNoIsAgree:function(){
  519. $.ajax({
  520. url: "/ajax/article/unAgree",
  521. dataType: 'json', //数据格式类型
  522. type: 'POST', //http请求类型
  523. timeout: 10000, //超时设置
  524. data: {
  525. operateId:userid,
  526. articleId:articleId
  527. },
  528. success: function(data) {
  529. if(data.success) {
  530. $(".plus").attr("data-flag","0");
  531. $(".plus").css("background-position-y","0px");
  532. $(".message1").text(parseInt($(".message1").html())-1);
  533. }
  534. },
  535. error: function(XMLHttpRequest) {
  536. $.MsgBox.Alert('提示', '服务器请求失败');
  537. }
  538. });
  539. }
  540. }
  541. oIsGree.inquiry();
  542. oIsGree.favour();
  543. /*收藏模块*/
  544. var collection={
  545. /*查询是否收藏文章*/
  546. inquiry:function(){
  547. $.ajax({
  548. url: "/ajax/watch/hasWatch",
  549. dataType: 'json', //数据格式类型
  550. type: 'GET', //http请求类型
  551. timeout: 10000, //超时设置
  552. data: {
  553. professorId:userid,
  554. watchObject:articleId
  555. },
  556. success: function(data) {
  557. if(data.success) {
  558. if(data.data==null){
  559. $("#attention").attr("data-flag","0");
  560. }else{
  561. $("#attention").attr("data-flag","1").css({"background":"url(../images/favoricon.png) 0 -26px no-repeat","background-size": "100% auto"});
  562. }
  563. }
  564. },
  565. error: function(XMLHttpRequest) {
  566. $.MsgBox.Alert('提示', '服务器请求失败');
  567. }
  568. });
  569. },
  570. /*收藏及取消收藏*/
  571. attention:function() {
  572. $("#attention").click(function(){
  573. if(userid == "null"||userid==undefined){
  574. location.href="login.html";
  575. return;
  576. }
  577. var attFlag=$(this).attr("data-flag");
  578. if(attFlag==0){
  579. collection.attentionYes();
  580. }else{
  581. collection.attentionNo();
  582. }
  583. });
  584. },
  585. /*收藏文章*/
  586. attentionYes:function(){
  587. $.ajax({
  588. url: "/ajax/watch",
  589. dataType: 'json', //数据格式类型
  590. type: 'POST', //http请求类型
  591. timeout: 10000, //超时设置
  592. data: {
  593. professorId:userid,
  594. watchObject:articleId,
  595. watchType:3
  596. },
  597. success: function(data) {
  598. if(data.success) {
  599. $("#attention").attr("data-flag","1").css({"background":"url(../images/favoricon.png) 0 -26px no-repeat","background-size": "100% auto"});
  600. }
  601. },
  602. error: function(XMLHttpRequest) {
  603. $.MsgBox.Alert('提示', '服务器请求失败');
  604. }
  605. });
  606. },
  607. /*取消收藏文章*/
  608. attentionNo:function(){
  609. $.ajax({
  610. url: "/ajax/watch/delete",
  611. dataType: 'json', //数据格式类型
  612. type: 'POST', //http请求类型
  613. timeout: 10000, //超时设置
  614. data: {
  615. professorId:userid,
  616. watchObject:articleId
  617. },
  618. success: function(data) {
  619. if(data.success) {
  620. $("#attention").attr("data-flag","0").css({"background":"url(../images/favoricon.png) 0 -50px no-repeat","background-size": "100% auto"});
  621. }
  622. },
  623. error: function(XMLHttpRequest) {
  624. $.MsgBox.Alert('提示', '服务器请求失败');
  625. }
  626. });
  627. }
  628. };
  629. collection.inquiry();
  630. collection.attention();
  631. })