xuanzeyisheng.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. // TODO 医生列表示例数据
  2. //var doctorsData = {"msg":"获取医院医生列表成功!","list":[{"code":"D2016080002","jobName":" 全科医师","introduce":"我是全科医生","name":"大米全科1","deptName":"","photo":"http://172.19.103.85:8882/res/images/2016/08/12/20160812170142_901.jpg","id":1262,"expertise":"我是全科医生","hospitalName":"嘉莲社区医疗服务中心"},{"code":"D2016080005","jobName":" 全科医师","introduce":"我是全科医生","name":"大米全科2","deptName":"","photo":"","id":1271,"expertise":"我是全科医生","hospitalName":"嘉莲社区医疗服务中心"},{"code":"D2016080225","jobName":" 全科医师","introduce":"我是全科医生","name":"谭仁祝(全科)","deptName":"","photo":"","id":1274,"expertise":"我是全科医生","hospitalName":"嘉莲社区医疗服务中心"},{"code":"D2010080225","jobName":" 全科医师","introduce":"我是全科医生","name":"谭仁祝(全科1)","deptName":"","photo":"","id":1276,"expertise":"我是全科医生","hospitalName":"嘉莲社区医疗服务中心"}],"status":200};
  3. // TODO 临时构造plus对象,使得能够在浏览器中进行调试
  4. // var plus = null;
  5. // 登录者相关信息(包括userAgent)
  6. var baseInfo = null,
  7. // 基础环境信息(包括当前webview)
  8. baseEnv = null;
  9. var $orgTab = $('#org_tab'),
  10. $yishengWrapper = $('#yisheng_wrapper'),
  11. $yishengiList = $('#yisheng_list'),
  12. // 搜索输入框
  13. $searchbarInput = $('.searchbar input'),
  14. // 搜索无结果时显示
  15. $noResultWrap = $('#no_result_wrap');
  16. var curPage = 1,
  17. // iscroll 滚动条实例
  18. iscroller;
  19. // 获取基本信息(包括userAgent、上个页面传递的数据)
  20. var getBaseInfoPromise = function() {
  21. // 登录的相关信息
  22. var userAgent = plus && JSON.parse(plus.storage.getItem("userAgent"));
  23. return {
  24. userAgent: userAgent,
  25. accessData: baseEnv.webview.accessData
  26. }
  27. },
  28. // 获取基础环境信息
  29. getBaseEnvPromise = function () {
  30. var env = {
  31. webview: plus&&plus.webview.currentWebview()
  32. };
  33. return Promise.resolve().then(function(res) {
  34. return env;
  35. });
  36. },
  37. // 初始化医生列表
  38. initYiShengList = function(doctorsData) {
  39. var html = template("yisheng_li_tmpl", {list: doctorsData.list})
  40. $yishengiList.append(html);
  41. },
  42. // 分页查询列表
  43. searchByPaging = function () {
  44. // TODO 示例示例搜索参数
  45. // id: 上次搜索结果列表最后一条记录id,type:6(进行中),query:搜素关键字,pageSize:每页条数
  46. var url = "/doctor/findDoctorByDept",
  47. dept = baseInfo.accessData.dept,
  48. params = { page:curPage,pagesize:15, dept: dept};
  49. getReqPromise(url,params).then(function(res){
  50. var data = res;
  51. if(!iscroller) {
  52. iscroller = initScroller($yishengWrapper,url,
  53. function() { // 传递分页参数
  54. return $.extend({},params,{page:curPage+1});
  55. },function(data) {
  56. if(data.list && data.list.length) {
  57. curPage++;
  58. }
  59. initYiShengList(data);
  60. iscroller.refresh();
  61. });
  62. }
  63. if(!data.list || !data.list.length) {
  64. $searchtResult.hide();
  65. $noResultWrap.show();
  66. } else {
  67. $noResultWrap.hide();
  68. initYiShengList(data);
  69. if(data.list.length<15){
  70. $('.pullUp').hide();
  71. }
  72. }
  73. iscroller.refresh();
  74. }).catch(function(e) {
  75. console && console.error(e)
  76. });
  77. },
  78. // 滚动条分页实例初始化
  79. initScroller = function($el,url,getData,pullUpAction) {
  80. var scroller = $el.initScroll({pullDown: false,pullUpAction: function() {
  81. var data = getData();
  82. getReqPromise(url,data).then(function(data) {
  83. if(pullUpAction && $.isFunction(pullUpAction)) {
  84. pullUpAction(data);
  85. }
  86. updatePullUpText(scroller,data.list);
  87. })
  88. }});
  89. return scroller;
  90. },
  91. // 更新分页上拉加载的提示文本
  92. updatePullUpText= function(scroller,list) {
  93. var $wrap = $(scroller.wrapper),
  94. $pullupLabel = $wrap.find('.pullUpLabel');
  95. if(!list || !list.length) {
  96. $pullupLabel.text('没有更多');
  97. } else if(list.length==15){
  98. $pullupLabel.text('上拉加载更多');
  99. }else{
  100. $wrap.find('.pullUp').hide();
  101. }
  102. scroller.on('refresh',function() {
  103. if(!list || !list.length) {
  104. $pullupLabel.text('没有更多');
  105. } else if(list.length==15){
  106. $pullupLabel.text('上拉加载更多');
  107. }
  108. if(list.length<15){
  109. $wrap.find('.pullUp').hide();
  110. }
  111. });
  112. },
  113. // 绑定页面事件
  114. bindEvents = function () {
  115. $yishengiList.on('tap','li',function() {
  116. var code = $(this).attr('data-code');
  117. openWebview("doctor-homepage.html",{
  118. accessData: {
  119. doctor: code
  120. }
  121. })
  122. });
  123. $searchbarInput.on('tap',function() {
  124. var toWebview = plus.webview.getWebviewById("sousuojigouyisheng");
  125. var createNew = !!toWebview;
  126. createNew && toWebview.close();
  127. mui.openWindow({
  128. url:"sousuojigouyisheng.html",
  129. id:"sousuojigouyisheng",
  130. createNew: true
  131. });
  132. });
  133. };
  134. // 页面业务处理流程开始
  135. new Promise(function(resolve, reject) {
  136. // TODO 临时放开
  137. //resolve(true);
  138. mui.plusReady(function() {
  139. // plus已经准备好,可以往下执行
  140. resolve(true);
  141. });
  142. }).then(function() {
  143. // 获取基础环境信息
  144. return getBaseEnvPromise().then(function(env) {
  145. baseEnv = env;
  146. }).then(function() {
  147. // 获取登录医生信息
  148. baseInfo = getBaseInfoPromise();
  149. searchByPaging();
  150. // 绑定页面事件
  151. bindEvents();
  152. })
  153. }).catch(function(e) {
  154. plus.nativeUI.closeWaiting();
  155. console && console.error(e);
  156. });
  157. template.helper("setPhoto", function(p) {
  158. return getImgUrl(p);
  159. });