huanzhe.js 4.6 KB

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