123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256 |
- // 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);
- });
|