portal html css js resource

resourceShow.js 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  1. $(document).ready(function() {
  2. loginStatus(); //判断个人是否登录
  3. var userid = $.cookie("userid");
  4. $(".jqzoom").imagezoom();
  5. $("#thumblist").on("click", "li a", function() {
  6. $(this).parents("li").addClass("tb-selected").siblings().removeClass("tb-selected");
  7. $(".jqzoom").attr('src', $(this).find("img").attr("src"));
  8. $(".jqzoom").attr('rel', $(this).find("img").attr("src"));
  9. });
  10. $('.shareWeixin').hover(function() {
  11. $('.shareCode').stop(true, false).fadeToggle();
  12. });
  13. var resourceId = GetQueryString("resourceId");
  14. ifCollection(resourceId,2)
  15. var professorId = "";
  16. getRecourceMe();
  17. /*获取资源信息*/
  18. function getRecourceMe() {
  19. $.ajax({
  20. "url": "/ajax/resource/queryOne",
  21. "type": "GET",
  22. "success": function(data) {
  23. console.log(data);
  24. if(data.success) {
  25. resourceHtml(data.data);
  26. }
  27. },
  28. "data": {
  29. "resourceId": resourceId
  30. },
  31. dataType: "json",
  32. 'error': function() {
  33. $.MsgBox.Alert('提示', '服务器连接超时!');
  34. }
  35. });
  36. }
  37. /*合作备注及性能参数存储换行格式*/
  38. function outHTML(selecter) {
  39. var getValue = selecter;
  40. var aa = "";
  41. if(getValue) {
  42. var endValue = ((getValue.replace(/<(.+?)>/gi, "&lt;$1&gt;")).replace(/ /gi, "&nbsp;")).replace(/\n/gi, "|");
  43. var cc = endValue.split("|");
  44. for(var i = 0; i < cc.length; i++) {
  45. aa += cc[i] + '<br/>'
  46. }
  47. }
  48. return aa;
  49. }
  50. /*处理资源html代码*/
  51. function resourceHtml($da) {
  52. $("#resourceName").text($da.resourceName); //名字
  53. $("#application").text($da.supportedServices); //应用用途
  54. if($da.orgName) { //所属机构
  55. $("#organizationName").text($da.orgName).parents("li").show();
  56. }
  57. $("#nameS").text($da.editProfessor.name);
  58. if($da.editProfessor.title) {
  59. $("#titleOffice").text($da.editProfessor.title);
  60. } else {
  61. if($da.editProfessor.office) {
  62. $("#titleOffice").text($da.editProfessor.office);
  63. }
  64. }
  65. if($da.editProfessor.orgName) {
  66. $("#orgType").text($da.editProfessor.orgName);
  67. }
  68. professorId = $da.editProfessor.id;
  69. console.log(professorId);
  70. console.log(userid);
  71. if(userid!=professorId) {
  72. ifCollection(professorId,1)
  73. $(".goSpan").show();
  74. }
  75. var professorFlag = autho($da.editProfessor.authType, $da.editProfessor.orgAuth, $da.editProfessor.authStatus);
  76. $("#authFlag").addClass(professorFlag.sty).attr("title", professorFlag.title);
  77. if($da.editProfessor.hasHeadImage == 1) {
  78. $("#headImg").css("background-image", 'url(/images/head/' + $da.editProfessor.id + '_l.jpg)');
  79. }
  80. if($da.spec) { //厂商型号
  81. $("#modelNumber").text($da.spec).parents("li").show();
  82. }
  83. if($da.parameter) { //性能参数
  84. $("#performancePa").html(outHTML($da.parameter)).parents("li").show();
  85. }
  86. if($da.cooperationNotes) { //合作备注
  87. $("#remarkContent").html(outHTML($da.cooperationNotes)).parents("li").show();
  88. }
  89. if($da.subject) {
  90. var oSub = $da.subject.split(",");
  91. interestingResources(oSub);
  92. var oSt = "";
  93. for(var i = 0; i < oSub.length; i++) {
  94. oSt += '<li><p class="h2Font">' + oSub[i] + '</p></li>'
  95. }
  96. $(".tagList").html(oSt);
  97. }else {
  98. $(".aboutTit:contains('您可能感兴趣的资源')").parent().hide();
  99. }
  100. if($da.descp) { //编辑器
  101. $("#descp").html($da.descp).parents("li").show();
  102. }
  103. var weibotitle = $da.resourceName;
  104. var weibourl =window.location.href;
  105. //return;
  106. if($da.images.length) {
  107. var weibopic ="http://"+window.location.host+"/data/resource/" + $da.images[0].imageSrc;
  108. $("#firstFigure").attr({
  109. "src": "/data/resource/" + $da.images[0].imageSrc,
  110. "rel": "/data/resource/" + $da.images[0].imageSrc
  111. }).parent().attr("href", "/data/resource/" + $da.images[0].imageSrc);
  112. var arr = "";
  113. for(var i = 0; i < $da.images.length; i++) {
  114. if($da.images[i] == $da.images[0]) {
  115. var oString = '<li class="tb-selected">' +
  116. '<div class="tb-pic tb-s66">' +
  117. '<a href="javascript:void(0);">' +
  118. '<img src="/data/resource/' + $da.images[i].imageSrc + '"/>' +
  119. '</a>' +
  120. '</div>' +
  121. '</li>'
  122. } else {
  123. var oString = '<li >' +
  124. '<div class="tb-pic tb-s66">' +
  125. '<a href="javascript:void(0);">' +
  126. '<img src="/data/resource/' + $da.images[i].imageSrc + '"/>' +
  127. '</a>' +
  128. '</div>' +
  129. '</li>'
  130. }
  131. arr += oString;
  132. }
  133. $("#thumblist").html(arr);
  134. }else{
  135. var weibopic ="http://"+window.location.host+"../images/default-resource.jpg";
  136. $("#firstFigure").attr({"src":'../images/default-resource.jpg',"rel":'../images/default-resource.jpg'});
  137. }
  138. $("#weibo").attr("href","http://service.weibo.com/share/share.php?appkey=3677230589&title="+weibotitle+"&url="+weibourl+"&pic="+weibopic+"&ralateUid=6242830109&searchPic=false&style=simple");
  139. }
  140. /*点击名字及头像跳转个人浏览页面*/
  141. $("#nameS,#headImg").click(function() {
  142. location.href = "information-brow.html?professorId=" + professorId;
  143. })
  144. /*资源里面相关文章*/
  145. function relatedArticles() {
  146. $.ajax({
  147. "url": "/ajax/resource/articles",
  148. "type": "GET",
  149. "success": function(data) {
  150. console.log(data);
  151. if(data.success) {
  152. if(data.data.length==0) {
  153. $("#oArticle").parent().hide();
  154. $(".aboutTit:contains('相关文章')").hide();
  155. return;
  156. }
  157. relatedArticlesHtml(data.data);
  158. }
  159. },
  160. "data": {
  161. "resourceId": resourceId,
  162. "rows": 5
  163. },
  164. dataType: "json",
  165. 'error': function() {
  166. $.MsgBox.Alert('提示', '服务器连接超时!');
  167. }
  168. });
  169. }
  170. relatedArticles();
  171. /*资源相关文章html*/
  172. function relatedArticlesHtml($html) {
  173. for(var i = 0; i < $html.length; i++) {
  174. (function(n) {
  175. $.ajax({
  176. "url": "/ajax/professor/baseInfo/" + $html[i].article.professorId,
  177. "type": "GET",
  178. "success": function(data) {
  179. if(data.success) {
  180. var stl = autho(data.data.authType, data.data.orgAuth, data.data.authStatus);
  181. var str = ""
  182. str += '<li data-id="'+$html[n].article.articleId+'">'
  183. if($html[n].article.articleImg) {
  184. str += '<div class="madiaHead artHead" style="background-image: url(/data/article/' + $html[n].article.articleImg + ')"></div>'
  185. } else {
  186. str += '<div class="madiaHead artHead"></div>'
  187. }
  188. str += '<div class="madiaInfo" style="margin-top:18px;padding-bottom:8px">'
  189. str += '<p class="h1Font ellipsisSty">' + $html[n].article.articleTitle + '</p>'
  190. str += '<p><span class="h1Font">' + data.data.name + '</span><em class="authiconNew ' + stl.sty + '" title="' + stl.title + '"></em></p>'
  191. str += '</div></li>'
  192. $("#oArticle").append(str);
  193. }
  194. },
  195. 'dataType': "json",
  196. 'error': function() {
  197. $.MsgBox.Alert('提示', '服务器连接超时!');
  198. }
  199. });
  200. })(i);
  201. }
  202. }
  203. /*文章跳转*/
  204. $("#oArticle").on("click","li",function(){
  205. location.href="articalShow.html?articleId="+$(this).attr("data-id");
  206. })
  207. /*感兴趣的资源*/
  208. function interestingResources(arry) {
  209. $.ajax({
  210. "url": "/ajax/resource/ralateRes",
  211. "type": "GET",
  212. "success": function(data) {
  213. console.log(data);
  214. if(data.success) {
  215. if(data.data.length==0) {
  216. $(".aboutTit:contains('您可能感兴趣的资源')").parent().hide();
  217. return;
  218. }
  219. interestingResourcesHtml(data.data);
  220. }
  221. },
  222. "data": {
  223. "keys": arry,
  224. "resourceId": resourceId,
  225. "professorId":professorId
  226. },
  227. "traditional":true,
  228. dataType: "json",
  229. 'error': function() {
  230. $.MsgBox.Alert('提示', '服务器连接超时!');
  231. }
  232. });
  233. }
  234. /*感兴趣资源的html*/
  235. function interestingResourcesHtml($respond) {
  236. for(var i=0;i<$respond.length;i++) {
  237. var stl = autho($respond[i].editProfessor.authType, $respond[i].editProfessor.orgAuth, $respond[i].editProfessor.authStatus);
  238. var oStr='';
  239. if($respond[i].images.length) {
  240. oStr+='<li data-id="'+$respond[i].resourceId+'"><div class="madiaHead resouseHead"style="background-image: url(/data/resource/'+$respond[i].images[0].imageSrc+')"></div>'
  241. }else {
  242. oStr+='<li data-id="'+$respond[i].resourceId+'"><div class="madiaHead resouseHead"></div>'
  243. }
  244. oStr+='<div class="madiaInfo">'
  245. oStr+='<p class="h1Font">'+$respond[i].resourceName+'</p>'
  246. oStr += '<p><span class="h1Font">' + $respond[i].editProfessor.name + '</span><em class="authiconNew ' + stl.sty + '" title="' + stl.title + '"></em></p>'
  247. oStr+='<p class="h2Font ellipsisSty">用途:<span>'+$respond[i].supportedServices+'</span></p>'
  248. oStr+='</div></li>'
  249. $("#resourceList").append(oStr);
  250. }
  251. }
  252. /*点击资源列表*/
  253. $("#resourceList").on("click","li",function(){
  254. location.href="resourceShow.html?resourceId="+$(this).attr("data-id");
  255. })
  256. /*点击咨询*/
  257. $("#consultin").on("click", function() {
  258. clickResouceConsultHandler();
  259. });
  260. /*咨询函数*/
  261. function clickResouceConsultHandler() {
  262. if(userid && userid != "null" && userid != null) {
  263. ConsultApply();
  264. concultProInfo(professorId); //专家信息common.js中
  265. //默认选中资源咨询和标题
  266. for(var i = 0; i < $("ul.menucon").children().length; i++) {
  267. $("ul.menucon").children().eq(i).removeClass("clicknow");
  268. $("ul.menucon").children().eq(1).addClass("clicknow");
  269. }
  270. var consultTitleVal = $(".h2Font").text();
  271. $("#consultTitle").val("关于" + consultTitleVal + "的咨询");
  272. //点击的发送
  273. $("#sendConsultBtn").click(function() {
  274. sendConsultHandler(professorId); //common.js中
  275. });
  276. } else {
  277. $.MsgBox.Alert("消息提醒", "请先登录再进行咨询");
  278. $("#mb_btn_ok").val("去登录");
  279. var aele = document.createElement('a');
  280. $("#mb_btnbox").append(aele);
  281. $("#mb_btnbox a").css({
  282. 'display': "block",
  283. 'width': '100%',
  284. 'height': '40px',
  285. 'position': 'absolute',
  286. 'bottom': '-6px',
  287. 'left': '0'
  288. });
  289. aele.setAttribute('href', '../login.html');
  290. }
  291. };
  292. //点击专家关注
  293. $('.attenSpan').click(function(){
  294. if (userid && userid != "null" && userid != null) {
  295. if($(this).is('.attenSpanyes')){
  296. cancelCollectionExpert(professorId,1)
  297. }else{
  298. collectionExpert(professorId,1);
  299. }
  300. }else{
  301. $.MsgBox.Alert('提示',"请先登录再进行关注");
  302. $("#mb_btn_ok").val("去登录");
  303. var aele = document.createElement('a');
  304. $("#mb_btnbox").append(aele);
  305. $("#mb_btnbox a").css({
  306. 'display': "block",
  307. 'width': '100%',
  308. 'height': '40px',
  309. 'position': 'absolute',
  310. 'bottom': '-6px',
  311. 'left': '0'
  312. });
  313. aele.setAttribute('href', '../login.html');
  314. }
  315. })
  316. //点击资源收藏
  317. $('#attention em').click(function(){
  318. if (userid && userid != "null" && userid != null) {
  319. if($(this).is('.icon-collected')){
  320. cancelCollectionExpert(resourceId,2)
  321. }else{
  322. collectionExpert(resourceId,2);
  323. }
  324. }else{
  325. $.MsgBox.Alert('提示',"请先登录再进行收藏");
  326. $("#mb_btn_ok").val("去登录");
  327. var aele = document.createElement('a');
  328. $("#mb_btnbox").append(aele);
  329. $("#mb_btnbox a").css({
  330. 'display': "block",
  331. 'width': '100%',
  332. 'height': '40px',
  333. 'position': 'absolute',
  334. 'bottom': '-6px',
  335. 'left': '0'
  336. });
  337. aele.setAttribute('href', '../login.html');
  338. }
  339. })
  340. /*判断是非关注专家*/
  341. function ifCollection(getid,num) {
  342. var data = {"professorId": userid,"watchObject": getid}
  343. //alert(JSON.stringify(data))
  344. $.ajax({
  345. url:"/ajax/watch/hasWatch",
  346. data:data,
  347. dataType: 'json', //数据格式类型
  348. type: 'get', //http请求类型
  349. timeout: 10000,
  350. async: true,
  351. success: function(data) {
  352. if(num==1){
  353. if(data.success && data.data != null) {
  354. $('.attenSpan').addClass("attenSpanyes");
  355. $('.attenSpan').text('已关注');
  356. zjreturnId = data.data.watchObject;
  357. } else {
  358. $('.attenSpan').removeClass("attenSpanyes");
  359. $('.attenSpan').text('关注');
  360. }
  361. }
  362. if(num==2){
  363. if(data.success && data.data != null) {
  364. $('#attention em').addClass("icon-collected").removeClass("icon-collect");
  365. wzreturnId = data.data.watchObject;
  366. } else {
  367. $('#attention em').removeClass("icon-collected").addClass("icon-collect");
  368. }
  369. }
  370. },
  371. error: function() {
  372. $.MsgBox.Alert('提示',"服务器链接超时");
  373. }
  374. });
  375. }
  376. /*关注专家*/
  377. function collectionExpert(watchObject,num) {
  378. if(num==1){
  379. var data = {"professorId": userid,"watchObject": watchObject,"watchType": 1}
  380. }else{
  381. var data = {"professorId": userid,"watchObject": watchObject,"watchType": 3}
  382. }
  383. $.ajax({
  384. url:"/ajax/watch",
  385. data:data,
  386. dataType: 'json', //数据格式类型
  387. type: 'POST', //http请求类型
  388. timeout: 10000,
  389. async: false,
  390. success: function(data) {
  391. if(num==1){
  392. if(data.success) {
  393. $('.attenSpan').addClass("attenSpanyes");
  394. $('.attenSpan').text('已关注');
  395. zjreturnId = data.data.watchObject;
  396. }
  397. }
  398. if(num==2){
  399. if(data.success) {
  400. $('#attention em').addClass("icon-collected").removeClass("icon-collect");
  401. wzreturnId = data.data.watchObject;
  402. }
  403. }
  404. },
  405. error: function() {
  406. $.MsgBox.Alert('提示',"服务器链接超时");
  407. }
  408. });
  409. }
  410. /*取消收藏专家*/
  411. function cancelCollectionExpert(watchObject,num) {
  412. $.ajax({
  413. url:"/ajax/watch/delete",
  414. data: {
  415. professorId: userid,
  416. watchObject: watchObject
  417. },
  418. dataType: 'json', //数据格式类型
  419. type: 'post', //http请求类型
  420. timeout: 10000,
  421. async: true,
  422. success: function(data) {
  423. console.log(data.success)
  424. if(num==1){
  425. if(data.success) {
  426. $('.attenSpan').removeClass("attenSpanyes");
  427. $('.attenSpan').text('关注');
  428. }
  429. }
  430. if(num==2){
  431. if(data.success) {
  432. $('#attention em').removeClass("icon-collected").addClass("icon-collect");
  433. }
  434. }
  435. },
  436. error: function(data) {
  437. $.MsgBox.Alert('提示',"服务器链接超时");
  438. }
  439. });
  440. }
  441. //资源浏览量
  442. function pageViewsVal(){
  443. $.ajax({
  444. "url" : "/ajax/resource/pageViews",
  445. "type" : "POST" ,
  446. "dataType" : "json",
  447. "data" :{"resourceId":resourceId},
  448. "success" : function(data) {
  449. console.log(data);
  450. if (data.success){
  451. }
  452. },
  453. "error":function(){
  454. $.MsgBox.Alert('提示','链接服务器超时')
  455. }
  456. });
  457. }
  458. pageViewsVal();
  459. })