var d = dialog({contentType:'load', skin:'bk-popup'});
$(function(){
var doctorInfo;
var request = GetRequest();
var hospitalId =request["hospitalId"];
var hosDeptId = request["hosDeptId"];
var doctorId = request["doctorId"];
initData();
bindEvents();//注册事件
function initData(){
d.show();
getDoctorInfo();
}
function getDoctorInfo(){
var params ={};
params.city="350200";
params.doctorId = doctorId;
params.hospitalId = hospitalId;
params.hosDeptId = hosDeptId;
sendPost("third/guahao/GetDoctorInfo",params,"JSON","POST",queryFailed,queryDoctorSuc);
}
function getDocWorkTimeInfo(){
var params ={};
params.city="350200";
params.doctorId = doctorId;
params.hospitalId = hospitalId;
params.hosDeptId = hosDeptId;
sendPost("third/guahao/GetDoctorArrange",params,"JSON","POST",queryFailed,queryWorkTimeSuc);
}
function queryFailed(res){
d.close();
if (res && res.msg) {
if((res.msg).indexOf("SOAP")>=0){
dialog({contentType:'tipsbox', skin:'bk-popup' , content:"医院接口访问异常,请刷新后重试!",bottom:true}).show();
return false;
}
dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg,bottom:true}).show();
} else {
dialog({contentType:'tipsbox', skin:'bk-popup' , content:'加载失败',bottom:true}).show();
}
}
function queryDoctorSuc(res){
d.close();
if(res.status==200){
showDocInfo(res.data);
}else{
queryFailed(res);
}
}
function queryWorkTimeSuc(res){
if(res.status==200){
showWorkTimeList(res.data);
}else{
queryFailed(res);
}
}
function showDocInfo(data){
$("#name").html(data.name);
$("#jobName").html(data.title);
$("#hospitalName").html(data.hospitalName);
$("#introduce").html(data.introduce);
if(data.sex==2){
$("#photo").attr("src","../../../images/d-female.png");
}else{
$("#photo").attr("src","../../../images/d-male.png");
}
doctorInfo = data;
getDocWorkTimeInfo();
}
function showWorkTimeList(data){
var timeList = "";
for(var j in data){
var detail = data[j];
var dateTime = detail.date+"";
var date= dateTime.split(" ")[0];
var week = getWeek(date);
var riqi = date.split("-");
riqi = riqi[1]+"-"+riqi[2];
var used = detail.used;
var max = detail.max;
var isMo = detail.time;
if(isMo =="a"){
isMo ="上午";
}else{
isMo ="下午";
}
var status = detail.status;
var statusHtml ="";
if(status==2){
statusHtml= '
';
}else{
statusHtml= '';
}
var liHtml = appendLi(detail);
var titleColor = 'c-323232';
if(detail.regType != undefined){
if(detail.regType.indexOf('vip')>-1 || detail.regType.indexOf('VIP')>-1 || detail.fee == '300'){
titleColor = 'c-FF9526';
}
}else{
if(detail.fee == '300'){
titleColor = 'c-FF9526';
detail.regType = "VIP门诊";
}else{
detail.regType = "普通门诊";
}
}
timeList+= ''+
'
'+
'
'+
'
'+
'
'+
'
'+
date+
'
'+
'
'+
week+" "+isMo+
'
'+
'
'+
'
'+
'
'+
detail.regType +
'
'+
'
'+
'诊查费:'+detail.fee+'元'+
'
'+
'
'+
'
'+
statusHtml+
'
'+
'
'+
'
'+
'
'+
'
'+
'
'+
'
';
}
$("#tice_list").append(timeList);
init();//页面初始化
}
function appendLi(detail){
var sections = detail.sections;
var liHtml = "";
for(var j in sections){
var data = sections[j];
if(j%3==0){
if(j!=0){
liHtml+='';
}
liHtml+='';
}
var start = data.startTime;
var end = data.endTime;
var max = data.max;
var used = data.used;
var clazz = "div-time-enable";
if(max==used){
clazz = "div-time-disable";
}
liHtml+=''+getTime(start)+"-"+getTime(end)+'
';
if(j==(sections.length-1)){
liHtml+='';
}
}
return liHtml;
}
function getWeek(d){
var dateArray = d.split("/");
var year = dateArray[0], month = dateArray[1], date = dateArray[2];
var dt = new Date(year, month-1, date);
var weekDay = ["周天", "周一", "周二", "周三", "周四", "周五", "周六"];
return weekDay[dt.getDay()]
}
function getTime(dateTime){
var tempStrs = dateTime.split(" ");
var timeStrs = tempStrs[1].split(":");
var hour = timeStrs [0];
var minute = timeStrs [1];
var second = timeStrs [2];
return hour+":"+minute;
}
function init(){
var request = GetRequest();
var type = request["type"] || "";
var id = decodeURIComponent(request["id"]);
if(type==1 || type==""){//显示医生简介
$("#doctorLi").addClass("hit");
$(".div-doctor-info").show();
}else{//显示门诊预约
$("#deptyuyueLi").addClass("hit");
$(".div-dept-info").show();
}
if($('.member-sel[data-id='+id+']').length>0){
$('.member-sel[data-id='+id+']').siblings("ul").removeClass("c-hide");
$('.member-sel[data-id='+id+']').find(".arrow-shou").addClass("active");
var offset = $('.member-sel[data-id='+id+']').offset();
window.scrollTo(offset.left,offset.top);
}
}
function bindEvents(){
//分组展开收起
$(".div-dept-info").on('click', '.member-sel', function() {
if(!$(this).siblings("ul").hasClass("c-hide")){
$(this).find(".arrow-shou").removeClass("active");
$(this).siblings("ul").addClass("c-hide");
}else{
$(".member-list").addClass("c-hide");
$(".member-sel").find(".arrow-shou").removeClass("active");
$(this).siblings("ul").removeClass("c-hide");
$(this).find(".arrow-shou").addClass("active");
}
});
$(".pt-tab").on("click","li",function(){
var activeId = $(this).attr("id");
$(".pt-tab li").removeClass("hit");
$(this).addClass("hit");
if(activeId=="doctorLi"){//医生简介
$(".div-doctor-info").show();
$(".div-dept-info").hide();
}else{//门诊预约
$(".div-doctor-info").hide();
$(".div-dept-info").show();
}
})
$(".div-dept-info").on("click",".div-time-enable",function(){
$(".div-time-enable").removeClass("active");
$(this).addClass("active");
var arrangeDate = $(this).attr("data-attr");
window.localStorage.setItem("arrangeDate",arrangeDate);
window.localStorage.setItem("doctorInfo",JSON.stringify(doctorInfo));
location.href = "https://open.weixin.qq.com/connect/oauth2/authorize?appid="+appId+"&redirect_uri="+wxurl+"%2fwdyy%2fhtml%2finfo-confirm.html&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect";
// location.href = "info-confirm.html";
});
}
});