select-consult-doctor.js 5.8 KB

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