select_dept_doctor.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. // TODO 社区列表示例数据
  2. //var data = {"msg":"查询成功","list":[{"code":"3502050100","name":"内科"},{"code":"3502050101","name":"儿科"},{"code":"3502050200","name":"妇科"},{"code":"3502050300","name":"肿瘤科"},{"code":"3502050301","name":"五官科"},{"code":"3502050302","name":"消化内科"}],"status":200};
  3. // TODO 临时构造plus对象,使得能够在浏览器中进行调试
  4. //var plus = null;
  5. // 基本信息(包括userAgent、上个页面传递的数据)
  6. var baseInfo = null,
  7. // 基础环境信息(包括当前webview)
  8. baseEnv = null;
  9. var self;
  10. var isConsulted = false;
  11. var $resultWrapper = $('#result_wrap'),
  12. $doctorList = $('#doctor_list'),
  13. // 搜索输入框
  14. $searchbarInput = $('.searchbar input'),
  15. // 搜索无结果时显示
  16. $noResultWrap = $('#no_result_wrap');
  17. var curPage = 1,
  18. pageSize = 15,
  19. // iscroll 滚动条实例
  20. iscroller,
  21. isLastPage = false;
  22. // 获取基本信息(包括userAgent、上个页面传递的数据)
  23. var getBaseInfoPromise = function() {
  24. self = plus.webview.currentWebview();
  25. isConsulted = self.isConsulted;
  26. // 登录的相关信息
  27. var userAgent = plus && JSON.parse(plus.storage.getItem("userAgent"))
  28. return {
  29. userAgent: userAgent,
  30. // 上一个页面传递的数据
  31. accessData: baseEnv.webview.accessData
  32. }
  33. },
  34. // 获取基础环境信息
  35. getBaseEnvPromise = function () {
  36. var env = {
  37. webview: plus&&plus.webview.currentWebview()
  38. };
  39. return Promise.resolve().then(function(res) {
  40. return env;
  41. });
  42. },
  43. // 初始化科室列表
  44. initDoctorList = function(data) {
  45. var html = template("doctor_li_tmpl", data);
  46. $doctorList.append(html);
  47. },
  48. // 分页查询列表
  49. searchByPaging = function () {
  50. plus.nativeUI.showWaiting();
  51. var url = "doctor/doctors_list",
  52. params = {
  53. hospital: baseInfo.accessData.hospitalId,
  54. dept: baseInfo.accessData.deptId,
  55. page: curPage,
  56. pagesize:pageSize
  57. };
  58. getReqPromise(url,params).then(function(res){
  59. if(res.status == 200) {
  60. var data = res;
  61. if(!iscroller) {
  62. iscroller = initScroller($resultWrapper,url,
  63. function() { // 传递分页参数
  64. return $.extend({},params,{page:curPage+1});
  65. },function(data) {
  66. initDoctorList(data);
  67. iscroller.refresh();
  68. });
  69. }
  70. if(!data.data || !data.data.length) {
  71. $resultWrapper.hide();
  72. $(".searchbar").hide();
  73. $noResultWrap.show();
  74. } else {
  75. if(res.data.length < pageSize){
  76. $('.pullUp').hide();
  77. isLastPage = true;
  78. }
  79. $noResultWrap.hide();
  80. $(".searchbar").show();
  81. $resultWrapper.show();
  82. initDoctorList(data);
  83. }
  84. iscroller.refresh();
  85. } else {
  86. mui.toast(res.msg);
  87. }
  88. plus.nativeUI.closeWaiting();
  89. }).catch(function(e) {
  90. plus.nativeUI.closeWaiting()
  91. // mui.toast(res.msg);
  92. });
  93. },
  94. // 滚动条分页实例初始化
  95. initScroller = function($el,url,getData,pullUpAction) {
  96. var scroller;
  97. if(!isLastPage){
  98. scroller = $el.initScroll({pullDown: false,pullUpAction: function() {
  99. var data = getData();
  100. getReqPromise(url,data).then(function(data) {
  101. if(pullUpAction && $.isFunction(pullUpAction)) {
  102. pullUpAction(data);
  103. }
  104. updatePullUpText(scroller,data.list);
  105. });
  106. }});
  107. }else{
  108. scroller = $el.initScroll({pullDown: false, pullUp: false});
  109. }
  110. return scroller;
  111. },
  112. // 更新分页上拉加载的提示文本
  113. updatePullUpText= function(scroller,list) {
  114. var $wrap = $(scroller.wrapper),
  115. $pullupLabel = $wrap.find('.pullUpLabel');
  116. if(!list || !list.length) {
  117. $pullupLabel.text('没有更多');
  118. $wrap.find('.pullUp').hide();
  119. isLastPage = true;
  120. } else if(list.length == pageSize){
  121. $pullupLabel.text('上拉加载更多');
  122. }else{
  123. isLastPage = true;
  124. $wrap.find('.pullUp').hide();
  125. }
  126. scroller.on('refresh',function() {
  127. if(!list || !list.length) {
  128. isLastPage = true;
  129. $pullupLabel.text('没有更多');
  130. $wrap.find('.pullUp').hide();
  131. } else if(list.length == pageSize){
  132. $pullupLabel.text('上拉加载更多');
  133. }
  134. if(list.length < pageSize){
  135. isLastPage = true;
  136. $pullupLabel.text('没有更多');
  137. $wrap.find('.pullUp').hide();
  138. }
  139. });
  140. },
  141. // 绑定页面事件
  142. bindEvents = function () {
  143. $searchbarInput.on('click',function() {
  144. mui.openWindow({
  145. url:"search_doctor.html",
  146. id:"search_doctor",
  147. extras: {
  148. accessData:{
  149. consultCode: self.consultInfo.consult,
  150. patient: self.consultInfo.patient
  151. },
  152. aa: self.aa,
  153. members: self.members,
  154. consultInfo: self.consultInfo
  155. }
  156. });
  157. });
  158. $("#cy_btn").on('click',function(){
  159. mui.openWindow({
  160. url:"changyong_doctor.html",
  161. id:"changyong_doctor"
  162. });
  163. });
  164. };
  165. // 页面业务处理流程开始
  166. new Promise(function(resolve, reject) {
  167. // TODO 临时放开
  168. //resolve(true);
  169. mui.plusReady(function() {
  170. // plus已经准备好,可以往下执行
  171. resolve(true);
  172. });
  173. }).then(function() {
  174. // 获取基础环境信息
  175. return getBaseEnvPromise().then(function(env) {
  176. baseEnv = env;
  177. }).then(function() {
  178. // 获取登录医生信息
  179. baseInfo = getBaseInfoPromise();
  180. searchByPaging();
  181. // 绑定页面事件
  182. bindEvents();
  183. })
  184. }).catch(function(e) {
  185. plus.nativeUI.closeWaiting();
  186. console && console.error(e);
  187. });
  188. template.helper("setPhoto", function(p) {
  189. return getImgUrl(p);
  190. });