123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429 |
- 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/zhmm-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,"<br/>");
- $("#content_text").html(content);
- var images = data.images?data.images.split(","):[];
- var imgTmp = "";
- for(i=0; i<images.length; i++){
- imgTmp += "<div><img src='"+ getImgUrl(images[i])+"' width='100%'></div>";
- }
- $(".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 +'医生还有<br/>未结束咨询,无法发起新的咨询',
- 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: '对不起,该医生暂时关闭了咨询功能,<br/>暂时无法咨询该医生',
- cancelValue: '我知道了',
- cancel: function () {
- wx.closeWindow();
- }
- }).showModal();
- }else{
- //三师咨询或家庭签约咨询,跳转到新增咨询页面
- window.location.href = "add-consult.html?id=" + id + "&type="+ type +"&doctorCode=" + doctor;
- }
- }else{
- queryFailed(res);
- }
- })
- }
- //未缴费时,判断剩余咨询次数
- function limitZxTimes(){
- //获取剩余家庭咨询次数
- 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();
- }
- }
- }
|