jifenguanli.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. // 基本信息(包括userAgent)
  2. var baseInfo = null,
  3. // 基础环境信息(包括当前webview)
  4. baseEnv = null;
  5. // 搜索框
  6. var $searchbar = $('.searchbar'),
  7. // 搜索输入框
  8. $searchbarInput = $('.searchbar input'),
  9. $searchCancel = $('#cancel_btn'),
  10. // 搜索结果展示容器
  11. $searchtResult = $('#search_result'),
  12. // 患者分组列表
  13. $resultList = $('#result_list');
  14. var self;
  15. var docInfo;
  16. var selectJudge = 0,
  17. activityIdArr = [0],
  18. activityTitleArr = ["积分排行榜"];
  19. var scrollered,
  20. keyword = "",
  21. page = 1,
  22. pagesize = 10;
  23. // 获取登录相关信息
  24. var getBaseInfo = function() {
  25. // 登录的相关信息
  26. var userAgent = JSON.parse(plus.storage.getItem("userAgent"))
  27. return {
  28. userAgent: userAgent,
  29. teamInfo: JSON.parse(plus.storage.getItem("teamInfo"))
  30. }
  31. },
  32. // 获取基础环境信息
  33. getBaseEnvPromise = function () {
  34. self = plus.webview.currentWebview();
  35. docInfo = JSON.parse(plus.storage.getItem("docInfo"));
  36. var env = {
  37. webview: plus&&plus.webview.currentWebview()
  38. };
  39. return Promise.resolve().then(function(res) {
  40. return env;
  41. });
  42. },
  43. //下拉刷新上拉加载
  44. updatePullUpText = function(scroller, list) {
  45. var $wrap = $(scroller.wrapper),
  46. $pullupLabel = $wrap.find('.pullUpLabel');
  47. $(".pullUp").removeClass("loading");
  48. if(!list) {
  49. $pullupLabel.text('没有更多');
  50. } else if(list.length < 10) {
  51. $(".pullUp").hide();
  52. } else {
  53. $pullupLabel.text('上拉加载更多');
  54. }
  55. scroller.on('refresh', function() {
  56. if(!list) {
  57. $pullupLabel.text('没有更多');
  58. } else if(list.length < 10) {
  59. $(".pullUp").hide();
  60. } else {
  61. $pullupLabel.text('上拉加载更多');
  62. }
  63. });
  64. },
  65. // 初始化画面患者-积分列表
  66. searchList = function(boolean) {
  67. plus.nativeUI.showWaiting();
  68. var params = {
  69. doctorId:docInfo.code,
  70. name: keyword,
  71. activityId: selectJudge,
  72. page: page,
  73. size: pagesize
  74. }
  75. sendPost("/doctor/healthBank/findCreditRanking", params, queryFails, function(res) {
  76. if(res.status == 200) {
  77. page += 1;
  78. var list = res.data.detailModelList;
  79. updatePullUpText(scrollered, list);
  80. plus.nativeUI.closeWaiting();
  81. var html = template("result_tmpl", {list: list});
  82. if(boolean) {
  83. $resultList.empty().append(html);
  84. if(list.length == 0) {
  85. $("#no_result_wrap").show();
  86. } else {
  87. $("#no_result_wrap").hide();
  88. }
  89. } else {
  90. $resultList.append(html);
  91. }
  92. $('#wrapper').show();
  93. scrollered.refresh();
  94. } else {
  95. plus.nativeUI.closeWaiting();
  96. queryFails(res);
  97. }
  98. }, 'post')
  99. },
  100. // 活动下的积分排行
  101. activityPatList = function(boolean) {
  102. plus.nativeUI.showWaiting();
  103. var params = {
  104. doctorId:docInfo.code,
  105. name: keyword,
  106. activityId: selectJudge,
  107. page: page,
  108. size: pagesize
  109. }
  110. sendPost("/doctor/healthBank/findActivityRanking", params, queryFails, function(res) {
  111. if(res.status == 200) {
  112. page += 1;
  113. var list = res.data.detailModelList;
  114. updatePullUpText(scrollered, list);
  115. plus.nativeUI.closeWaiting();
  116. var html = template("result_tmpl", {list: list});
  117. if(boolean) {
  118. $resultList.empty().append(html);
  119. if(list.length == 0) {
  120. $("#no_result_wrap").show();
  121. } else {
  122. $("#no_result_wrap").hide();
  123. }
  124. } else {
  125. $resultList.append(html);
  126. }
  127. $('#wrapper').show();
  128. scrollered.refresh();
  129. } else {
  130. plus.nativeUI.closeWaiting();
  131. queryFails(res);
  132. }
  133. }, 'post')
  134. },
  135. //查询失败回调
  136. queryFails = function(res) {
  137. if(res) {
  138. mui.toast(res.msg)
  139. } else {
  140. mui.toast("加载失败!")
  141. }
  142. },
  143. /**
  144. * 获取积分活动列表
  145. */
  146. getActivityList = function() {
  147. sendPost("/doctor/healthBank/selectTask",{task: "{}", page: 1, size: 100}, null, function(res){
  148. if(res.status == 200){
  149. var dataList = res.data.detailModelList;
  150. for(var i = 0; i < dataList.length; i++){
  151. activityIdArr.push(dataList[i].id);
  152. activityTitleArr.push(dataList[i].title);
  153. }
  154. setActiveSortTit(activityIdArr, activityTitleArr);
  155. }
  156. },'post')
  157. },
  158. /**
  159. * 设置选择活动标题
  160. */
  161. setActiveSortTit = function(activityIdArr, activityTitleArr) {
  162. $('#sort_tit').mobiscroll({
  163. theme: 'ios',
  164. lang: 'zh',
  165. customWheels: true,
  166. wheels: [
  167. [{
  168. keys: activityIdArr,
  169. values: activityTitleArr
  170. }]
  171. ],
  172. onSelect: function(valueText, inst) {
  173. var dd = eval("[" + valueText + "]");
  174. $(this).html(dd[0].values).attr("data-code", dd[0].keys);
  175. selectJudge = dd[0].keys
  176. page = 1
  177. if(selectJudge == 0) {
  178. searchList(true)
  179. } else {
  180. activityPatList(true)
  181. }
  182. }
  183. }
  184. )},
  185. // 绑定页面事件
  186. bindEvents = function () {
  187. //初始化下拉刷新 上拉加载
  188. scrollered = $("#wrapper").initScroll({
  189. pullDownAction: function() {
  190. page = 1
  191. if(selectJudge == 0) {
  192. searchList(true)
  193. } else {
  194. activityPatList(true)
  195. }
  196. },
  197. pullUpAction: function() {
  198. if(selectJudge == 0) {
  199. searchList(false)
  200. } else {
  201. activityPatList(false)
  202. }
  203. }
  204. });
  205. $searchbarInput.bind('input propertychange', function() {
  206. keyword = $(this).val();
  207. if(keyword == "") {
  208. $searchCancel.hide()
  209. } else {
  210. $searchCancel.show()
  211. }
  212. page = 1;
  213. if(selectJudge == 0) {
  214. searchList(true)
  215. } else {
  216. activityPatList(true)
  217. }
  218. });
  219. $searchCancel.on("tap", function() {
  220. $(this).hide()
  221. $searchbarInput.val("")
  222. keyword = "";
  223. page = 1;
  224. if(selectJudge == 0) {
  225. searchList(true)
  226. } else {
  227. activityPatList(true)
  228. }
  229. });
  230. $resultList.on("tap", "li", function() {
  231. patient = $(this).attr("data-code")
  232. openWebview("pati_detail.html", {
  233. patient: patient
  234. });
  235. });
  236. };
  237. // 页面业务处理流程开始
  238. mui.plusReady(function() {
  239. //获取当前页面
  240. var self = plus.webview.currentWebview();
  241. getBaseEnvPromise();
  242. //绑定事件
  243. bindEvents();
  244. //数据渲染
  245. searchList(true);
  246. getActivityList();
  247. })