var d = dialog({ contentType: 'load', skin: 'bk-popup' }); var pagetype = 0; var userAgent = window.localStorage.getItem(agentName); var Request = new Object(); Request = GetRequest(); //这个页面兼作为绑卡成功后的回调页面,所以在此将url中的参数缓存起来 window.localStorage.setItem('request_info', JSON.stringify(Request)); var toUser = Request["toUser"]; var toName = decodeURIComponent(Request["toName"]); var represented = Request["represented"]; var openid = Request["openid"]; var newUaObj = JSON.parse(window.localStorage.getItem(agentName)) var signInfo; $(function(){ //判断接收者是否是本人 if(!userAgent) { window.location.href = server + "wx/html/home/html/zhmm-login.html?openid=" + openid+"&type="+pagetype; return false; } //判断是否可以在线支付 if(!canPayOnline){ var param = window.location.search; window.location.replace(server +"wx/html/ssgg/html/doctor-homepage-new.html"+param); return false; } initFamilyData(); }); 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{ userInfo = JSON.parse(window.localStorage.getItem(agentName)); bindEvents(); checkStatus(); } } //保存信息 function saveUserInfo(a,b){ Promise.all([hasFamilyRelation(a,b)]).then(function () { newUaObj.represented = represented; window.localStorage.setItem(agentName,JSON.stringify(newUaObj)); userInfo = JSON.parse(window.localStorage.getItem(agentName)); getSignInfo(); }) } //重新登录操作 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 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 getSignInfo(){ d.show(); var url = "/patient/sign/signInfo", params ={code: Request['signCode']}; sendPost(url, params, 'JSON', 'get', queryFailed, function(res){ if(res.status == 200){ signInfo = res.data; if(signInfo.expensesStatus == 1){ d.close(); //已缴费,跳转去缴费结果页面 var payParams = { code: signInfo.code, teamCode: signInfo.teamCode, type: signInfo.type, doctorHealth: signInfo.doctor, status: signInfo.status, renew: signInfo.isRenew, exstatus: signInfo.expensesStatus, payCode: signInfo.payCode, showResult: true //标记直接根据交易码获取缴费信息,区别在线支付回调 }; payParams = JSON.stringify(payParams); window.localStorage.setItem("payParams",payParams); //删除缓存的链接参数 window.localStorage.removeItem('request_info'); window.location.href = 'pay_result.html'; }else{ //未缴费,判断是否绑卡 checkBindStatus(); } }else{ queryFailed(res); } }); } //判断是否有绑卡 function checkBindStatus(){ var url = "/patient/bindCard"; sendPost(url, {}, 'json', 'post', queryFailed, function(res){ d.close(); if(res.data.bindStatus == '000000'){ //已绑卡 //跳转去支付页面 //先获取缴费金额信息,然后再组装支付信息 charge(); }else if(res.data.bindStatus == '030007'){//未绑卡 d.close(); //跳转去绑卡链接 var bindUrl = res.data.sicardUrl; window.location.href = bindUrl; } }); } //发起缴费申请 function charge(){ var url = "/patient/charge", params = { orgCode: signInfo.hospital, chargeType: 1, //签约类型 chargeRelation: signInfo.code, //签约的code totalAmount: 12000 //固定值 }; sendPost(url, params, 'json', 'post', queryFailed, function(res){ d.close(); if(res.status == 200){ //跳转去缴费页面 window.location.href = res.data; }else{ queryFailed(res); } }); } function queryFailed(res){ d.close(); if(res && res.msg) { dialog({ contentType: 'tipsbox', skin: 'bk-popup', content: res.msg }).show(); } else { dialog({ contentType: 'tipsbox', skin: 'bk-popup', content: '加载失败' }).show(); } }