Request = GetRequest(); var d = dialog({contentType:'load', skin:'bk-popup'}); var id = Request["id"]; var photo = Request["photo"]; var toUser = Request["toUser"]; var openid = Request["openid"]; var toName = decodeURIComponent(Request["toName"]); var represented = Request["represented"]; var pagetype=25; var type; var doctorCode; var userAgent = window.localStorage.getItem(agentName); var expensesStatus; //标记缴费状态 $(function(){ if(!userAgent) { localStorage.setItem("toUser",toUser); localStorage.setItem("id",id); window.location.href = server + "wx/html/home/html/login.html?openid=" + openid+"&type="+pagetype; return false; } 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); queryInit(); // 点击咨询详情 $("#detail").on("tap", function () { querySignType(); }); }) } 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{ queryInit(); // 点击咨询详情 $("#detail").on("tap", function () { querySignType(); }); } } initFamilyData(); }); /** * 界面数据初始化 */ function queryInit() { d.show(); var data = {}; data.id = id; sendPost("patient/health/guidance/id", data, "json", "post", queryListFailed, queryAppoListSuccesss); getPatientInfo(); } function queryListFailed(res) { d.close(); if (res && res.msg) { var d1 = dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:res.msg}); } else { var d2 = dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'加载失败'}); } } function queryAppoListSuccesss(res) { if (res.status == 200) { var data = res.data; if (data) { doctorCode = data.doctor; // type = data.del; window.localStorage.setItem("guidance",data.content); var regN = /\n/g; var regRN = /\r\n/g; var content = data.content.replace(/ /g, " "); content = content.replace(regN,"
"); $("#content_text").html(content); var images = data.images?data.images.split(","):[]; var imgTmp = ""; for(i=0; i"; } $(".main").append(imgTmp); } d.close(); } else { //非200则为失败 queryListFailed(res); } } function getPatientInfo(){ //先获取患者缴费信息,然后未缴费的需要判断是否已经达到咨询上线 sendPost('patient/baseinfo', {}, 'json', 'post', queryFailed, function(res){ if(res.status == 200){ expensesStatus = res.data.expensesStatus; }else{ queryFailed(res); } }) } function querySignType(){ //判断该居民是否已经缴费 1为已经交费 ""没有签约信息 "0"未扣费 "1"已扣费 "2"已退费 if(expensesStatus == 1){ querySignType2(); }else{ limitZxTimes(); } } function querySignType2(){ d.show(); sendPost('patient/sign_doctors', {}, 'json', 'post', querySignTypeFailed, querySignTypeSuccess); } function querySignTypeFailed(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 querySignTypeSuccess(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 == ""){ //不存在 // window.location.href = "add-consult.html?id=" + id + "&type=0&doctorCode=" + doctorCode; checkDocInWork(0, doctorCode, id); } else { d.close(); dialog({ content: '十分抱歉,您与'+ docInfo.name +'医生还有
未结束咨询,无法发起新的咨询', okValue:'前往查看', ok: function (){ var userInfo = JSON.parse(userAgent); // if(type == "2"){ //家庭签约 // window.location.href = "" // }else{//三师签约 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 { querySignTypeFailed(res); } } 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 = "add-consult.html?id=" + id + "&type="+ type +"&doctorCode=" + doctor; } }).showModal(); }else if(res.data==0){//医生不接受咨询 dialog({ content: '对不起,该医生暂时关闭了咨询功能,
暂时无法咨询该医生', cancelValue: '我知道了', cancel: function () { wx.closeWindow(); } }).showModal(); }else{ //三师咨询或家庭签约咨询,跳转到新增咨询页面 window.location.href = "add-consult.html?id=" + id + "&type="+ type +"&doctorCode=" + doctor; } }else{ queryFailed(res); } }) } //未缴费时,判断剩余咨询次数 function limitZxTimes(){ window.location.href = "../../qygl/html/signing_management.html"; //获取剩余家庭咨询次数 // var url = '/patient/consult/remainConsultTimes'; // var remainTimes;//剩余咨询次数 // var countTimes;//总咨询次数 // var zxTimes;//已咨询次数 // d.show(); // sendPost(url, {}, 'json', 'get', queryFailed, function(res){ // if(res.status == 200){ // d.close(); // remainTimes = res.data.amount; // countTimes = res.data.count; // zxTimes = countTimes - remainTimes; // if(zxTimes == countTimes){ // //未缴费的总咨询次数已达上限 提示去缴费 // dialog({ // content: '您本年度家庭医生签约暂未缴费,当前10次免费健康咨询已全部使用.如果需要家庭医生继续为您提供服务,请尽快完成缴费操作', // okValue:'前往缴费', // ok: function (){ // window.location.href = "../../qygl/html/signing_management.html"; // } // }).showModal(); // }else{ // dialog({ // content: '您本年度家庭医生签约暂未缴费,可使用10次免费健康咨询,当前剩余:'+remainTimes+'次.为避免影响您的服务体验,请尽快完成缴费操作', // okValue:'前往缴费', // ok: function (){ // window.location.href = "../../qygl/html/signing_management.html"; // }, // cancelValue: '开始咨询', // cancel: function () { // querySignType2(); // } // }).showModal(); // } // }else{ // queryFailed(res); // } // }); } //查询失败 function queryFailed(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 payCost() { var url = "/patient/consult/remainConsultTimes", params = {}; sendPost(url, params, "json", "get", queryFailed, function(res) { if(expensesStatus == 1) { querySignType(2); } else { if(expensesStatus == 0) { if(res.status == 200) { if(res.data > 0) { dialog({ content: "您本年度家庭医生签约暂未缴费,可使用10次免费健康咨询,当前剩余:" + res.data + "次.为避免影响您的服务体验,请尽快完成缴费操作", cancelValue: '前往缴费', cancel: function() { window.location.href = "../../qygl/html/signing_management.html?id" }, okValue: '开始咨询', ok: function() { querySignType(); // window.location.href = "../../yszx/html/add-consult.html?type=" + request.type + "&doctorCode=" + request.doctor; }, }).showModal() } else { dialog({ content: "您本年度家庭医生签约暂未缴费,当前10次免费健康咨询已全部使用.为避免影响您的服务体验,请尽快完成缴费操作", cancelValue: '前往缴费', cancel: function() { window.location.href = "../../qygl/html/signing_management.html?id" }, }).showModal() } } else { queryFailed(res) } } if(expensesStatus == 2) { } } }) } //请求失败处理事件 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(); } } }