select-consult-doctor.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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. if($(this).prop('comstart')) {
  82. //console.log("true");
  83. return;
  84. }
  85. var text = $(this).val().trim();
  86. $searchtResult.hide();
  87. showSearchSuggest(text);
  88. //如果有部门信息
  89. if(text != deptName){
  90. deptId = '';
  91. }
  92. if(text){
  93. $searchCancelBtn.show();
  94. $searchCancelBtn.css("opacity","1");
  95. }else{
  96. $searchCancelBtn.hide();
  97. $searchCancelBtn.css("opacity","0");
  98. mui(".mui-scroll-wrapper").pullRefresh().refresh(true);
  99. getDoctorList(true);
  100. }
  101. }).on('compositionstart', function(){
  102. $(this).prop('comstart', true);
  103. //console.log('中文输入:开始');
  104. }).on('compositionend', function(){
  105. $(this).prop('comstart', false);
  106. // console.log('中文输入:结束');
  107. })
  108. //取消事件
  109. $searchCancelBtn.on('click',function() {
  110. $(this).hide();
  111. $searchSuggest.text('');
  112. $searchSuggest.hide();
  113. $searchtResult.show();
  114. });
  115. $searchSuggest.on('click',function() {
  116. $searchCancelBtn.hide();
  117. $searchCancelBtn.css("opacity","0");
  118. $searchSuggest.hide();
  119. $searchtResult.show();
  120. getDoctorList(true);
  121. });
  122. // 选择科室
  123. $('#select_dept').on('click', function() {
  124. window.location.href = 'hospital-dept.html'
  125. })
  126. // 已关注医生列表
  127. $('#focused').on('click', function() {
  128. window.location.href = 'focused-doctor.html'
  129. })
  130. //单个医生点击
  131. $("#docList").on("tap", "li", function(){
  132. var doctorCode = $(this).attr("data-code");
  133. window.location.href = "doctor-homepage.html?doctor="+doctorCode;
  134. })
  135. }
  136. function getTemplateHelper(){
  137. template.helper("getImgUrl", function(str){
  138. return getImgUrl(str);
  139. });
  140. template.helper("highlightKeyword", function(str){
  141. var kw = $(".inp-search").val(),
  142. reg = new RegExp(kw+"(?!>)","gi"),
  143. html = str;
  144. if(kw){
  145. html = str.replace(reg,'<em>'+kw+'</em>');
  146. }
  147. return html;
  148. })
  149. }
  150. function initScroller(){
  151. //阻尼系数
  152. var deceleration = mui.os.ios?0.003:0.0009;
  153. mui('.mui-scroll-wrapper').scroll({
  154. bounce: false,
  155. indicators: true, //是否显示滚动条
  156. deceleration:deceleration
  157. });
  158. mui.ready(function() {
  159. mui(".mui-scroll-wrapper").pullRefresh({
  160. down:{
  161. callback: function(){
  162. getDoctorList(true);
  163. this.endPulldownToRefresh();
  164. }
  165. },
  166. up: {
  167. callback: function() {
  168. var self = this;
  169. setTimeout(function() {
  170. getDoctorList(false);
  171. // self.endPullupToRefresh();
  172. }, 1000);
  173. }
  174. }
  175. });
  176. });
  177. }
  178. function showSearchSuggest(text) {
  179. var suggestText = '搜索“'+text+'”';
  180. // 如果text不为空,则显示;否则隐藏
  181. if(text&&text.trim().length) {
  182. $searchSuggest.text(suggestText);
  183. $searchSuggest.show();
  184. } else {
  185. $searchSuggest.text('');
  186. $searchSuggest.hide();
  187. }
  188. }
  189. //请求失败处理事件
  190. function queryFailed(res, message){
  191. d.close();
  192. if(message){
  193. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content: message}).show();
  194. }else{
  195. if (res && res.msg) {
  196. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:res.msg}).show();
  197. } else {
  198. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'加载失败'}).show();
  199. }
  200. }
  201. }