article-info.js 8.0 KB

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