var page = 1;
var pageSize = 1000000;
var d = dialog({contentType:'load', skin:'bk-popup'});
var patientcode ="";
var isSearch = false;
// 搜索框
var $searchbar = $('.searchbar'),
// 搜索输入框
$searchbarInput = $('.searchbar input'),
// 搜索取消按钮
$searchCancelBtn = $('.searchbar-cancel'),
// 搜索框下面悬浮的搜索提示
$searchSuggest = $('#search_suggest_text'),
// 搜索结果展示容器
$searchtResult = $('.div-content');
// 搜索框初始化
$searchbar.addClass("searchbar-active");
var getReqPromise = null;
var scroller1 = null;
$(function(){
//添加isrcoll
scroller1 = new IScrollPullUpDown('wrapper2',{
probeType:2,
bounceTime: 250,
bounceEasing: 'quadratic',
mouseWheel:false,
scrollbars:true,
click:true,
fadeScrollbars:true,
interactiveScrollbars:false
},pullDownAction);
bindEvents();
pageInit();
})
//下拉刷新
function pullDownAction(theScrollerTemp) {
setTimeout(function () {
$(".c-list").html("");
page=1;
pageInit();
}, 1000);
}
//上拉加载数据
function pullUpAction(theScrollerTemp) {
$(".pullUp").show();
setTimeout(function () {
page++;
pageInit();
}, 1000);
}
function pageInit(){
d.show();
var params = {};
params.page = page;
params.pagesize = pageSize;
params.name = $(".inp-search").val();
getReqPromise("patient/consult/famousDoctorList",params).then(function(data){
if(data.status == 200){
var rowData = data.list;
if (rowData.length > 0) {
var listResult = _.map(rowData,function(item,index){
var countClass = "c-74bf00";
var num = item.num || 0;
var expertise = "";
var job_name = "";
var photo = item.photo;
if(!photo){
var photo = "../../../images/noSexDoctor.jpg";
if(item.sex==1){
photo = "../../../images/d-male.png";
}else if(item.sex==2){
photo = "../../../images/d-female.png";
}
}
if(num==0){
countClass = "c-FF6A56";
}
if(item.expertise){
expertise = '
'+
'擅长:'+item.expertise || ""+''+
'
';
}
if(item.job_name.trim()){
job_name = '('+item.job_name+')';
}
var content =''+
''+
'
'+
'
'+
'
'+
'
'+
'
'+
'
'+
'
'+
'
'+
''+item.name+''+
job_name+
'剩余次数:'+num+''+
'
'+
'
'+
''+item.dept_name+''+
''+item.hospital_name+''+
'
'+
'
'+
'
'+
expertise+
'
'+
'';
id = item.id;
return content;
})
$(".c-list").append(listResult);
var kw = $(".inp-search").val();
highlightKeyword(kw);
scroller1.myScroll.refresh();
}else {
if(isSearch){//查询无结果
$(".main").show();
$(".div-content").hide();
$(".div-no-search-info").show();
$(".div-search-content").html("查无数据");
isSearch = false;
}else if(page==1){//page为1的时候证明是第一次加载,第一次加载无数据,显示无数据界面
$(".main").hide();
$(".div-no-search-info").show();
$(".div-search-content").html("今天无名医坐诊哦,请改天再来~");
}else {
dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'无更多数据'}).show();
}
}
} else {
dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:data.msg}).show();
}
d.close();
$(".pullUp").hide();
});
}
function bindEvents(){
$(".c-list").on("click","li",function(){
d.show();
var doctorCode = $(this).attr("data-code");
var docName = $(this).attr("data-name");
sendPost('patient/consult/is_consult_unfinished', {doctor: doctorCode}, 'json', 'post',
function(res){
d.close();
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();
}
}, function(res){
d.close();
if(res.status == 200){
if(res.data == ""){
window.location.href = "mingyi-homepage.html?doctorCode="+doctorCode;
} else {
dialog({
content: '十分抱歉,您与'+ docName +'医生还有
未结束咨询,无法发起新的咨询',
okValue:'前往查看',
ok: function (){
var userAgent = window.localStorage.getItem(agentName);
var userInfo = JSON.parse(userAgent);
var rep = userInfo.represented?userInfo.represented:userInfo.uid;
window.location.href = "consulting-doctor.html?consult=" + res.data +"&toUser="+rep;
},
cancelValue: '我知道了',
cancel: function () {
$(".modal-overlay").trigger("click");
$(".sanshi-icon").removeClass("active");
$(".jiating-icon").removeClass("active");
$(".mingyi-icon").removeClass("active");
return;
}
}).showModal();
}
} else {
dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:res.msg}).show();
}
})
})
// 控制搜索关键字悬浮提示的显示
getReqPromise = function(url, data) {
return new Promise(function(resolve, reject) {
sendPost(url, data, "json", "post",
function queryFailed (req) {
dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'加载失败'}).show();
// TODO 开启示例数据
//resolve({});
}
, function success(req) {
resolve(req);
});
});
}
//取消事件
$searchCancelBtn.on('click',function() {
$(this).hide();
$searchSuggest.text('');
$searchSuggest.hide();
$searchtResult.show();
});
$searchSuggest.on('click',function() {
search();
});
//搜索框事件
$(".inp-search").on("input",function(){
var text = $(this).val().trim();
$searchtResult.hide();
showSearchSuggest(text);
if(text){
$searchCancelBtn.show();
$searchCancelBtn.css("opacity","1");
}else{
$searchCancelBtn.hide();
$searchCancelBtn.css("opacity","0");
search();
}
})
}
var showSearchSuggest = function(text) {
var suggestText = '搜索“'+text+'”';
// 如果text不为空,则显示;否则隐藏
if(text&&text.trim().length) {
$searchSuggest.text(suggestText);
$searchSuggest.show();
} else {
$searchSuggest.text('');
$searchSuggest.hide();
}
},
// 关键字高亮显示
highlightKeyword = function(kw) {
$searchTarget = $('.search-target-text');
$searchTarget.hide();
_.each($searchTarget,function(ele){
var $ele = $(ele),
text = $ele.text(),
reg = new RegExp(kw+"(?!>)","gi"),
html = text.replace(reg,''+kw+'');
$ele.html(html);
});
$searchTarget.show();
},
// TODO搜索框搜索执行方法
search = function () {
$(".div-no-search-info").hide();
isSearch = true;
$searchSuggest.text('');
$searchSuggest.hide();
$searchCancelBtn.hide();
$searchCancelBtn.css("opacity","0");
$searchtResult.show();
$(".c-list").html("");
id=0;
pageInit();
},
// 重置搜索结果的容器高度(为了让滚动条出现在容器内部,而不引起外部内容滚动)
resetResultWrapHeight = function() {
var winHeight = $(window).height(),
diff = 45,
$wrap = $('.div-content');
$wrap.height(winHeight-diff);
},
// 监听窗口大小变化,重置所属区列表、社区列表列表容器高度
resultWrapAutoAdapt = function() {
resetResultWrapHeight();
$(window).on('resize',function() {
resetResultWrapHeight();
});
};