hospital_dept.js 6.4 KB

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