guidance_list.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. mui.init();
  2. var scrollers = [],
  3. page = [1,1], //主要存储个人和系统的模板分页信息
  4. page1 = [], //存储团队模板中,各个团队对应的模板分页信息
  5. loaded = [],
  6. patient = null,
  7. docInfo = null,
  8. reference,
  9. pagesize = 20,
  10. pagesize2 = 10,
  11. selectedTab = 0; //默认选中第一个tab
  12. isIndex=null;
  13. mui.plusReady(function(){
  14. var self = plus.webview.currentWebview();
  15. var opener = self.opener();
  16. if(opener.id == "home2.html"){
  17. reference = "home2";
  18. }
  19. patient = self.code;
  20. isIndex = self.isIndex;
  21. initScroller();
  22. getList(true);
  23. bindEvents();
  24. });
  25. function getList(isInit){
  26. if(isInit){
  27. page[selectedTab] = 1;
  28. }
  29. var url = "doctor/guidance_temp/list",
  30. params = {
  31. type: selectedTab == 0 ? 2 : 1, //模板类型 1:系统 2:自定义 为空:所有
  32. pageNo: page[selectedTab],
  33. pageSize: pagesize
  34. },
  35. filter = '';
  36. if(selectedTab == 0){
  37. filter = $("#item1 .search-input").val();
  38. }else{
  39. filter = $("#item2 .search-input").val();
  40. }
  41. params.filter = filter;
  42. plus.nativeUI.showWaiting();
  43. sendGet(url, params, null, function(res){
  44. if(res.status == 200){
  45. loaded[selectedTab] = true;
  46. var $controlPanel = $("#item"+(selectedTab + 1)),
  47. $ul = $controlPanel.find("ul"),
  48. $noResult = $controlPanel.find(".no-result");
  49. if(isInit){
  50. if(res.data.length == 0){
  51. $ul.hide();
  52. $noResult.show();
  53. }else{
  54. $ul.show();
  55. $noResult.hide();
  56. var html = template("guidance_tmp", {list: res.data});
  57. $ul.empty().append(html);
  58. }
  59. }else{
  60. var html = template("guidance_tmp", {list: res.data});
  61. $ul.append(html);
  62. }
  63. if(res.data.length < pagesize){
  64. scrollers[selectedTab].endPullupToRefresh(true);
  65. }else{
  66. scrollers[selectedTab].endPullupToRefresh(false);
  67. page[selectedTab] ++;
  68. }
  69. }else{
  70. mui.toast(res.msg);
  71. }
  72. plus.nativeUI.closeWaiting();
  73. }, true);
  74. }
  75. function bindEvents(){
  76. document.querySelector('.mui-slider').addEventListener('slide', function(event) {
  77. selectedTab = event.detail.slideNumber;
  78. if(loaded[selectedTab] == "false"){
  79. getList(true);
  80. loaded[selectedTab] = "true";
  81. }
  82. });
  83. //新增按钮
  84. $(".add-icon").on("tap", function(){
  85. var $this = $(this),
  86. type = $this.attr("data-val");
  87. openWebview('edit_guidance.html',{
  88. action: "add",
  89. reference: reference,
  90. patiCode: patient
  91. });
  92. });
  93. //查看文章详情
  94. $("#item1").on('tap', 'li', function(){
  95. var code = $(this).attr("data-code");
  96. openWebview("guidance_detail.html",{
  97. code: code,
  98. reference: reference,
  99. patiCode: patient,
  100. isIndex:isIndex
  101. });
  102. });
  103. $("#item2").on('tap', 'li', function(){
  104. var code = $(this).attr("data-code");
  105. openWebview("guidance_detail.html", {
  106. code: code,
  107. reference: reference,
  108. patiCode: patient,
  109. is_sys: true,
  110. isIndex:isIndex
  111. });
  112. });
  113. //搜索功能
  114. $(".search-input").on('keydown', function(e){
  115. if (e.which === 13) {
  116. e.preventDefault();
  117. getList(true);
  118. }
  119. });
  120. //设置页面监听
  121. window.addEventListener("refresh", function(e){
  122. getList(true);
  123. })
  124. }
  125. function initScroller(){
  126. $.each(document.querySelectorAll('.mui-slider-group .mui-scroll-wrapper'), function(index, pullRefreshEl) {
  127. page.push(1);
  128. loaded.push("false");
  129. var pullRefresh = mui(pullRefreshEl).pullRefresh({
  130. down:{
  131. callback: function(){
  132. var self = this;
  133. setTimeout(function(){
  134. if(selectedTab == 0){
  135. $("#item1 .search-input").blur();
  136. }else{
  137. $("#item2 .search-input").blur();
  138. }
  139. getList(true);
  140. self.endPulldownToRefresh();
  141. }, 300);
  142. }
  143. },
  144. up: {
  145. callback: function(){
  146. var self = this;
  147. if(selectedTab == 0){
  148. $("#item1 .search-input").blur();
  149. }else{
  150. $("#item2 .search-input").blur();
  151. }
  152. setTimeout(function(){
  153. getList(false);
  154. }, 300);
  155. }
  156. }
  157. });
  158. scrollers.push(pullRefresh);
  159. })
  160. }