jianchajianyan.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. // 最后一条记录的eventDate
  12. lastTime = "",
  13. // iscroll 滚动条实例
  14. iscroller;
  15. template.helper("toJson", function(v, i) {
  16. return JSON.stringify(v);
  17. });
  18. // 获取基本信息(包括userAgent、上个页面传递的数据)
  19. var getBaseInfoPromise = function() {
  20. // 登录的相关信息
  21. var userAgent = plus && JSON.parse(plus.storage.getItem("userAgent"))
  22. return {
  23. userAgent: userAgent,
  24. patiInfo: baseEnv.webview.patiInfo
  25. }
  26. },
  27. // 获取基础环境信息
  28. getBaseEnvPromise = function () {
  29. var env = {
  30. webview: plus&&plus.webview.currentWebview()
  31. };
  32. return Promise.resolve().then(function(res) {
  33. return env;
  34. });
  35. },
  36. // 初始化就诊事件列表
  37. initEventList = function(list) {
  38. var html = template("recent_event_tmpl", {list: list})
  39. $eventList.append(html);
  40. },
  41. // 分页查询列表
  42. searchByPaging = function () {
  43. var url = healthProfileServer+"doctor/archives/event/report",
  44. pagesize = 50,
  45. params = {
  46. patient: baseInfo.patiInfo.code,
  47. page: curPage,
  48. pageSize: pagesize
  49. };
  50. getReqPromise(url,params,'GET').then(function(res){
  51. plus.nativeUI.closeWaiting();
  52. if(!iscroller) {
  53. iscroller = initScroller($eventListWrapper,url,
  54. function() { // 传递分页参数
  55. return $.extend({},params,{page: curPage,lastTime: lastTime});
  56. },function(res) {
  57. if(res.status == 200) {
  58. var list = res.data;
  59. if(list && list.length) {
  60. curPage++;
  61. lastTime = list[list.length-1].eventDate;
  62. }
  63. initEventList(list);
  64. if(list.length < pagesize){
  65. $(".pullUp").hide();
  66. }else{
  67. $(".pullUp").show();
  68. }
  69. iscroller.refresh();
  70. } else {
  71. mui.toast(res.msg);
  72. }
  73. });
  74. }
  75. if(res.status == 200) {
  76. curPage++;
  77. var list = res.data;
  78. if(!list|| !list.length) {
  79. $eventListWrapper.hide();
  80. $noResultWrap.show();
  81. } else {
  82. $noResultWrap.hide();
  83. $eventListWrapper.show();
  84. initEventList(list);
  85. lastTime = list[list.length-1].eventDate;
  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("single-profile.html",{eventInfo: data,patiInfo: baseInfo.patiInfo});
  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. });