select-consult-doctor.js 5.6 KB

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