select-consult-doctor.js 6.3 KB

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