// TODO 临时构造plus对象,使得能够在浏览器中进行调试 //var plus = null; // 登录者相关信息(包括userAgent) var loginerInfo = null, // 基础环境信息(包括当前webview) baseEnv = null; // 关闭重新登录检查(防止一个ajax error导致所有请求成功无法回调) var checkReload = false; // var isInit = true; var $switchWrap = $('#switch_wrap'), $numSettingWrap = $('#num_setting_wrap'), $timeSettingWrap = $('#time_setting_wrap'), $numSettingSelector = $numSettingWrap.find('.mobi-selector'), $switch = $('#zixunSwitch'), $acceptZiXun = $('#accept_zixun'), $worktimeCell = $("#worktime_cell"), $unsetTip = $('#unset_tip'); // 获取登录相关信息 var getLoginerInfo = function() { // 登录的相关信息 var userAgent = JSON.parse(plus.storage.getItem("userAgent")), // 登录的医生类别 docType = plus.storage.getItem("docType"), // 登录的医生信息 docInfo= JSON.parse(plus.storage.getItem("docInfo")), // 该医生(登录者)所在社区(机构)编码 hospital = plus.storage.getItem("hospital"); return { userAgent: userAgent, docInfo: $.extend(docInfo,{docType:docType},{hospital: hospital}) } }, // 获取基础环境信息 getBaseEnvPromise = function () { var env = { webview: plus&&plus.webview.currentWebview() }; return Promise.resolve().then(function(res) { return env; }); }, // 初始化“接受新的咨询”开关 initSwitch = function() { mui('#zixunSwitch').switch(); }, // 初始化“居民名医咨询次数”下拉列表 initNumSetting = function() { var keys = _.range(100), values = _.map(keys,function(k) { return k+"次"; }); $numSettingSelector.mobiscroll({ theme: 'ios', lang: 'zh', customWheels: true, wheels: [ [{ keys: keys, values: values }] ], onSelect: function(valueText, inst) { var dd = eval("[" + valueText + "]"), name=dd[0].values, currExpenses = dd[0].keys; $(this).val(name); $numSettingSelector.attr("data-code",currExpenses); //保存咨询次数 saveConsultTimesSetting(currExpenses); } }); }, //页面初始化时,检查当前是否接受咨询 isDoctorWorking = function(doctorid){ var url = server+"doctor/work_scheduling/is_doctor_working?doctor="+doctorid; getReqPromise(url,null,"GET").then(function(res){ if(res.status == 200) { var status = res.data.status; if(status && status != 0){ mui('#zixunSwitch').switch(); } } else { console && console.error(res); } }).catch(function(e){ console && console.error(e); }); }, getWorkScheduling = function(){ var url = server+"doctor/work_scheduling/all"; getReqPromise(url,null,"GET").then(function(res){ if(res.status == 200) { var Time=res.data.workTime//时间 var Weeks=res.data.workWeeks//周安排 //名医咨询次数 默认为0 var famousConsultTimes = Time.famousConsultTimes; //是否接受咨询,1为接受 0不接受 var receiveConsult = Time.receiveConsult; if(receiveConsult != 0){ $switch.addClass('mui-active') mui('#zixunSwitch').switch(); $acceptZiXun.show(); // $numSettingWrap.show(); } else { $acceptZiXun.hide(); // $numSettingWrap.hide(); } if(!famousConsultTimes)famousConsultTimes = 0; if(res.data.doctor.isFamous=="1") { // 是名医才显示 // $switchWrap.show(); $numSettingWrap.show(); initNumSetting(); var scroll = $numSettingSelector.mobiscroll('getInst'); var valueText = "{keys:'"+famousConsultTimes+"',values:'"+famousConsultTimes + "次"+"'}"; scroll.setVal([valueText]); $numSettingSelector.val(famousConsultTimes + "次"); $numSettingSelector.attr("data-code",famousConsultTimes); } else { $acceptZiXun.show(); $numSettingWrap.hide(); //非名医,只有专科可以这是是否接受咨询 if(res.data.doctor.level == 1){ // $switchWrap.show(); } } // 没设置工作时间,则隐藏工作计划表 if(!Time || !(Time.morningBegin || Time.morningEnd || Time.afternoonBegin || Time.afternoonEnd || Time.nightBegin || Time.nightEnd )) { // $timeSettingWrap.find('.cycworktime').hide(); $unsetTip.show() $worktimeCell.hide(); } else { // $timeSettingWrap.find('.cycworktime').show(); $unsetTip.hide() $worktimeCell.show(); } if(Time.length!=0){//查询成功有数据 // $($(".work .c-list-value i")[0]).html(Time.morningBegin); // $($(".work .c-list-value i")[1]).html(Time.morningEnd); // $($(".work .c-list-value i")[2]).html(Time.afternoonBegin); // $($(".work .c-list-value i")[3]).html(Time.afternoonEnd); // $($(".work .c-list-value i")[4]).html(Time.nightBegin); // $($(".work .c-list-value i")[5]).html(Time.nightEnd); $.each(Weeks,function(i,v){ var obj=$(".cycworktime tr[data-fl="+v.week+"]"); if(v.morning=="1"){ // obj.find("td[data-type='1']").addClass("on"); obj.find("td[data-type='1']").html(Time.morningBegin+"~"+Time.morningEnd); } if(v.afternoon=="1"){ // obj.find("td[data-type='2']").addClass("on"); obj.find("td[data-type='2']").html(Time.afternoonBegin+"~"+Time.afternoonEnd); } if(v.night=="1"){ // obj.find("td[data-type='3']").addClass("on"); obj.find("td[data-type='3']").html(Time.nightBegin+"~"+Time.nightEnd); } }); } } else { console && console.error(res); } }).catch(function(e){ console && console.error(e); }); } , saveConsultTimesSetting = function(consultTimes){ var url = server+"/doctor/work_scheduling/consult_times_setting?consultTimes="+consultTimes; getReqPromise(url,null,"GET").then(function(res){ if(res.status == 200) { mui.toast("设置成功"); } else { mui.toast(""+res.msg); } }).catch(function(e){ console && console.error(e); }); }, // 绑定页面事件 bindEvents = function () { $switch[0].addEventListener("toggle",function(event){ var url = server+"/doctor/work_scheduling/receive_consult_setting"; var params = { receiveConsult: event.detail.isActive ? 1 : 0 }; //页面初始化时,不提交到后台。 // if(isInit){ // isInit = false; // return; // } getReqPromise(url,params).then(function(res){ if(res.status == 200) { $acceptZiXun.toggle(event.detail.isActive); mui.toast("设置成功"); } else { mui.toast("设置失败"); console && console.error(res); } }).catch(function(e){ console && console.error(e); }); }) }; // 页面业务处理流程开始 new Promise(function(resolve, reject) { // TODO 临时放开 //resolve(true); mui.plusReady(function() { // plus已经准备好,可以往下执行 resolve(true); }); }).then(function() { // 获取基础环境信息 return getBaseEnvPromise().then(function(env) { baseEnv = env; }).then(function() { // TODO 防止因为其它ajax error导致存在isLoginOut标识,所有请求回调无法执行的问题 window.localStorage.removeItem("isLoginOut"); // 获取登录医生信息 loginerInfo = getLoginerInfo(); // TODO Switch需等到plusReady触发之后才能初始化,为了测试所以使用setTimeout延迟执行 //setTimeout(function() { // initSwitch(); //},0); // 绑定页面事件 bindEvents(); }) .then(function(){ //读取医生的当前是否接受咨询的设置状态 //var doctorid = loginerInfo.docInfo.code; //isDoctorWorking(doctorid); getWorkScheduling(); }) }).catch(function(e) { plus.nativeUI.closeWaiting(); console && console.error(e); });