select-consult-doctor-fare.js 6.5 KB

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