123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222 |
- var d = dialog({contentType:'load', skin:'bk-popup'});
- var page = 1,
- pageSize = 10,
- pagetype = 3;
- // 搜索框
- var $searchbar = $('.searchbar'),
- // 搜索输入框
- $searchbarInput = $('.searchbar input'),
- // 搜索取消按钮
- $searchCancelBtn = $('.searchbar-cancel'),
- // 搜索框下面悬浮的搜索提示
- $searchSuggest = $('#search_suggest_text'),
- // 搜索结果展示容器
- $searchtResult = $('.div-content');
- // 搜索框初始化
- $searchbar.addClass("searchbar-active");
- // 获取链接带参
- var request = GetRequest(),
- deptId = request["deptId"] || null,
- deptName = decodeURI(request["deptName"]) || "";
-
- $(function(){
- checkUserAgent();
- })
- function queryInit(){
- initScroller();
- if(deptId){
- $(".inp-search").val(deptName);
- }
- getDoctorList(true);
- bindEvents();
- getTemplateHelper();
- }
- function getDoctorList(isInit){
- d.show();
- if(isInit){
- page = 1;
- }
- var url = "patient/consult/doctorList",
- params = {
- dept: deptId,
- page: page,
- pagesize: pageSize,
- name: $(".inp-search").val()
- };
- sendPost(url, params, 'JSON', 'GET', queryFailed, function(res){
- if(res.status == 200){
- d.close();
- var list = res.list;
- if(list.length>0){
- page ++;
- var html = template("doc-tmp", {list: list});
- if(isInit){
- $(".div-content").show();
- $(".div-no-search-info").hide();
- $("#docList").empty().append(html);
- }else{
- $("#docList").append(html);
- }
- if(list.length < pageSize){
- mui(".mui-scroll-wrapper").pullRefresh().endPullupToRefresh(true);
- }else{
- mui(".mui-scroll-wrapper").pullRefresh().endPullupToRefresh(false);
- }
- }else{
- if(isInit){
- $(".div-content").hide();
- $(".div-no-search-info").show();
- mui(".mui-scroll-wrapper").pullRefresh().endPullupToRefresh(true);
- }else{
- mui(".mui-scroll-wrapper").pullRefresh().endPullupToRefresh(true);
- }
- }
- }else{
- queryFailed(res);
- }
- })
- }
- function bindEvents(){
- //搜索框事件
- $(".inp-search").on('compositionstart', function(){
- $(this).prop('comstart', true);
- //console.log('中文输入:开始');
- }).on('compositionend', function(){
- $(this).prop('comstart', false);
- // console.log('中文输入:结束');
- }).on("input",function(e){
- var $this = $(this);
- setTimeout(function(){
- if($this.prop('comstart')) {
- //console.log("true");
- return;
- }
- var text = $this.val().trim();
- $searchtResult.hide();
- showSearchSuggest(text);
- //如果有部门信息
- if(text != deptName){
- deptId = '';
- }
- if(text){
- $searchCancelBtn.show();
- $searchCancelBtn.css("opacity","1");
- }else{
- $searchCancelBtn.hide();
- $searchCancelBtn.css("opacity","0");
- mui(".mui-scroll-wrapper").pullRefresh().refresh(true);
- getDoctorList(true);
- }
- }, 0)
-
- })
-
- //取消事件
- $searchCancelBtn.on('click',function() {
- $(this).hide();
- $searchSuggest.text('');
- $searchSuggest.hide();
- $searchtResult.show();
- });
-
- $searchSuggest.on('click',function() {
- $searchCancelBtn.hide();
- $searchCancelBtn.css("opacity","0");
- $searchSuggest.hide();
- $searchtResult.show();
- getDoctorList(true);
- });
-
- // 选择科室
- $('#select_dept').on('click', function() {
- window.location.href = 'hospital-dept.html'
- })
-
- // 已关注医生列表
- $('#focused').on('click', function() {
- window.location.href = 'focused-doctor.html'
- })
-
- //单个医生点击
- $("#docList").on("tap", "li", function(){
- var doctorCode = $(this).attr("data-code");
- window.location.href = "doctor-homepage.html?doctor="+doctorCode;
- })
- }
- function getTemplateHelper(){
- template.helper("getImgUrl", function(str){
- return getImgUrl(str);
- });
-
- template.helper("highlightKeyword", function(str){
- var kw = $(".inp-search").val(),
- reg = new RegExp(kw+"(?!>)","gi"),
- html = str;
- if(kw){
- html = str.replace(reg,'<em>'+kw+'</em>');
- }
- return html;
- })
- }
- function initScroller(){
- //阻尼系数
- var deceleration = mui.os.ios?0.003:0.0009;
- mui('.mui-scroll-wrapper').scroll({
- bounce: false,
- indicators: true, //是否显示滚动条
- deceleration:deceleration
- });
- mui.ready(function() {
- mui(".mui-scroll-wrapper").pullRefresh({
- down:{
- callback: function(){
- getDoctorList(true);
- this.endPulldownToRefresh();
- }
- },
- up: {
- callback: function() {
- var self = this;
- setTimeout(function() {
- getDoctorList(false);
- // self.endPullupToRefresh();
- }, 1000);
- }
- }
- });
- });
- }
- function showSearchSuggest(text) {
- var suggestText = '搜索“'+text+'”';
- // 如果text不为空,则显示;否则隐藏
- if(text&&text.trim().length) {
- $searchSuggest.text(suggestText);
- $searchSuggest.show();
- } else {
- $searchSuggest.text('');
- $searchSuggest.hide();
- }
- }
- //请求失败处理事件
- function queryFailed(res, message){
- d.close();
- if(message){
- dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content: message}).show();
- }else{
- if (res && res.msg) {
- dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:res.msg}).show();
- } else {
- dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'加载失败'}).show();
- }
- }
-
- }
|