fasongjilu.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. // 基本信息(包括userAgent)
  2. var baseInfo = null,
  3. //滚动条
  4. scroller1=null,
  5. // 基础环境信息(包括当前webview)
  6. baseEnv = null,
  7. patient = null,
  8. patientName ="",
  9. page=0,
  10. pagesize=10;
  11. //文章列表
  12. $articleList = $(".mui-table-view");
  13. // 获取登录相关信息
  14. var getBaseInfo = function() {
  15. // 登录的相关信息
  16. var userAgent = JSON.parse(plus.storage.getItem("userAgent"))
  17. return {
  18. userAgent: userAgent
  19. }
  20. },
  21. // 获取基础环境信息
  22. getBaseEnvPromise = function () {
  23. var env = {
  24. webview: plus&&plus.webview.currentWebview()
  25. };
  26. var self = plus.webview.currentWebview();
  27. return Promise.resolve().then(function(res) {
  28. return env;
  29. });
  30. },
  31. //事件绑定
  32. bindEvents = function(){
  33. $('#scroll1').on('tap','li[data-article]',function() {
  34. var article = $(this).attr('data-article');
  35. var batchNo = $(this).attr('data-batch-no')||"";
  36. openWebviewExtras("jiluxiangqing.html",{article:article,batchNo:batchNo});
  37. });
  38. },
  39. loadListPromise = function(page) {
  40. plus.nativeUI.showWaiting();
  41. return new Promise(function(resolve, reject) {
  42. sendPost("/doctor/health/edu/logs",{
  43. page: page,
  44. pagesize: pagesize
  45. },function(res){
  46. plus.nativeUI.closeWaiting();
  47. if(res.msg){
  48. mui.toast(res.msg);
  49. }else{
  50. mui.toast("加载失败!");
  51. }
  52. },function(res){
  53. plus.nativeUI.closeWaiting();
  54. if(res.status==200){
  55. resolve(res.list)
  56. }else{
  57. if(res.msg){
  58. mui.toast(res.msg);
  59. }else{
  60. mui.toast("加载失败!");
  61. }
  62. }
  63. })
  64. });
  65. },
  66. initScroll = function () {
  67. var page = 1;
  68. var pullRefresh = mui('.mui-scroll-wrapper').pullRefresh({
  69. down: {
  70. callback: function() {
  71. page = 1;
  72. var self = this;
  73. var ul = self.element.querySelector('.mui-table-view');
  74. var $scrollEl = $(ul).closest('.mui-scroll');
  75. var $noResult = $scrollEl.find('.no-result');
  76. loadListPromise(page)
  77. .then(function(list) {
  78. if(list && list.length) {
  79. page++;
  80. setTimeout(function() {
  81. var html = template('liTempl',{list: list});
  82. $(ul).html(html);
  83. self.endPulldownToRefresh();
  84. }, 1000);
  85. }
  86. })
  87. .catch(function(e) {
  88. console && console.error(e)
  89. })
  90. }
  91. },
  92. up: {
  93. callback: function() {
  94. var self = this;
  95. var ul = self.element.querySelector('.mui-table-view');
  96. var $scrollEl = $(ul).closest('.mui-scroll');
  97. var $noResult = $scrollEl.find('.no-result');
  98. loadListPromise(page)
  99. .then(function(list) {
  100. if(list && list.length) {
  101. page++;
  102. setTimeout(function() {
  103. var ul = self.element.querySelector('.mui-table-view');
  104. var html = template('liTempl',{list: list});
  105. $(ul).append(html);
  106. self.endPullupToRefresh(list.length < pagesize);
  107. }, 1000);
  108. } else {
  109. if(page == 1) {
  110. $noResult.show();
  111. }
  112. self.endPullupToRefresh(true);
  113. }
  114. })
  115. .catch(function(e) {
  116. console && console.error(e)
  117. })
  118. }
  119. }
  120. }).pullupLoading();
  121. };
  122. template.helper("dateFormat", function(d) {
  123. return new Date(d).format('yyyy-MM-dd hh:mm')
  124. });
  125. template.helper("handleSenders", function(str) {
  126. if(str) {
  127. var arr = str.split(',').slice(0,3);
  128. str = arr.join(',');
  129. }
  130. return str;
  131. });
  132. // 页面业务处理流程开始
  133. new Promise(function(resolve, reject) {
  134. // TODO 临时放开
  135. //resolve(true);
  136. mui.plusReady(function() {
  137. // hrefhrefplus已经准备好,可以往下执行
  138. resolve(true);
  139. });
  140. }).then(function() {
  141. // 获取基础环境信息
  142. return getBaseEnvPromise().then(function(env) {
  143. baseEnv = env;
  144. }).then(function() {
  145. // 获取登录基本信息
  146. baseInfo = getBaseInfo();
  147. var self = plus.webview.currentWebview();
  148. patient = self.patient;
  149. patientName = self.patientName;
  150. initScroll();
  151. // 绑定页面事件
  152. bindEvents();
  153. })
  154. }).catch(function(e) {
  155. plus.nativeUI.closeWaiting();
  156. console && console.error(e);
  157. });