zhuyuanjilu.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. // 基本信息(包括userAgent、上个页面传递的数据)
  2. var baseInfo = null,
  3. // 基础环境信息(包括当前webview)
  4. baseEnv = null;
  5. var $eventListWrapper = $('#recent_event_list_wrap'),
  6. $eventList = $('#recent_event_list'),
  7. // 搜索无结果时显示
  8. $noResultWrap = $('#no_result_wrap');
  9. // 分页查询当前页数
  10. var curPage = 1,
  11. // iscroll 滚动条实例
  12. iscroller;
  13. template.helper("toJson", function(v, i) {
  14. return JSON.stringify(v);
  15. });
  16. // 获取基本信息(包括userAgent、上个页面传递的数据)
  17. var getBaseInfoPromise = function() {
  18. // 登录的相关信息
  19. var userAgent = plus && JSON.parse(plus.storage.getItem("userAgent"))
  20. return {
  21. userAgent: userAgent,
  22. patiInfo: baseEnv.webview.patiInfo
  23. }
  24. },
  25. // 获取基础环境信息
  26. getBaseEnvPromise = function () {
  27. var env = {
  28. webview: plus&&plus.webview.currentWebview()
  29. };
  30. return Promise.resolve().then(function(res) {
  31. return env;
  32. });
  33. },
  34. // 初始化就诊事件列表
  35. initEventList = function(list) {
  36. var html = template("recent_event_tmpl", {list: list})
  37. $eventList.append(html);
  38. },
  39. // 分页查询列表
  40. searchByPaging = function () {
  41. var url = healthProfileServer+"doctor/archives/event",
  42. curPage = 1,
  43. pagesize = 50,
  44. params = {
  45. patient: baseInfo.patiInfo.code,
  46. type: '2',
  47. page: curPage,
  48. pageSize: pagesize,
  49. lastTime: ''
  50. };
  51. getReqPromise(url,params,'GET').then(function(res){
  52. plus.nativeUI.closeWaiting();
  53. if(!iscroller) {
  54. iscroller = initScroller($eventListWrapper,url,
  55. function() { // 传递分页参数
  56. var lastTime = $eventList.find('li:last').attr('data-event-date');
  57. return $.extend({},params,{page:curPage+1,lastTime: lastTime});
  58. },function(res) {
  59. if(res.status == 200) {
  60. var list = res.data;
  61. if(list && list.length) {
  62. curPage++;
  63. }
  64. initEventList(list);
  65. if(list.length < pagesize){
  66. $(".pullUp").hide();
  67. }else{
  68. $(".pullUp").show();
  69. }
  70. iscroller.refresh();
  71. } else {
  72. mui.toast(res.msg);
  73. }
  74. });
  75. }
  76. if(res.status == 200) {
  77. curPage++;
  78. var list = res.data;
  79. if(!list|| !list.length) {
  80. $eventListWrapper.hide();
  81. $noResultWrap.show();
  82. } else {
  83. $noResultWrap.hide();
  84. $eventListWrapper.show();
  85. initEventList(list);
  86. }
  87. if(list.length < pagesize){
  88. $(".pullUp").hide();
  89. }else{
  90. $(".pullUp").show();
  91. }
  92. iscroller.refresh();
  93. } else {
  94. mui.toast(res.msg);
  95. }
  96. }).catch(function(e) {
  97. plus.nativeUI.closeWaiting();
  98. console && console.error(e)
  99. });
  100. },
  101. // 滚动条分页实例初始化
  102. initScroller = function($el,url,getData,pullUpAction) {
  103. var scroller = $el.initScroll({pullDown: false,pullUpAction: function() {
  104. var data = getData();
  105. getReqPromise(url,data,'GET').then(function(data) {
  106. if(pullUpAction && $.isFunction(pullUpAction)) {
  107. pullUpAction(data);
  108. updatePullUpText(scroller,data.list);
  109. }
  110. })
  111. }});
  112. return scroller;
  113. },
  114. // 更新分页上拉加载的提示文本
  115. updatePullUpText= function(scroller,list) {
  116. var $wrap = $(scroller.wrapper),
  117. $pullupLabel = $wrap.find('.pullUpLabel');
  118. if(!list || !list.length) {
  119. $pullupLabel.text('没有更多');
  120. } else {
  121. $pullupLabel.text('上拉加载更多');
  122. }
  123. scroller.on('refresh',function() {
  124. if(!list || !list.length) {
  125. $pullupLabel.text('没有更多');
  126. } else {
  127. $pullupLabel.text('上拉加载更多');
  128. }
  129. });
  130. },
  131. // 绑定页面事件
  132. bindEvents = function () {
  133. $eventList.on('click','li',function() {
  134. var data = JSON.parse($(this).attr("data-json"));
  135. if(data.dataFrom==1) {
  136. openWebview("event-profile.html",{eventInfo: data,patiInfo: baseInfo.patiInfo,type:2});//cy
  137. } else {
  138. openWebview("jiuzhenxiangqing.html",{eventInfo: data,patiInfo: baseInfo.patiInfo});
  139. }
  140. });
  141. };
  142. // 页面业务处理流程开始
  143. new Promise(function(resolve, reject) {
  144. // TODO 临时放开
  145. //resolve(true);
  146. mui.plusReady(function() {
  147. // plus已经准备好,可以往下执行
  148. resolve(true);
  149. });
  150. }).then(function() {
  151. plus.nativeUI.showWaiting();
  152. // 获取基础环境信息
  153. return getBaseEnvPromise().then(function(env) {
  154. baseEnv = env;
  155. }).then(function() {
  156. // 获取登录医生信息
  157. baseInfo = getBaseInfoPromise();
  158. searchByPaging();
  159. // 绑定页面事件
  160. bindEvents();
  161. })
  162. }).catch(function(e) {
  163. plus.nativeUI.closeWaiting();
  164. console && console.error(e);
  165. });