article-info.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. var articleId = null;
  2. // 是否显示底部“收藏、分享”按钮
  3. var showHandleBar = true;
  4. var patient = null;
  5. var patientName = "";
  6. var pCodes = [],
  7. referrer;
  8. mui.init();
  9. mui.plusReady(function() {
  10. self = plus.webview.currentWebview();
  11. articleId = self.articleId;
  12. patient = self.patient;
  13. patientName = self.patientName;
  14. pCodes = self.pCodes;
  15. referrer = self.referrer;
  16. showHandleBar = self.showHandleBar;
  17. initPage();
  18. bindEvents();
  19. })
  20. function initPage() {
  21. var url = "/third/jkEdu/Article/getArticalById",
  22. params = { articleId: articleId, userType: 1 };
  23. plus.nativeUI.showWaiting();
  24. sendGet(url, params, null, function(res) {
  25. if(res.status == 200) {
  26. var content = res.data.articleContent;
  27. var reg=/group1\//g;
  28. content = content.replace(reg,imgUrlDomain+ 'group1/');
  29. var html = template("article_tmpl", { it: res.data, content: content, showHandleBar: showHandleBar});
  30. $("#xiangqing-content").html(html);
  31. //禁止超链接执行默认行为
  32. $("#xiangqing-content a").attr("onclick","return false");
  33. } else {
  34. queryFailed(res);
  35. }
  36. plus.nativeUI.closeWaiting();
  37. });
  38. }
  39. function queryFailed(res) {
  40. if(res.msg) {
  41. plus.nativeUI.toast(res.msg);
  42. } else {
  43. plus.nativeUI.toast("加载文章失败!");
  44. }
  45. }
  46. /*
  47. * 收藏文章
  48. */
  49. function collectionArticle(code,$this){
  50. plus.nativeUI.showWaiting();
  51. var params = {};
  52. params.articleId = code;
  53. params.userType = 1; //1医生,2居民
  54. sendPost("/third/jkEdu/Article/saveArticleCollection",params,function(res){
  55. plus.nativeUI.closeWaiting();
  56. if(res.msg){
  57. plus.nativeUI.toast(res.msg);
  58. }else{
  59. plus.nativeUI.toast("收藏失败!");
  60. }
  61. },function(res){
  62. plus.nativeUI.closeWaiting();
  63. if(res.status==200){
  64. $this.attr("data-status", 1);
  65. $this.find("img").attr("src", "../images/shoucang_pre.png");
  66. var span = $this.find("span");
  67. span.html('已收藏');
  68. plus.nativeUI.toast("收藏成功");
  69. }else{
  70. if(res.msg){
  71. plus.nativeUI.toast(res.msg);
  72. }else{
  73. plus.nativeUI.toast("收藏失败!");
  74. }
  75. }
  76. })
  77. }
  78. /*
  79. * 取消收藏文章
  80. */
  81. function unCollectionArticle(code,$this){
  82. plus.nativeUI.showWaiting();
  83. var params = {};
  84. params.articleId=code;
  85. params.userType = 1; //1医生,2居民
  86. sendPost("/third/jkEdu/Article/cancelArticleCollection",params,function(res){
  87. plus.nativeUI.closeWaiting();
  88. if(res.msg){
  89. plus.nativeUI.toast(res.msg);
  90. }else{
  91. plus.nativeUI.toast("取消收藏失败!");
  92. }
  93. },function(res){
  94. plus.nativeUI.closeWaiting();
  95. if(res.status==200){
  96. $this.attr("data-status", 0);
  97. $this.find("img").attr("src", "../images/shoucang_button.png");
  98. var span = $this.find("span");
  99. span.html('收藏');
  100. plus.nativeUI.toast("取消收藏成功");
  101. }else{
  102. if(res.msg){
  103. plus.nativeUI.toast(res.msg);
  104. }else{
  105. plus.nativeUI.toast("取消收藏失败!");
  106. }
  107. }
  108. })
  109. }
  110. //弹框提示是否发送给居民
  111. function showDialog(article,title,patientName) {
  112. dialog({
  113. title: '<div><div class="c-f18 c-17b3ec c-t-left">发送给</div><div class="mt5 c-f14 c-t-left c-909090">'+patientName+'</div></div>',
  114. content: '<div><div class="c-f16 c-323232 c-t-left mb10">《'+title+'》</div><input id="messageInput" class="c-f14 pl10" placeholder="给居民留言..."/></div>',
  115. okValue: '立即发送',
  116. cancelValue: '我再看看',
  117. cancel: function () {
  118. return;
  119. },
  120. ok: function() {
  121. send(article);
  122. }
  123. }).showModal();
  124. }
  125. //发送文章给患者
  126. function send(article){
  127. var url = "/doctor/jkEdu/article/doctorSendArticleToPatients",
  128. params = {
  129. articleId: article,
  130. patient: patient,
  131. leaveWords: $.trim($('#messageInput').val())
  132. };
  133. if(pCodes){
  134. params.patient = pCodes.join(",");
  135. }
  136. var docInfo = JSON.parse(plus.storage.getItem('docInfo'));
  137. params.currentUserRole = docInfo.hospital;
  138. params.currentUserRoleLevel = 4;
  139. plus.nativeUI.showWaiting();
  140. sendPost(url, params, null, function(res){
  141. if(res.status == 10000){
  142. mui.toast("发送成功!");
  143. if(referrer == "manbing"){
  144. var self = plus.webview.currentWebview(),
  145. selfId = self.id;
  146. backToManbingPage(self, selfId);
  147. }
  148. }else{
  149. if(res.msg){
  150. mui.toast(res.msg);
  151. }else{
  152. mui.toast("发送失败!");
  153. }
  154. }
  155. plus.nativeUI.closeWaiting();
  156. });
  157. }
  158. function bindEvents() {
  159. $("#xiangqing-content").on('tap','.collection', function(){
  160. var $this = $(this);
  161. var status = $this.attr("data-status");
  162. var code = $this.attr("data-code");
  163. if(status == 0){
  164. collectionArticle(code,$this);
  165. }else{
  166. unCollectionArticle(code,$this);
  167. }
  168. }).on('tap','.share', function(){
  169. var $this = $(this);
  170. var code = $this.attr("data-code");
  171. var title = $this.attr("data-title");
  172. if(!patient){
  173. if(pCodes){
  174. dialog({
  175. title: '<div><div class="c-f18 c-17b3ec c-t-left">发送给</div><div class="mt5 c-f14 c-t-left c-909090">'+pCodes.length+'人</div></div>',
  176. content: '<div><div class="c-f16 c-323232 c-t-left mb10">《'+title+'》</div><input id="messageInput" class="c-f14 pl10" placeholder="给居民留言..."/></div>',
  177. okValue: '立即发送',
  178. cancelValue: '我再看看',
  179. cancel: function () {
  180. return;
  181. },
  182. ok: function() {
  183. send(code);
  184. }
  185. }).showModal();
  186. return false;
  187. }else{
  188. openWebview("xuanzejumin_more.html", {
  189. article: code,
  190. articleTitle: title,
  191. origin: 'jiaoyu'
  192. });
  193. }
  194. }else{
  195. showDialog(code,title,patientName);
  196. }
  197. });
  198. //为文章内的超链接监听点击事件
  199. $("#xiangqing-content").on('click', "a", function(){
  200. var $this = $(this),
  201. url = $this.attr("href");
  202. mui.openWindow({
  203. id: "browser-page",
  204. url: "../../browser/html/browser.html",
  205. extras: {
  206. url: url
  207. }
  208. })
  209. })
  210. template.helper("setPhoto", function(p) {
  211. return getImgUrl(p);
  212. });
  213. template.helper("formatDate", function(str){
  214. if(str){
  215. return str.substr(0,19)
  216. }else{
  217. return "";
  218. }
  219. });
  220. window.addEventListener("refresh", function refresh(e) {
  221. initPage();
  222. });
  223. }
  224. function backToManbingPage(wv, selfId){
  225. var targetId = "zhongdiangenzong";
  226. if(wv.id == targetId){
  227. setTimeout(function(){
  228. plus.webview.getWebviewById(selfId).close();
  229. }, 300);
  230. }else{
  231. var opener = wv.opener();
  232. if(wv.id != selfId){
  233. wv.close();
  234. }
  235. backToManbingPage(opener, selfId);
  236. }
  237. }