menzhenjilu.js 4.5 KB

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