huanzhe.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. // TODO 临时构造plus对象,使得能够在浏览器中进行调试
  2. // var plus = null;
  3. // 基本信息(包括userAgent、上个页面传递的数据)
  4. var baseInfo = null,
  5. // 基础环境信息(包括当前webview)
  6. baseEnv = null;
  7. var $patientListWrapper = $('#patient_list_wrap'),
  8. $patientList = $('#pati_list'),
  9. // 搜索无结果时显示
  10. $noResultWrap = $('#no_result_wrap');
  11. // 分页查询当前页数
  12. var curPage = 0,
  13. pageSize = 5,
  14. myScroll = null,
  15. hasMore = true;
  16. // 获取基本信息(包括userAgent、上个页面传递的数据)
  17. var getBaseInfoPromise = function() {
  18. // 登录的相关信息
  19. var userAgent = plus && JSON.parse(plus.storage.getItem("userAgent"))
  20. return {
  21. userAgent: userAgent
  22. }
  23. },
  24. // 获取基础环境信息
  25. getBaseEnvPromise = function () {
  26. var env = {
  27. webview: plus&&plus.webview.currentWebview()
  28. };
  29. return Promise.resolve().then(function(res) {
  30. return env;
  31. });
  32. },
  33. // 分页查询列表
  34. searchByPaging = function (isRefresh) {
  35. curPage = isRefresh ? 0 : curPage+1;
  36. var url = "/doctor/concern/getConcernPatients",
  37. params = { page:curPage,pageSize:pageSize};
  38. getReqPromise(url,params,'GET').then(function(res){
  39. var data = res.data;
  40. if(!data || !data.length) {
  41. $patientListWrapper.hide();
  42. $noResultWrap.show();
  43. } else {
  44. $noResultWrap.hide();
  45. $patientListWrapper.show();
  46. }
  47. if(isRefresh){
  48. myScroll.refresh(true);
  49. $patientList.empty().append(template("pati_list_tmpl", {list: data}));
  50. }else{
  51. $patientList.append(template('pati_list_tmpl', {list: data}));
  52. }
  53. if(data.length < pageSize){
  54. hasMore = false;
  55. myScroll.endPullUpToRefresh(!hasMore);
  56. }else{
  57. hasMore = true;
  58. }
  59. }).catch(function(e) {
  60. console && console.error(e)
  61. });
  62. },
  63. // 滚动条分页实例初始化
  64. initScroller = function() {
  65. //阻尼系数
  66. var deceleration = mui.os.ios?0.003:0.0009;
  67. mui('.mui-scroll-wrapper').scroll({
  68. bounce: false,
  69. indicators: true, //是否显示滚动条
  70. deceleration:deceleration
  71. });
  72. myScroll = mui(".mui-scroll").pullToRefresh({
  73. up: {
  74. callback: function(){
  75. var self = this;
  76. setTimeout(function() {
  77. searchByPaging();
  78. self.endPullUpToRefresh(!hasMore);
  79. }, 1000);
  80. }
  81. },
  82. down: {
  83. callback: function() {
  84. var self = this;
  85. setTimeout(function() {
  86. searchByPaging(true);
  87. self.endPullDownToRefresh();
  88. }, 1000);
  89. }
  90. }
  91. });
  92. },
  93. // 绑定页面事件
  94. bindEvents = function () {
  95. $patientList.on('tap','li[data-patient-code]',function(e) {
  96. var code = $(this).attr("data-patient-code");
  97. if(baseEnv.webview.origin=="suifang") {//“随访”功能
  98. if(baseEnv.webview.follow_type == 1){
  99. openWebview("../../suifang/html/add_plan.html",{patientInfo: code,chooseDate:baseEnv.webview.chooseDate});
  100. return false;
  101. }
  102. if(baseEnv.webview.follow_type == 2){
  103. openWebview("../../suifang/html/follow_way.html",{patientInfo: code});
  104. return false;
  105. }
  106. }else{
  107. openWebview("../../huanzhe/html/huanzhexinxi.html",{
  108. patiCode: code
  109. });
  110. }
  111. return false;
  112. })
  113. /*刷新事件*/
  114. // window.addEventListener("refresh", function group(e) {
  115. // searchByPaging(true);
  116. // });
  117. };
  118. // 页面业务处理流程开始
  119. new Promise(function(resolve, reject) {
  120. // TODO 临时放开
  121. //resolve(true);
  122. mui.plusReady(function() {
  123. // plus已经准备好,可以往下执行
  124. resolve(true);
  125. });
  126. }).then(function() {
  127. // 获取基础环境信息
  128. return getBaseEnvPromise().then(function(env) {
  129. baseEnv = env;
  130. }).then(function() {
  131. // 获取登录医生信息
  132. baseInfo = getBaseInfoPromise();
  133. initScroller();
  134. searchByPaging(true);
  135. // 绑定页面事件
  136. bindEvents();
  137. if(baseEnv.webview.origin){//“随访”功能,需要返回按钮
  138. $(".mui-action-back").show();
  139. }
  140. })
  141. }).catch(function(e) {
  142. plus.nativeUI.closeWaiting();
  143. console && console.error(e);
  144. });
  145. function setAge(age) {
  146. if(age == 0) {
  147. return "<1";
  148. }
  149. if(age == -1)
  150. return "未知";
  151. return age;
  152. }
  153. template.helper("setAge", setAge);
  154. function setSex(s) {
  155. if(s == 1) {
  156. return "男";
  157. } else if(s == 2) {
  158. return "女";
  159. }
  160. }
  161. template.helper("setSex", setSex);