select-consult-doctor.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. var d = dialog({contentType:'load', skin:'bk-popup'});
  2. var page = 1,
  3. pageSize = 10,
  4. pagetype = 3;
  5. // 搜索框
  6. var $searchbar = $('.searchbar'),
  7. // 搜索输入框
  8. $searchbarInput = $('.searchbar input'),
  9. // 搜索取消按钮
  10. $searchCancelBtn = $('.searchbar-cancel'),
  11. // 搜索框下面悬浮的搜索提示
  12. $searchSuggest = $('#search_suggest_text'),
  13. // 搜索结果展示容器
  14. $searchtResult = $('.div-content');
  15. // 搜索框初始化
  16. $searchbar.addClass("searchbar-active");
  17. // 获取链接带参
  18. var request = GetRequest(),
  19. deptId =request["deptId"] || null;
  20. $(function(){
  21. checkUserAgent();
  22. })
  23. function queryInit(){
  24. initScroller();
  25. getDoctorList(true);
  26. bindEvents();
  27. getTemplateHelper();
  28. }
  29. function getDoctorList(isInit){
  30. d.show();
  31. if(isInit){
  32. page = 1;
  33. }
  34. var url = "patient/consult/doctorList",
  35. params = {
  36. dept: deptId,
  37. page: page,
  38. pagesize: pageSize,
  39. name: $(".inp-search").val()
  40. };
  41. sendPost(url, params, 'JSON', 'GET', queryFailed, function(res){
  42. if(res.status == 200){
  43. d.close();
  44. var list = res.list;
  45. if(list.length>0){
  46. page ++;
  47. var html = template("doc-tmp", {list: list});
  48. if(isInit){
  49. $("#docList").empty().append(html);
  50. }else{
  51. $("#docList").append(html);
  52. }
  53. if(list.length < pageSize){
  54. mui(".mui-scroll-wrapper").pullRefresh().endPullupToRefresh(true);
  55. }else{
  56. mui(".mui-scroll-wrapper").pullRefresh().endPullupToRefresh(false);
  57. }
  58. }else{
  59. if(isInit){
  60. $(".main").hide();
  61. $(".div-no-search-info").show();
  62. mui(".mui-scroll-wrapper").pullRefresh().endPullupToRefresh(true);
  63. }else{
  64. mui(".mui-scroll-wrapper").pullRefresh().endPullupToRefresh(true);
  65. }
  66. }
  67. }else{
  68. queryFailed(res);
  69. }
  70. })
  71. }
  72. function bindEvents(){
  73. //搜索框事件
  74. $(".inp-search").on("input",function(){
  75. var text = $(this).val().trim();
  76. $searchtResult.hide();
  77. showSearchSuggest(text);
  78. if(text){
  79. $searchCancelBtn.show();
  80. $searchCancelBtn.css("opacity","1");
  81. }else{
  82. $searchCancelBtn.hide();
  83. $searchCancelBtn.css("opacity","0");
  84. getDoctorList(true);
  85. }
  86. });
  87. //取消事件
  88. $searchCancelBtn.on('click',function() {
  89. $(this).hide();
  90. $searchSuggest.text('');
  91. $searchSuggest.hide();
  92. $searchtResult.show();
  93. });
  94. $searchSuggest.on('click',function() {
  95. $searchCancelBtn.hide();
  96. $searchCancelBtn.css("opacity","0");
  97. $searchSuggest.hide();
  98. $searchtResult.show();
  99. getDoctorList(true);
  100. });
  101. // 选择科室
  102. $('#select_dept').on('click', function() {
  103. window.location.href = 'hospital-dept.html'
  104. })
  105. // 已关注医生列表
  106. $('#focused').on('click', function() {
  107. window.location.href = 'focused-doctor.html'
  108. })
  109. //单个医生点击
  110. $("#docList").on("tap", "li", function(){
  111. var doctorCode = $(this).attr("data-code");
  112. window.location.href = "doctor-homepage.html?doctor="+doctorCode;
  113. })
  114. }
  115. function getTemplateHelper(){
  116. template.helper("getImgUrl", function(str){
  117. return getImgUrl(str);
  118. });
  119. template.helper("highlightKeyword", function(str){
  120. var kw = $(".inp-search").val(),
  121. reg = new RegExp(kw+"(?!>)","gi"),
  122. html = str.replace(reg,'<em>'+kw+'</em>');
  123. return html;
  124. })
  125. }
  126. function initScroller(){
  127. //阻尼系数
  128. var deceleration = mui.os.ios?0.003:0.0009;
  129. mui('.mui-scroll-wrapper').scroll({
  130. bounce: false,
  131. indicators: true, //是否显示滚动条
  132. deceleration:deceleration
  133. });
  134. mui.ready(function() {
  135. mui(".mui-scroll-wrapper").pullRefresh({
  136. down:{
  137. callback: function(){
  138. getDoctorList(true);
  139. this.endPulldownToRefresh();
  140. }
  141. },
  142. up: {
  143. callback: function() {
  144. var self = this;
  145. setTimeout(function() {
  146. getDoctorList(false);
  147. // self.endPullupToRefresh();
  148. }, 1000);
  149. }
  150. }
  151. });
  152. });
  153. }
  154. function showSearchSuggest(text) {
  155. var suggestText = '搜索“'+text+'”';
  156. // 如果text不为空,则显示;否则隐藏
  157. if(text&&text.trim().length) {
  158. $searchSuggest.text(suggestText);
  159. $searchSuggest.show();
  160. } else {
  161. $searchSuggest.text('');
  162. $searchSuggest.hide();
  163. }
  164. }
  165. //请求失败处理事件
  166. function queryFailed(res, message){
  167. d.close();
  168. if(message){
  169. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content: message}).show();
  170. }else{
  171. if (res && res.msg) {
  172. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:res.msg}).show();
  173. } else {
  174. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'加载失败'}).show();
  175. }
  176. }
  177. }