my-store2.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. mui.init();
  2. var page = 0,
  3. pageSize = 10,
  4. patient,
  5. patientName,
  6. isAdmin,
  7. pCodes,
  8. referrer;
  9. var back = mui.back;
  10. mui.back = function(){
  11. var self = plus.webview.currentWebview(),
  12. opener = self.opener();
  13. if(opener){
  14. mui.fire(opener, 'reload');
  15. }
  16. back();
  17. }
  18. mui.plusReady(function(){
  19. var self = plus.webview.currentWebview();
  20. isAdmin = self.isAdmin;
  21. patient = self.patient;
  22. patientName = self.patientName;
  23. pCodes = self.pCodes;
  24. referrer = self.referrer;
  25. getList(true);
  26. initScroller();
  27. bindEvents();
  28. });
  29. function getList(isInit){
  30. if(isInit){
  31. page = 0;
  32. }
  33. var url = "/third/jkEdu/Article/getCollectionArticalList",
  34. params = {
  35. articleState: 1, // 1-正常,2-删除,3-草稿
  36. pageIndex: page,
  37. pageSize: pageSize,
  38. userType: 1 //1医生,2居民
  39. };
  40. if(patient){
  41. params.patient = patient;
  42. }
  43. sendGet(url, params, null, function(res){
  44. if(res.status == 200){
  45. if(isInit && res.data.length == 0){
  46. $("#articleList").hide();
  47. $(".no-result").show();
  48. }else{
  49. var html = template('li-tmp', {list : res.data});
  50. if(isInit){
  51. $("#articleList").empty().append(html);
  52. }else{
  53. $("#articleList").append(html);
  54. }
  55. if(res.data.length < pageSize){
  56. mui('.mui-scroll-wrapper').pullRefresh().endPullupToRefresh(true);
  57. }else{
  58. mui('.mui-scroll-wrapper').pullRefresh().endPullupToRefresh(false);
  59. page ++;
  60. }
  61. }
  62. }else{
  63. mui.toast(res.msg);
  64. }
  65. }, true);
  66. }
  67. /*
  68. * 取消收藏文章
  69. */
  70. function unCollectionArticle(code,$this){
  71. plus.nativeUI.showWaiting();
  72. var params = {};
  73. params.articleId=code;
  74. params.userType = 1; //1医生,2居民
  75. sendPost("/third/jkEdu/Article/cancelArticleCollection",params,function(res){
  76. plus.nativeUI.closeWaiting();
  77. if(res.msg){
  78. plus.nativeUI.toast(res.msg);
  79. }else{
  80. plus.nativeUI.toast("取消收藏失败!");
  81. }
  82. },function(res){
  83. plus.nativeUI.closeWaiting();
  84. if(res.status==200){
  85. var $li = $this.closest('.article-li');
  86. $li.remove();
  87. plus.nativeUI.toast("取消收藏成功");
  88. var $lis = $(".article-li"),
  89. len = $lis.length;
  90. if(len == 0){
  91. $("#articleList").hide();
  92. $(".no-result").show();
  93. }
  94. }else{
  95. if(res.msg){
  96. plus.nativeUI.toast(res.msg);
  97. }else{
  98. plus.nativeUI.toast("取消收藏失败!");
  99. }
  100. }
  101. })
  102. }
  103. //弹框提示是否发送给居民
  104. function showDialog(article,title,patientName) {
  105. dialog({
  106. 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>',
  107. content: '<div><div class="c-f16 c-323232 c-t-left mb10">《'+title+'》</div><input id="messageInput" class="c-f14 pl10" placeholder="给居民留言..."/></div>',
  108. okValue: '立即发送',
  109. cancelValue: '我再看看',
  110. cancel: function () {
  111. return;
  112. },
  113. ok: function() {
  114. send(article);
  115. }
  116. }).showModal();
  117. }
  118. //发送文章给患者
  119. function send(article){
  120. var url = "/doctor/jkEdu/article/doctorSendArticleToPatients",
  121. params = {
  122. articleId: article,
  123. patient: patient,
  124. leaveWords: $.trim($('#messageInput').val())
  125. };
  126. if(pCodes){
  127. params.patient = pCodes.join(",");
  128. }
  129. var docInfo = JSON.parse(plus.storage.getItem('docInfo'));
  130. params.currentUserRole = docInfo.hospital;
  131. params.currentUserRoleLevel = 4;
  132. plus.nativeUI.showWaiting();
  133. sendPost(url, params, null, function(res){
  134. if(res.status == 10000){
  135. mui.toast("发送成功!");
  136. var $this = $(".share[data-code="+article+"]");
  137. if(!pCodes){
  138. $this.after('<div class="sent-flag"><span class="c-fff c-f14 ml10">已发送</span></div>');
  139. }
  140. var num = $this.find(".send_count").text();
  141. $this.find(".send_count").text(parseInt(num)+1);
  142. if(referrer == "manbing"){
  143. var self = plus.webview.currentWebview(),
  144. selfId = self.id;
  145. backToManbingPage(self, selfId);
  146. }
  147. }else{
  148. if(res.msg){
  149. mui.toast(res.msg);
  150. }else{
  151. mui.toast("发送失败!");
  152. }
  153. }
  154. plus.nativeUI.closeWaiting();
  155. });
  156. }
  157. function bindEvents(){
  158. $("#articleList").on('tap', ".article-info", function(e){
  159. e.stopPropagation();
  160. var code = $(this).attr("data-article-code");
  161. var title = $(this).attr('data-title');
  162. if(isAdmin){
  163. openWebviewExtras("../../home/html/jianjiaotuisong-xiangqing.html",{articleId:code});
  164. }else{
  165. openWebview("article-info.html", {
  166. articleId:code,
  167. patient: patient,
  168. patientName: patientName,
  169. pCodes: pCodes,
  170. showHandleBar: true,
  171. referrer: referrer
  172. })
  173. }
  174. return false;
  175. }).on('tap','div.collect', function(e){
  176. e.stopPropagation();
  177. var $this = $(this);
  178. var code = $this.attr("data-code");
  179. unCollectionArticle(code,$this);
  180. }).on('tap','div.share', function(e){
  181. e.stopPropagation();
  182. var $this = $(this);
  183. var code = $this.attr("data-code");
  184. var title = $this.attr("data-title");
  185. if(isAdmin){
  186. openWebviewExtras("../../home/html/tuisong_duixiang.html",{articleId:code});
  187. }else{
  188. if(!patient){
  189. if(pCodes){
  190. dialog({
  191. 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>',
  192. content: '<div><div class="c-f16 c-323232 c-t-left mb10">《'+title+'》</div><input id="messageInput" class="c-f14 pl10" placeholder="给居民留言..."/></div>',
  193. okValue: '立即发送',
  194. cancelValue: '我再看看',
  195. cancel: function () {
  196. return;
  197. },
  198. ok: function() {
  199. send(code);
  200. }
  201. }).showModal();
  202. return false;
  203. }else{
  204. openWebview("xuanzejumin_more.html", {
  205. article: code,
  206. articleTitle: title,
  207. origin: 'jiaoyu'
  208. });
  209. }
  210. }else{
  211. showDialog(code,title,patientName);
  212. }
  213. }
  214. });
  215. template.helper("setContent", function(str){
  216. if(str){
  217. var reg=/<[^<>]+>/g;
  218. str = str.replace(reg, '');
  219. return str;
  220. }else{
  221. return "";
  222. }
  223. });
  224. template.helper("getArticleImage", function(str){
  225. if(str){
  226. if(str.indexOf("../") > -1){
  227. return ""; //原福州代码中返回的相对路径
  228. }
  229. var url = getImgUrl(str);
  230. return "<img src='"+url+"' width='80' height='80'>";
  231. }
  232. return "";
  233. })
  234. window.addEventListener("refresh", function(e){
  235. getList(true);
  236. })
  237. }
  238. function initScroller(){
  239. //阻尼系数
  240. var deceleration = mui.os.ios?0.003:0.0009;
  241. mui('.mui-scroll-wrapper').scroll({
  242. bounce: false,
  243. indicators: true, //是否显示滚动条
  244. deceleration:deceleration
  245. });
  246. mui('.mui-scroll-wrapper').pullRefresh({
  247. down: {
  248. callback: function(){
  249. getList(true);
  250. this.endPulldownToRefresh();
  251. }
  252. },
  253. up: {
  254. callback: function(){
  255. var self = this;
  256. setTimeout(function(){
  257. getList(false);
  258. self.endPullupToRefresh();
  259. }, 500);
  260. }
  261. }
  262. });
  263. }
  264. function backToManbingPage(wv, selfId){
  265. var targetId = "zhongdiangenzong";
  266. if(wv.id == targetId){
  267. setTimeout(function(){
  268. plus.webview.getWebviewById(selfId).close();
  269. }, 300);
  270. }else{
  271. var opener = wv.opener();
  272. if(wv.id != selfId){
  273. wv.close();
  274. }
  275. backToManbingPage(opener, selfId);
  276. }
  277. }