huanzhe.js 4.9 KB

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