var d = dialog({contentType:'load', skin:'bk-popup', content:''}); var userAgent = localStorage.getItem(agentName); var patient, doctor, healthDoctor, doctorName, healthDoctorName; var doctors = []; var request = GetRequest(); var changeDoctor = request.changeDoctor; //标记是否是从医生发起的模板消息 var request = GetRequest(); var signStatus = request.signStatus; var isSignLimit = false; //判断签约人数是否达到上限 if(userAgent){ userAgent = JSON.parse(userAgent); patient = userAgent.represented?userAgent.represented:userAgent.uid; } $(function() { // var referrer = document.referrer; getSignMessage(); $('#agree_btn').on('click',function() { //判断当前时间是否在2017年度 // var date = new Date(); // if(date.getFullYear() != 2017){ // dialog({ // content: "对不起,2017年度续签工作已结束,无法发起续签工作", // okValue: "我知道了", // ok: function(){} // }).showModal(); // return false; // }else{ // if(referrer.indexOf("xuqian/html/information.html") == -1){ checkRenewEnable(); // }else{ // showDialogInfo(signStatus); // } // } }); $("#changeDoctor").on("click", function(){ window.localStorage.setItem("is_renew", "1"); window.location.href = "../../qygl/html/select-doctor.html?renew=1"; }); }); function checkRenewEnable(){ //判断是否可以续签 var url = "/patient/family_contract/checkCanRenew", params = {patient: userAgent.represented?userAgent.represented:userAgent.uid}; d.show(); sendPost(url, params, "json", "post", reqFailed , function(res){ if(res.status == 200){ d.close(); var code = res.data.code, msg = res.data.mes, enable = true; switch (parseInt(code)){ case -5: msg = "医生已同意您的续签,您无需再次签约"; enable = false; break; case -4: msg = "您当前无可续签的家庭医生,可在签约管理页面签约医生"; enable = false; break; case -3: //已经提交续签申请了 msg = "您已提交过申请,无需重复提交"; enable = false; break; case -2: msg = "您已完成2017~2018年度签约,不能再次签约"; enable = false; break; case -1: msg = "当前时间段不允许续签,可前往签约管理页面签约医生"; enable = false; break; case 0: msg = "患者数据有误"; enable = false; break; } if(!enable){ if(code == "-4" || code == "-1"){ dialog({ content: msg, okValue: "我知道了", ok: function(){ location.href = "../../qygl/html/signing_management.html"; } }).showModal(); }else{ dialog({ content: msg, okValue: "我知道了", ok: function(){ } }).showModal(); } }else{ showDialogInfo(code); } }else{ reqFailed(res); } }); } //弹框信息 function showDialogInfo(status){ if(status == 1){ if(parseInt(changeDoctor)){ if(isSignLimit){ dialog({ content: doctors.join("、")+"医生签约人数已达上限,请重新选择签约医生", okValue: "选择其他医生", ok: function(){ window.localStorage.setItem("is_renew", "1"); window.location.href = "../../qygl/html/select-doctor.html?renew=1"; }, cancelValue: "我再看看", cancel: function(){} }).showModal(); }else{ dialog({ content: "是否向"+doctors.join("、")+"提交续签申请?提交后无法变更", okValue: "立即提交", ok: function(){ var renew = window.localStorage.getItem("is_renew"); if(renew){ window.localStorage.setItem("is_renew", "0"); } renewSign(); }, cancelValue: "我再看看", cancel: function(){} }).showModal(); } }else{ var content = ""; if(isSignLimit){ content = doctors.join("、")+"医生签约人数已达上限,请重新选择签约医生"; $("#renewSign").hide(); }else{ content = "是否向"+doctors.join("、")+"提交续签申请?提交后无法变更"; } $("#remind-msg").text(content); mui('#sheet1').popover('toggle'); } } if(status == 2){ //签约过期的患者 getOverdueSignMessage(); } } /*获取签约信息*/ function getSignMessage(){ d.show(); var url = "/patient/family_contract/getSignMessage", params = {patientCode: patient}; sendPost(url, params, "json", "post", reqFailed, function(res){ if(res.status == 200){ d.close(); var len = res.list.length; for(i=0; i< len; i++){ var item = res.list[i]; if(item.level == 2){ doctor = item.code; doctorName = item.name; } if(item.level == 3){ healthDoctor = item.code; healthDoctorName = item.name; } } if(doctorName){ doctors.push(doctorName); } if(healthDoctorName){ doctors.push(healthDoctorName); } if(doctor){ getDoctorInfo(); } }else{ reqFailed(res); } }); } //获取已过期的签约信息 function getOverdueSignMessage(){ var url = "/patient/family_contract/getSignMessageOverdue", params = {patientCode: patient}; d.show(); sendPost(url, params, "json", "get", reqFailed, function(res){ if(res.status == 200){ d.close(); var len = res.list.length; for(i=0; i< len; i++){ var item = res.list[i]; if(item.level == 2){ doctor = item.code; doctorName = item.name; } if(item.level == 3){ healthDoctor = item.code; healthDoctorName = item.name; } } if(doctorName){ doctors.push(doctorName); } if(healthDoctorName){ doctors.push(healthDoctorName); } getDoctorInfo(function(){ if(parseInt(changeDoctor)){ if(isSignLimit){ dialog({ content: doctors.join("、")+"医生签约人数已达上限,请重新选择签约医生", okValue: "选择其他医生", ok: function(){ window.localStorage.setItem("is_renew", "1"); window.location.href = "../../qygl/html/select-doctor.html?renew=1"; }, cancelValue: "我再看看", cancel: function(){} }).showModal(); }else{ dialog({ content: "是否向"+doctors.join("、")+"提交续签申请?提交后无法变更", okValue: "立即提交", ok: function(){ var renew = window.localStorage.getItem("is_renew"); if(renew){ window.localStorage.setItem("is_renew", "0"); } renewSign(); }, cancelValue: "我再看看", cancel: function(){} }).showModal(); } }else{ var content = ""; if(isSignLimit){ content = doctors.join("、")+"医生签约人数已达上限,请重新选择签约医生"; $("#renewSign").hide(); }else{ content = "是否向"+doctors.join("、")+"提交续签申请?提交后无法变更"; } $("#remind-msg").text(content); mui('#sheet1').popover('toggle'); } }); }else{ reqFailed(res); } }); } //获取医生是否签约达到上限 function getDoctorInfo(cb){ var url = 'family_contract/homepage/homepage', data = {doctor: doctor}; sendPost(url, data, 'json', 'post', reqFailed, function(res){ if(res.status == 200){ //判断签约人数是否达到上限 if(res.data.signTotal >= res.data.limitTotal){ isSignLimit = true; } if(cb && (typeof cb == "function")){ cb(); } }else{ reqFailed(res); } }); } //续签 function renewSign(){ var url = "/patient/family_contract/signRenew", params = { doctor: doctor || "", healthDoctor: healthDoctor || "", patient: patient }; d.show(); sendPost(url, params, "json", "post", reqFailed, function(res){ if(res.status == 200){ d.close(); window.location.href = "../../qygl/html/signing_management.html"; }else{ reqFailed(res); } }) } function reqFailed(res){ d.close(); if(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 notSignFlow(){ dialog({ content: "您当前未签约家庭医生,是否前往签约家庭医生?", okValue: "签约家庭医生", ok: function(){ location.href = "../../qygl/html/select-doctor.html"; }, cancelValue: "不了,谢谢", cancel: function(){} }).showModal(); } function preSignedFlow(){ dialog({ content: "您已完成2017~2018年度预签约,不能再次签约", okValue: "我知道了", ok:{} }).showModal(); }