| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330 | var userAgent = window.localStorage.getItem(agentName);var d = dialog({contentType:'load', skin:'bk-popup'});var Request = GetRequest();var openid = Request["openid"];var dataId=null,scroller1=null,articleId='';var pagetype=27;var toUser = Request["toUser"];var toName = decodeURIComponent(Request["toName"]);var represented = Request["represented"];var doctorCode;localStorage.setItem("toUser",toUser);$(function(){	dataId = Request["dataId"];	articleId = Request.articleId;	localStorage.setItem("article",dataId);	article.closeWindow();    if(!userAgent) {        localStorage.setItem("toUser",toUser);        window.location.href = server + "wx/html/home/html/zhmm-login.html?openid=" + openid+"&type="+pagetype;        return false;    }else{        queryInit();    }})function queryInit(){		article.initPage();	}var article={	initPage:function(){		article.initScroll();				var newUaObj = JSON.parse(window.localStorage.getItem(agentName))		//判断关系		function hasFamilyRelation(a,b){			return new Promise(function(resolve, reject) {				var data={					patient:a,					familyMember:b				}				sendPost("patient/family/is_authorize", data, "json", "get", function(res){					dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请求家庭成员关系失败'}).show(); 				}, function(res){					if(res.status == 200) {						window.localStorage.setItem('nowPatientName',res.data.name);						resolve(res)					}else if(res.status == 100) {						dialog({							content:'对不起,'+res.data.name+'未授权给您,如需查看,请切换'+res.data.name+'账号登录',							okValue:'切换账号',							ok: function() {								window.localStorage.setItem(pageName, JSON.stringify({pageurl: location.href}))								window.location.href = "../../grzx/html/change-login.html?type=0&openid="+ Request["openid"];							},							cancelValue: '我不看了',							cancel: function () {								wx.closeWindow();				            }						}).showModal();					}else{						relogin();					}									})			})		}		//重新登录操作		function relogin(){			dialog({				content:'对不起,该消息是发给'+toName+',如需查看,请切换'+toName+'账号登录',				okValue:'切换账号',				ok: function() {					window.localStorage.setItem(pageName, JSON.stringify({pageurl: location.href}))					window.location.href = "../../grzx/html/change-login.html?type=0&openid="+ Request["openid"];				},				cancelValue: '我不看了',				cancel: function () {					wx.closeWindow();	            }			}).showModal();		}		//保存信息		function saveUserInfo(a,b){			Promise.all([hasFamilyRelation(a,b)]).then(function () {				newUaObj.represented = represented;				window.localStorage.setItem(agentName,JSON.stringify(newUaObj));				userAgent = window.localStorage.getItem(agentName);				article.initData();				article.bindEvents();			})		}				function initFamilyData () {			//从微信模板消息进入			if(represented && userAgent && toUser){				if(toUser == represented){					saveUserInfo(represented,newUaObj.uid)				}else if(toUser != represented && represented == newUaObj.uid){					//本人代理					saveUserInfo(represented,newUaObj.uid)				}else if(toUser != represented && toUser == newUaObj.uid){					//需要判定关系 200有授权 100家人 1无关系						saveUserInfo(represented,newUaObj.uid)				}else{					//重新登录						relogin();				}			}else{				article.initData();				article.bindEvents();			}		}		initFamilyData();	},	initData:function(){		d.show();		var params = {};		params.article = dataId;		sendPost("/patient/health/edu/article",params,"JSON","POST",article.queryFailed,article.querySuccess);		}, 	initScroll:function(){		scroller1 =  new IScrollPullUpDown('wrapper1',{			probeType:2,			bounceTime: 250,			bounceEasing: 'quadratic',			mouseWheel:false,			scrollbars:true,			fadeScrollbars:true,			click:true,			interactiveScrollbars:false		},null,null);			function pullDownAction(theScrollerTemp) {			$(".pullDown").show();			$(".pullDownLabel").html("数据刷新中....");				setTimeout(function () {				article.initData();				}, 1000);			}		},queryFailed:function(res){		$(".pullUp,.pullDown").hide();		d.close();		if(res.msg){			dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg,bottom:true}).show(); 		}else{			dialog({contentType:'tipsbox', skin:'bk-popup' , content:'数据加载失败!',bottom:true}).show(); 		}	},querySuccess:function(res){		$(".pullUp,.pullDown").hide();		d.close();		if(res.status==200){			var data = res.data;			var html = template("article_temp",data);			$(".iScroller").html(html);			setTimeout(function(){				scroller1.myScroll.refresh();			},1000);		}else{			if(res.status==-2){				dialog({					content:'对不起,该消息不是您的消息,您无法查看哦~',					okValue:'我知道了',					ok: function() {						wx.closeWindow();					}				}).showModal();			}			article.queryFailed();				}	},closeWindow:function(){		var params = {};		params.pageUrl = window.location.href;		$.ajax(server + "weixin/getSign", {			data: params,			dataType: "json",			type: "post",			success: function(res) {				if(res.status == 200) {					var t = res.data.timestamp;					var noncestr = res.data.noncestr;					var signature = res.data.signature;					wx.config({						//debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。						appId: appId, // 必填,公众号的唯一标识						timestamp: t, // 必填,生成签名的时间戳						nonceStr: noncestr, // 必填,生成签名的随机串						signature: signature, // 必填,签名,见附录1						jsApiList: [								'closeWindow'							] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2					});				}			}		});	},	bindEvents: function() {		$("#zixun").on("click", function () {			article.querySignType();		});	},	querySignType: function() {		d.show();		sendPost('patient/sign_doctors', {}, 'json', 'post', article.querySignTypeFailed, article.querySignTypeSuccess);	},	querySignTypeFailed: 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(); 		}	},	querySignTypeSuccess: function(data) {				if (data.status == 200) {			var doctors = data.familyDoctors;						type = 2;			var docInfo,docQkInfo;			if(doctors.length == 0){			    doctors = data.teamDoctors;			    type = 1;			}			$.each(doctors, function(i, v) {				if(v.teamlevel){					if(v.teamlevel == 3){						docInfo = v;					}					if(v.teamlevel == 2){						docQkInfo = v;					}				}else{					if(v.level == 3){						docInfo = v;					}					if(v.level == 2){						docQkInfo = v;					}				}			});			if(!docInfo){				docInfo = docQkInfo;			}			sendPost('patient/consult/is_consult_unfinished', {doctor: docInfo ? docInfo.code : docQkInfo.code}, '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){										if(res.status == 200){						if(res.data == ""){							checkDocInWork(0, docInfo.code, articleId);						} else {							d.close();							dialog({								    content: '十分抱歉,您与'+ docInfo.name +'医生还有<br/>未结束咨询,无法发起新的咨询',								    okValue:'前往查看',								    ok: function (){									    	var userInfo = JSON.parse(userAgent);								    	var rep = userInfo.represented?userInfo.represented:userInfo.uid;								    	window.location.href = "../../yszx/html/consulting-doctor.html?consult=" + res.data +"&toUser="+rep+"&type="+type+"&doctor="+docInfo.code;								      									    },								    cancelValue: '我知道了',								    cancel: function () {										return;								    }						   	}).showModal();						}					} else {						dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:res.msg}).show();					}				}			);		} else {			article.querySignTypeFailed(res);		}	}}function queryFailed(res){	d.close();	if(res.msg){		dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg,bottom:true}).show(); 	}else{		dialog({contentType:'tipsbox', skin:'bk-popup' , content:'操作失败!',bottom:true}).show(); 	}}function checkDocInWork(type, doctor, id){	sendPost('patient/consult/is_doctor_working', {doctor:doctor}, 'json', 'get', queryFailed, function(res){		if(res.status==200){			d.close();			if(res.data==2){				dialog({				    content: '您好,由于您的签约医生工作繁忙,设置了每日回复咨询的时间段,所以,在该时间段外的时间,您的咨询将不会马上获得医生的回复。',				    okValue:'查看医生工作时间',				    ok: function (){				            						      	window.location.href = "../../yszx/html/doctor-work-hours.html?doctor=" + doctor;				    },				    cancelValue: '继续新增咨询',				    cancel: function () {//						window.location.href = "../../yszx/html/add-consult.html?id=" + id + "&type="+ type +"&doctorCode=" + doctor;	    	   			window.location.href = "../../yszd/html/add-consult.html?id=" + id + "&type="+ type +"&doctorCode=" + doctor+'&fromPage=jkzx';				    }		   		 }).showModal();			}else if(res.data==0){//医生不接受咨询				dialog({				    content: '对不起,该医生暂时关闭了咨询功能,<br/>暂时无法咨询该医生',				    cancelValue: '我知道了',				    cancel: function () {						wx.closeWindow();				    }				}).showModal();			}else{				//三师咨询或家庭签约咨询,跳转到新增咨询页面//				window.location.href = "add-consult.html?id=" + id + "&type="+ type +"&doctorCode=" + doctor;	    	    window.location.href = "../../yszd/html/add-consult.html?id=" + id + "&type="+ type +"&doctorCode=" + doctor+'&fromPage=jkzx';			}		}else{			queryFailed(res);		}				})}template.helper("setPhoto", function(p) {				return getImgUrl(p);});
 |