articleDetail.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. var isEdit;
  2. var articleId;
  3. mui.plusReady(function() {
  4. var self = plus.webview.currentWebview();
  5. isEdit = self.isEdit;
  6. articleId = self.articleId;
  7. getArticleDetail();
  8. bindEvents();
  9. })
  10. //获取文章详情
  11. function getArticleDetail() {
  12. sendPost("/third/jkEdu/Article/getArticalById",{articleId:articleId, userType: 1}, null, function(res){
  13. if(res.status == 200){
  14. if(res.data.isAuthentication == 0){
  15. $("#isEdit").show();
  16. }else{
  17. $("#isEdit").hide();
  18. }
  19. var content = res.data.articleContent;
  20. var reg=/group1\//g;
  21. content = content.replace(reg,imgUrlDomain+ 'group1/');
  22. var html=template("articleDetail_tmpl", {it: res.data, content: content});
  23. $("#mainContent").html(html);
  24. //禁止超链接执行默认行为
  25. $("#mainContent a").attr("onclick","return false");
  26. }else{
  27. queryFailed(res);
  28. }
  29. },'get')
  30. }
  31. function queryFailed(res){
  32. if(res.msg){
  33. plus.nativeUI.toast(res.msg);
  34. }else{
  35. plus.nativeUI.toast("加载文章失败!");
  36. }
  37. }
  38. function bindEvents(){
  39. $("#main").on("click",".collection",function(){
  40. var status = $(this).attr("data-status");
  41. if(status==0){
  42. collectionArticle($(this))
  43. }else{
  44. unCollectionArticle($(this))
  45. }
  46. return;
  47. });
  48. $("#main").on("click",".share",function(){
  49. var $this = $(this);
  50. var articleId = $this.attr("data-code");
  51. var articleTitle = $this.attr("data-title");
  52. mui.openWindow({
  53. id: "xuanzejumin_more",
  54. url: "xuanzejumin_more.html",
  55. extras: {
  56. articleId:articleId,origin:'jiaoyu',articleTitle:articleTitle
  57. }
  58. })
  59. });
  60. $("#isEdit").click(function() {
  61. mui.openWindow({
  62. id: "article-edit",
  63. url: "article-edit.html",
  64. extras: {
  65. articleId:articleId
  66. }
  67. })
  68. });
  69. //为文章内的超链接监听点击事件
  70. $("#mainContent").on('click', "a", function(){
  71. var $this = $(this),
  72. url = $this.attr("href");
  73. mui.openWindow({
  74. id: "browser-page",
  75. url: "../../browser/html/browser.html",
  76. extras: {
  77. url: url
  78. }
  79. })
  80. })
  81. }
  82. function collectionArticle($this){
  83. plus.nativeUI.showWaiting();
  84. var params = {};
  85. params.articleId=articleId;//文章id
  86. params.userType=1;//1是医生 2是居民
  87. sendPost("/third/jkEdu/Article/saveArticleCollection",params,function(res){
  88. plus.nativeUI.closeWaiting();
  89. if(res.msg){
  90. plus.nativeUI.toast(res.msg);
  91. }else{
  92. plus.nativeUI.toast("收藏失败!");
  93. }
  94. },function(res){
  95. plus.nativeUI.closeWaiting();
  96. if(res.status==200){
  97. $this.attr("data-status", 1);
  98. $this.find("img").attr("src", "../images/shoucang_pre.png");
  99. var span = $this.find("span");
  100. span.html("已收藏");
  101. plus.nativeUI.toast("收藏成功");
  102. resPage();
  103. }else{
  104. if(res.msg){
  105. plus.nativeUI.toast(res.msg);
  106. }else{
  107. plus.nativeUI.toast("收藏失败!");
  108. }
  109. }
  110. })
  111. }
  112. function unCollectionArticle($this){
  113. plus.nativeUI.showWaiting();
  114. var params = {};
  115. params.articleId=articleId;//文章id
  116. params.userType=1;//1是医生 2是居民
  117. sendPost("/third/jkEdu/Article/cancelArticleCollection",params,
  118. function(res){
  119. plus.nativeUI.closeWaiting();
  120. if(res.msg){
  121. plus.nativeUI.toast(res.msg);
  122. }else{
  123. plus.nativeUI.toast("取消收藏失败!");
  124. }
  125. },
  126. function(res){
  127. plus.nativeUI.closeWaiting();
  128. if(res.status==200){
  129. $this.attr("data-status", 0);
  130. $this.find("img").attr("src", "../images/shoucang_button.png");
  131. var span = $this.find("span");
  132. span.html("收藏");
  133. plus.nativeUI.toast("取消收藏成功");
  134. resPage();
  135. }else{
  136. if(res.msg){
  137. plus.nativeUI.toast(res.msg);
  138. }else{
  139. plus.nativeUI.toast("取消收藏失败!");
  140. }
  141. }
  142. })
  143. }
  144. function resPage(){
  145. var view = plus.webview.getWebviewById("jiankangjiaoyu");
  146. if(view){
  147. mui.fire(view,"refresh");
  148. }
  149. var my_store = plus.webview.getWebviewById("my_store");
  150. if(my_store){
  151. mui.fire(my_store,"refresh");
  152. }
  153. }
  154. template.helper('setTimer',function(o){
  155. return o.substr(0,19)
  156. });