pati_detail.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. var self;
  2. var scrollered,
  3. scrollered1,
  4. page = 1,
  5. size = 10;
  6. var activityLoaded = false; // 标志参与活动未加载
  7. var accountId = null;
  8. // 标签
  9. var $searchtResult = $('#search_result'),
  10. $searchtResult1 = $('#search_result1'),
  11. $goalList = $('#goal_list'),
  12. $activityList = $('#activity_list');
  13. var $patImg = $("#patImg");
  14. window.addEventListener("reLoad", function refresh(e) {
  15. patiDetail();
  16. });
  17. //下拉刷新上拉加载
  18. var updatePullUpText = function(scroller, list) {
  19. var $wrap = $(scroller.wrapper),
  20. $pullupLabel = $wrap.find('.pullUpLabel');
  21. $(".pullUp").removeClass("loading");
  22. if(!list) {
  23. $pullupLabel.text('没有更多');
  24. } else if(list.length < 10) {
  25. $(".pullUp").hide();
  26. } else {
  27. $pullupLabel.text('上拉加载更多');
  28. }
  29. scroller.on('refresh', function() {
  30. if(!list) {
  31. $pullupLabel.text('没有更多');
  32. } else if(list.length < 10) {
  33. $(".pullUp").hide();
  34. } else {
  35. $pullupLabel.text('上拉加载更多');
  36. }
  37. });
  38. },
  39. // 初始化画面-积分数据
  40. patiDetail = function() {
  41. plus.nativeUI.showWaiting();
  42. var obj = {
  43. patientId: self.patient
  44. },
  45. params = {
  46. account: JSON.stringify(obj),
  47. page: 1,
  48. size: 1
  49. }
  50. sendPost("/doctor/healthBank/findAccount", params, queryFails, function(res) {
  51. if(res.data.status == 200) {
  52. plus.nativeUI.closeWaiting();
  53. var data = res.data.detailModelList[0]
  54. accountId = data.id;
  55. var setImgHtml = template("set_pat_img", {data: data});
  56. // 渲染数据
  57. $patImg.empty().append(setImgHtml);
  58. $("#cityRanking").html(data.cityRanking);
  59. $("#teamRanking").html(data.teamRanking);
  60. $("#pati_name").html(data.accountName);
  61. $("#nowGoal").html(data.total);
  62. $("#finishTime").html(data.taskTotal);
  63. $("#joinTime").html(data.activityTotal);
  64. // $("#getAward").html();
  65. getAllGoal(true)
  66. } else {
  67. plus.nativeUI.closeWaiting();
  68. queryFails(res);
  69. }
  70. }, 'POST')
  71. },
  72. // 全部积分数据
  73. getAllGoal = function(boolean) {
  74. plus.nativeUI.showWaiting();
  75. var obj = {
  76. accountId: accountId
  77. },
  78. params = {
  79. creditsLogDo: JSON.stringify(obj),
  80. page: page,
  81. size: size
  82. }
  83. sendPost("/doctor/healthBank/selectDetails", params, queryFails, function(res) {
  84. if(res.status == 200) {
  85. var list = res.data.detailModelList;
  86. updatePullUpText(scrollered, list);
  87. plus.nativeUI.closeWaiting();
  88. var html = template("result_tmpl", {list: list});
  89. if(boolean) {
  90. $goalList.empty().append(html);
  91. if(list.length == 0) {
  92. $("#no_result_wrap").show();
  93. } else {
  94. $("#no_result_wrap").hide();
  95. }
  96. } else {
  97. $goalList.append(html);
  98. }
  99. $('#wrapper').show();
  100. scrollered.refresh();
  101. } else {
  102. plus.nativeUI.closeWaiting();
  103. queryFails(res);
  104. }
  105. }, 'POST')
  106. },
  107. // 全部活动数据
  108. getActivity = function(boolean) {
  109. plus.nativeUI.showWaiting();
  110. var params = {
  111. patientId: self.patient,
  112. page: page,
  113. size: size
  114. }
  115. sendPost("/doctor/healthBank/selectByPatient", params, queryFails, function(res) {
  116. if(res.status == 200) {
  117. activityLoaded = true
  118. plus.nativeUI.closeWaiting();
  119. var list = res.data.detailModelList;
  120. updatePullUpText(scrollered1, list);
  121. var html = template("activity_tmpl", {list: list});
  122. if(boolean) {
  123. $activityList.empty().append(html);
  124. if(list.length == 0) {
  125. $(".set-border-bg").hide()
  126. $("#no_result_wrap1").show();
  127. } else {
  128. $(".set-border-bg").show()
  129. $("#no_result_wrap1").hide();
  130. }
  131. } else {
  132. $activityList.append(html);
  133. }
  134. $('#wrapper1').show();
  135. scrollered1.refresh();
  136. } else {
  137. plus.nativeUI.closeWaiting();
  138. queryFails(res);
  139. }
  140. }, 'post')
  141. },
  142. //查询失败回调
  143. queryFails = function(res) {
  144. if(res) {
  145. mui.toast(res.msg)
  146. } else {
  147. mui.toast("加载失败!")
  148. }
  149. },
  150. // 绑定页面事件
  151. bindEvents = function () {
  152. $(".integral").on("tap", function() {
  153. openWebview("select_goal.html", {
  154. patient: self.patient
  155. })
  156. });
  157. //初始化下拉刷新 上拉加载
  158. scrollered = $("#wrapper").initScroll({
  159. pullDownAction: function() {
  160. page = 1
  161. getAllGoal(true);
  162. },
  163. pullUpAction: function() {
  164. page++
  165. getAllGoal(false);
  166. }
  167. });
  168. scrollered1 = $("#wrapper1").initScroll({
  169. pullDownAction: function() {
  170. page = 1;
  171. getActivity(true);
  172. },
  173. pullUpAction: function() {
  174. page++;
  175. getActivity(false);
  176. }
  177. });
  178. $("#con_tit div").on("tap", function() {
  179. var $this = $(this),
  180. index = $this.index();
  181. if($this.hasClass("active")){
  182. return false;
  183. }
  184. $this.siblings().removeClass("active");
  185. $this.addClass("active");
  186. mui('.mui-slider').slider().gotoItem(parseInt(index));
  187. if(!activityLoaded){
  188. getActivity(true)
  189. }
  190. })
  191. //滚动切换
  192. document.querySelector('.mui-slider').addEventListener('slide', function(event) {
  193. if (event.detail.slideNumber === 0) {
  194. $("#con_tit div").eq(0).addClass("active");
  195. $("#con_tit div").eq(1).removeClass("active");
  196. } else if (event.detail.slideNumber === 1) {
  197. if(!activityLoaded){
  198. getActivity(true)
  199. }
  200. $("#con_tit div").eq(0).removeClass("active");
  201. $("#con_tit div").eq(1).addClass("active");
  202. }
  203. });
  204. };
  205. // 页面业务处理流程开始
  206. mui.plusReady(function() {
  207. //获取当前页面
  208. self = plus.webview.currentWebview();
  209. //绑定事件
  210. bindEvents();
  211. //数据渲染
  212. patiDetail();
  213. })