article-info.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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. //修改图片路径,处理图片服务防盗链的问题
  28. var domain = server+"/image/getRemoteByURL?imageURL=";
  29. var strRegex = /((https|http):\/\/)/g;
  30. content = content.replace(strRegex , domain + "$1");
  31. var reg=/group1\//g;
  32. content = content.replace(reg,imgUrlDomain+ 'group1/');
  33. var html = template("article_tmpl", { it: res.data, content: content, showHandleBar: showHandleBar});
  34. $("#xiangqing-content").html(html);
  35. //禁止超链接执行默认行为
  36. $("#xiangqing-content a").attr("onclick","return false");
  37. } else {
  38. queryFailed(res);
  39. }
  40. plus.nativeUI.closeWaiting();
  41. });
  42. }
  43. function queryFailed(res) {
  44. if(res.msg) {
  45. plus.nativeUI.toast(res.msg);
  46. } else {
  47. plus.nativeUI.toast("加载文章失败!");
  48. }
  49. }
  50. /*
  51. * 收藏文章
  52. */
  53. function collectionArticle(code,$this){
  54. plus.nativeUI.showWaiting();
  55. var params = {};
  56. params.articleId = code;
  57. params.userType = 1; //1医生,2居民
  58. sendPost("/third/jkEdu/Article/saveArticleCollection",params,function(res){
  59. plus.nativeUI.closeWaiting();
  60. if(res.msg){
  61. plus.nativeUI.toast(res.msg);
  62. }else{
  63. plus.nativeUI.toast("收藏失败!");
  64. }
  65. },function(res){
  66. plus.nativeUI.closeWaiting();
  67. if(res.status==200){
  68. $this.attr("data-status", 1);
  69. $this.find("img").attr("src", "../images/shoucang_pre.png");
  70. var span = $this.find("span");
  71. span.html('已收藏');
  72. plus.nativeUI.toast("收藏成功");
  73. }else{
  74. if(res.msg){
  75. plus.nativeUI.toast(res.msg);
  76. }else{
  77. plus.nativeUI.toast("收藏失败!");
  78. }
  79. }
  80. })
  81. }
  82. /*
  83. * 取消收藏文章
  84. */
  85. function unCollectionArticle(code,$this){
  86. plus.nativeUI.showWaiting();
  87. var params = {};
  88. params.articleId=code;
  89. params.userType = 1; //1医生,2居民
  90. sendPost("/third/jkEdu/Article/cancelArticleCollection",params,function(res){
  91. plus.nativeUI.closeWaiting();
  92. if(res.msg){
  93. plus.nativeUI.toast(res.msg);
  94. }else{
  95. plus.nativeUI.toast("取消收藏失败!");
  96. }
  97. },function(res){
  98. plus.nativeUI.closeWaiting();
  99. if(res.status==200){
  100. $this.attr("data-status", 0);
  101. $this.find("img").attr("src", "../images/shoucang_button.png");
  102. var span = $this.find("span");
  103. span.html('收藏');
  104. plus.nativeUI.toast("取消收藏成功");
  105. }else{
  106. if(res.msg){
  107. plus.nativeUI.toast(res.msg);
  108. }else{
  109. plus.nativeUI.toast("取消收藏失败!");
  110. }
  111. }
  112. })
  113. }
  114. //弹框提示是否发送给居民
  115. function showDialog(article,title,patientName) {
  116. dialog({
  117. 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>',
  118. content: '<div><div class="c-f16 c-323232 c-t-left mb10">《'+title+'》</div><input id="messageInput" class="c-f14 pl10" placeholder="给居民留言..."/></div>',
  119. okValue: '立即发送',
  120. cancelValue: '我再看看',
  121. cancel: function () {
  122. return;
  123. },
  124. ok: function() {
  125. send(article);
  126. }
  127. }).showModal();
  128. }
  129. //发送文章给患者
  130. function send(article){
  131. var url = "/doctor/jkEdu/article/doctorSendArticleToPatients",
  132. params = {
  133. articleId: article,
  134. patient: patient,
  135. leaveWords: $.trim($('#messageInput').val())
  136. };
  137. if(pCodes){
  138. params.patient = pCodes.join(",");
  139. }
  140. var docInfo = JSON.parse(plus.storage.getItem('docInfo'));
  141. params.currentUserRole = docInfo.hospital;
  142. params.currentUserRoleLevel = 4;
  143. plus.nativeUI.showWaiting();
  144. sendPost(url, params, null, function(res){
  145. if(res.status == 10000){
  146. mui.toast("发送成功!");
  147. if(referrer == "manbing"){
  148. var self = plus.webview.currentWebview(),
  149. selfId = self.id;
  150. backToManbingPage(self, selfId);
  151. }else if(referrer){
  152. var self = plus.webview.currentWebview();
  153. backToPage(self, referrer);
  154. }
  155. }else{
  156. if(res.msg){
  157. mui.toast(res.msg);
  158. }else{
  159. mui.toast("发送失败!");
  160. }
  161. }
  162. plus.nativeUI.closeWaiting();
  163. });
  164. }
  165. function bindEvents() {
  166. $("#xiangqing-content").on('tap','.collection', function(){
  167. var $this = $(this);
  168. var status = $this.attr("data-status");
  169. var code = $this.attr("data-code");
  170. if(status == 0){
  171. collectionArticle(code,$this);
  172. }else{
  173. unCollectionArticle(code,$this);
  174. }
  175. }).on('tap','.share', function(){
  176. var $this = $(this);
  177. var code = $this.attr("data-code");
  178. var title = $this.attr("data-title");
  179. if(!patient){
  180. if(pCodes){
  181. dialog({
  182. 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>',
  183. content: '<div><div class="c-f16 c-323232 c-t-left mb10">《'+title+'》</div><input id="messageInput" class="c-f14 pl10" placeholder="给居民留言..."/></div>',
  184. okValue: '立即发送',
  185. cancelValue: '我再看看',
  186. cancel: function () {
  187. return;
  188. },
  189. ok: function() {
  190. send(code);
  191. }
  192. }).showModal();
  193. return false;
  194. }else{
  195. openWebview("xuanzejumin_more.html", {
  196. article: code,
  197. articleTitle: title,
  198. origin: 'jiaoyu'
  199. });
  200. }
  201. }else{
  202. showDialog(code,title,patientName);
  203. }
  204. });
  205. //为文章内的超链接监听点击事件
  206. $("#xiangqing-content").on('click', "a", function(){
  207. var $this = $(this),
  208. url = $this.attr("href");
  209. mui.openWindow({
  210. id: "browser-page",
  211. url: "../../browser/html/browser.html",
  212. extras: {
  213. url: url
  214. }
  215. })
  216. })
  217. template.helper("setPhoto", function(p) {
  218. return getImgUrl(p);
  219. });
  220. template.helper("formatDate", function(str){
  221. if(str){
  222. return str.substr(0,19)
  223. }else{
  224. return "";
  225. }
  226. });
  227. window.addEventListener("refresh", function refresh(e) {
  228. initPage();
  229. });
  230. }
  231. function backToManbingPage(wv, selfId){
  232. var targetId = "zhongdiangenzong";
  233. if(wv.id == targetId){
  234. setTimeout(function(){
  235. plus.webview.getWebviewById(selfId).close();
  236. }, 300);
  237. }else{
  238. var opener = wv.opener();
  239. if(wv.id != selfId){
  240. wv.close();
  241. }
  242. backToManbingPage(opener, selfId);
  243. }
  244. }
  245. var closeList = [];
  246. function backToPage(wv, wvId){
  247. if(wv.id == wvId){
  248. var self = plus.webview.currentWebview();
  249. if(wvId == "p2dzixun"){
  250. setTimeout(function(){
  251. mui.fire(wv, "update");
  252. wv.show();
  253. for(i=0; i<closeList.length; i++){
  254. closeList[i].close();
  255. }
  256. closeList = [];
  257. self.close();
  258. },1000);
  259. }else{
  260. mui.fire(wv, "reload");
  261. setTimeout(function(){
  262. wv.show();
  263. for(i=0; i<closeList.length; i++){
  264. closeList[i].close();
  265. }
  266. closeList = [];
  267. self.close();
  268. }, 500)
  269. }
  270. }else{
  271. var opener = wv.opener();
  272. if(opener.id != wvId){
  273. closeList.push(opener);
  274. }
  275. backToPage(opener, wvId);
  276. }
  277. }