// TODO 医生示例数据 //var doctorData = {"msg":"查询成功",data:{"id":"3502050100","consult":"",patient:"P123",photo:"",jobName:"主任医师",expertise:"中医内科疾病",introduce:"无",deptName:"骨科",hospitalName:"厦门市第一医院",title:"",name:"张敏敏",age:23,comment:"激光治疗红血丝治疗部位保持清洁,避免感染和摩擦;部位有痂皮的会自行脱落,不要手动进行抠除。",star:3,type:5,time:"2016-09-12 16:49:17",status:"",sex:0,doctorRead:""},"status":200}; var doctorData = null; // TODO 临时构造plus对象,使得能够在浏览器中进行调试 //var plus = null; // 基本信息(包括userAgent、上个页面传递的数据) var baseInfo = null, // 基础环境信息(包括当前webview) baseEnv = null; // 医生code var doctorCode = ""; var $baseInfoWrapper = $('#base_info_wrap'), $mingyiRoleWrapper = $('[data-role="mingyi"]'), $qitaRoleWrapper = $('[data-role="qitayisheng"]'), $cycworktime = $('.cycworktime'); // 获取基本信息(包括userAgent、上个页面传递的数据) var getBaseInfoPromise = function() { // 登录的相关信息 var userAgent = plus && JSON.parse(plus.storage.getItem("userAgent")) return { userAgent: userAgent, // 上一个页面传递的数据 accessData: baseEnv.webview.accessData } }, // 获取基础环境信息 getBaseEnvPromise = function () { var webview = plus.webview.currentWebview(); var env = { webview: webview, // 点击“返回”的webveiw的id(由上一个页面传递) backTo: webview.backTo }; return Promise.resolve().then(function(res) { return env; }); }, getBeginTime = function (w) { var morning = (w.morning === "1")?true:false, afternoon = (w.afternoon === "1")?true:false, night = (w.night === "1")?true:false, beginTime = "8:30"; if(morning) { beginTime = w.morningBegin; }else if(afternoon) { beginTime = w.afternoonBegin; } else if (night) { beginTime = w.nightBegin; } return beginTime; }, getEndTime = function (w) { var morning = (w.morning === "1")?true:false, afternoon = (w.afternoon === "1")?true:false, night = (w.night === "1")?true:false, endTime = "18:00"; if(night) { endTime = w.nightEnd; }else if(afternoon) { endTime = w.afternoonEnd; } else if (morning) { endTime = w.morningEnd; } return endTime; }, geWorktime = function(workTime,workWeeks) { if(!workWeeks || !workWeeks.length) return ; return _.chain(workWeeks).filter(function(w) { // 过滤morning、afternoon、night其中有值为"1"表示有设置 return (w.morning=="1"||w.afternoon=="1"||w.night=="1") }).map(function(w) { return $.extend({},workTime, w); }).value(); }, getWorktimeScheduling = function(){ getReqPromise("doctor/work_scheduling/doctor_worktime",{doctor: doctorCode}) .then(function(res) { if(res.status == 200) { var workTime = res.data.workTime, workWeeks = res.data.workWeeks, weeks = geWorktime(workTime, workWeeks); setWorktimeTable(weeks); } else { mui.toast(res.msg); } }); }, setWorktimeTableCell = function(data) { var $tr = $cycworktime.find('tr[data-fl="'+data.wid+'"]'), $time = $tr.find('td[data-type=1]'), $num = $tr.find('td[data-type=2]'); $time.text(data.beginTime+"~"+data.endTime); $num.text(data.famousConsultTimes+"次") }, setWorktimeTable = function(weeks) { _.each(weeks,function(w){ setWorktimeTableCell({ wid: w.week, beginTime: getBeginTime(w), endTime: getEndTime(w), famousConsultTimes: w.famousConsultTimes }); }); }, showBaseInfo = function(){ var url = server+"/doctor/baseinfo"; var data={code:doctorCode}; getReqPromise(url,data).then(function(res) { // TODO 示例后台返回医生数据 //res = doctorData; doctorData = res; if(res.status == 200) { return res.data; } else { mui.toast(res.msg); return null; } }).then(function(data) { if(data) { var html = template("base_info_tmpl", data); $baseInfoWrapper.html(html); if(data.isFamous){// TODO 如果是进入的角色是名医 $mingyiRoleWrapper.show(); getWorktimeScheduling(); } else// TODO 如果是进入的角色是其他医生 { $qitaRoleWrapper.show(); } } }).catch(function(e) { console && console.error(e); }); }, // 点击“设置名医”按钮的处理 setMingyi = function() { // TODO 示例医生姓名数据 var doctorName = doctorData.data.name; mui.confirm("是否确认将"+doctorName+"设置为名医?", "提示", ["取消", "确认"], function(e) { if(e.index == 0){ // 点击“取消”处理 } else { // 点击“确认”处理 var url = server + "/doctor/setFamous"; var params = {'doctorCode':doctorCode,'status':'1'}; getReqPromise(url,params).then(function(res){ if(res.status == 200) { mui.toast("设置名医成功"); baseEnv.webview.reload(true); } else { mui.toast("设置名医失败"); console && console.error(res); } }).catch(function(e){ console && console.error(e); }); } }); }, // 点击“取消名医”按钮的处理 cancelMingyi = function() { // TODO 示例医生姓名数据 var doctorName = doctorData.data.name; mui.confirm("取消名医后,该医生无法提供名医咨询服务,是否确认取消?", "", ["不了,谢谢","确认取消" ], function(e) { if(e.index == 0){ // 点击“不了,谢谢”处理 } else { // 点击“确认取消”处理 // 点击“确认”处理 var url = server + "/doctor/setFamous"; var params = {'doctorCode':doctorCode,'status':'0'}; getReqPromise(url,params).then(function(res){ if(res.status == 200) { mui.toast("取消名医成功"); baseEnv.webview.reload(true); } else { mui.toast("取消名医失败"); console && console.error(res); } }).catch(function(e){ console && console.error(e); }); } }); } // 绑定页面事件 bindEvents = function () { }; // 页面业务处理流程开始 new Promise(function(resolve, reject) { // TODO 临时放开 // resolve(true); mui.plusReady(function() { var old_back = mui.back; // mui.back = backToWebviewById('admin.html'); // mui.back = function() { // var myglWebview = plus.webview.getWebviewById("mingyiguanli"); // if(myglWebview) { // mui.fire(myglWebview,"refreshPage"); // } // old_back(); // } mui.back = backToWebviewById('admin.html'); // plus已经准备好,可以往下执行 resolve(true); }); }).then(function() { // 获取基础环境信息 return getBaseEnvPromise().then(function(env) { baseEnv = env; if(baseEnv.backTo) { backToWebviewById(baseEnv.backTo); } }).then(function() { // 获取登录医生信息 baseInfo = getBaseInfoPromise(); doctorCode = baseInfo.accessData.doctor; // 显示医生基本信息 showBaseInfo(); // 绑定页面事件 bindEvents(); }) }).catch(function(e) { plus.nativeUI.closeWaiting(); console && console.error(e); }); template.helper("setPhoto", function(p) { return getImgUrl(p); });