select-consult-doctor.js 6.4 KB

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