doctor-homepage.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. // TODO 医生示例数据
  2. //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};
  3. var doctorData = null;
  4. // TODO 临时构造plus对象,使得能够在浏览器中进行调试
  5. //var plus = null;
  6. // 基本信息(包括userAgent、上个页面传递的数据)
  7. var baseInfo = null,
  8. // 基础环境信息(包括当前webview)
  9. baseEnv = null;
  10. // 医生code
  11. var doctorCode = "";
  12. var $baseInfoWrapper = $('#base_info_wrap'),
  13. $mingyiRoleWrapper = $('[data-role="mingyi"]'),
  14. $qitaRoleWrapper = $('[data-role="qitayisheng"]'),
  15. $cycworktime = $('.cycworktime');
  16. // 获取基本信息(包括userAgent、上个页面传递的数据)
  17. var getBaseInfoPromise = function() {
  18. // 登录的相关信息
  19. var userAgent = plus && JSON.parse(plus.storage.getItem("userAgent"))
  20. return {
  21. userAgent: userAgent,
  22. // 上一个页面传递的数据
  23. accessData: baseEnv.webview.accessData
  24. }
  25. },
  26. // 获取基础环境信息
  27. getBaseEnvPromise = function () {
  28. var webview = plus.webview.currentWebview();
  29. var env = {
  30. webview: webview,
  31. // 点击“返回”的webveiw的id(由上一个页面传递)
  32. backTo: webview.backTo
  33. };
  34. return Promise.resolve().then(function(res) {
  35. return env;
  36. });
  37. },
  38. getBeginTime = function (w) {
  39. var morning = (w.morning === "1")?true:false,
  40. afternoon = (w.afternoon === "1")?true:false,
  41. night = (w.night === "1")?true:false,
  42. beginTime = "8:30";
  43. if(morning) {
  44. beginTime = w.morningBegin;
  45. }else if(afternoon) {
  46. beginTime = w.afternoonBegin;
  47. } else if (night) {
  48. beginTime = w.nightBegin;
  49. }
  50. return beginTime;
  51. },
  52. getEndTime = function (w) {
  53. var morning = (w.morning === "1")?true:false,
  54. afternoon = (w.afternoon === "1")?true:false,
  55. night = (w.night === "1")?true:false,
  56. endTime = "18:00";
  57. if(night) {
  58. endTime = w.nightEnd;
  59. }else if(afternoon) {
  60. endTime = w.afternoonEnd;
  61. } else if (morning) {
  62. endTime = w.morningEnd;
  63. }
  64. return endTime;
  65. },
  66. geWorktime = function(workTime,workWeeks) {
  67. if(!workWeeks || !workWeeks.length) return ;
  68. return _.chain(workWeeks).filter(function(w) {
  69. // 过滤morning、afternoon、night其中有值为"1"表示有设置
  70. return (w.morning=="1"||w.afternoon=="1"||w.night=="1")
  71. }).map(function(w) {
  72. return $.extend({},workTime, w);
  73. }).value();
  74. },
  75. getWorktimeScheduling = function(){
  76. getReqPromise("doctor/work_scheduling/doctor_worktime",{doctor: doctorCode})
  77. .then(function(res) {
  78. if(res.status == 200) {
  79. var workTime = res.data.workTime,
  80. workWeeks = res.data.workWeeks,
  81. weeks = geWorktime(workTime, workWeeks);
  82. setWorktimeTable(weeks);
  83. } else {
  84. mui.toast(res.msg);
  85. }
  86. });
  87. },
  88. setWorktimeTableCell = function(data) {
  89. var $tr = $cycworktime.find('tr[data-fl="'+data.wid+'"]'),
  90. $time = $tr.find('td[data-type=1]'),
  91. $num = $tr.find('td[data-type=2]');
  92. $time.text(data.beginTime+"~"+data.endTime);
  93. $num.text(data.famousConsultTimes+"次")
  94. },
  95. setWorktimeTable = function(weeks) {
  96. _.each(weeks,function(w){
  97. setWorktimeTableCell({
  98. wid: w.week,
  99. beginTime: getBeginTime(w),
  100. endTime: getEndTime(w),
  101. famousConsultTimes: w.famousConsultTimes
  102. });
  103. });
  104. },
  105. showBaseInfo = function(){
  106. var url = server+"/doctor/baseinfo";
  107. var data={code:doctorCode};
  108. getReqPromise(url,data).then(function(res) {
  109. // TODO 示例后台返回医生数据
  110. //res = doctorData;
  111. doctorData = res;
  112. if(res.status == 200) {
  113. return res.data;
  114. } else {
  115. mui.toast(res.msg);
  116. return null;
  117. }
  118. }).then(function(data) {
  119. if(data) {
  120. var html = template("base_info_tmpl", data);
  121. $baseInfoWrapper.html(html);
  122. if(data.isFamous){// TODO 如果是进入的角色是名医
  123. $mingyiRoleWrapper.show();
  124. getWorktimeScheduling();
  125. }
  126. else// TODO 如果是进入的角色是其他医生
  127. {
  128. $qitaRoleWrapper.show();
  129. }
  130. }
  131. }).catch(function(e) {
  132. console && console.error(e);
  133. });
  134. },
  135. // 点击“设置名医”按钮的处理
  136. setMingyi = function() {
  137. // TODO 示例医生姓名数据
  138. var doctorName = doctorData.data.name;
  139. mui.confirm("是否确认将"+doctorName+"设置为名医?", "提示", ["取消", "确认"], function(e) {
  140. if(e.index == 0){
  141. // 点击“取消”处理
  142. } else {
  143. // 点击“确认”处理
  144. var url = server + "/doctor/setFamous";
  145. var params = {'doctorCode':doctorCode,'status':'1'};
  146. getReqPromise(url,params).then(function(res){
  147. if(res.status == 200) {
  148. mui.toast("设置名医成功");
  149. baseEnv.webview.reload(true);
  150. } else {
  151. mui.toast("设置名医失败");
  152. console && console.error(res);
  153. }
  154. }).catch(function(e){
  155. console && console.error(e);
  156. });
  157. }
  158. });
  159. },
  160. // 点击“取消名医”按钮的处理
  161. cancelMingyi = function() {
  162. // TODO 示例医生姓名数据
  163. var doctorName = doctorData.data.name;
  164. mui.confirm("取消名医后,该医生无法提供名医咨询服务,是否确认取消?", "", ["不了,谢谢","确认取消" ], function(e) {
  165. if(e.index == 0){
  166. // 点击“不了,谢谢”处理
  167. } else {
  168. // 点击“确认取消”处理
  169. // 点击“确认”处理
  170. var url = server + "/doctor/setFamous";
  171. var params = {'doctorCode':doctorCode,'status':'0'};
  172. getReqPromise(url,params).then(function(res){
  173. if(res.status == 200) {
  174. mui.toast("取消名医成功");
  175. baseEnv.webview.reload(true);
  176. } else {
  177. mui.toast("取消名医失败");
  178. console && console.error(res);
  179. }
  180. }).catch(function(e){
  181. console && console.error(e);
  182. });
  183. }
  184. });
  185. }
  186. // 绑定页面事件
  187. bindEvents = function () {
  188. };
  189. // 页面业务处理流程开始
  190. new Promise(function(resolve, reject) {
  191. // TODO 临时放开
  192. // resolve(true);
  193. mui.plusReady(function() {
  194. var old_back = mui.back;
  195. // mui.back = backToWebviewById('admin.html');
  196. // mui.back = function() {
  197. // var myglWebview = plus.webview.getWebviewById("mingyiguanli");
  198. // if(myglWebview) {
  199. // mui.fire(myglWebview,"refreshPage");
  200. // }
  201. // old_back();
  202. // }
  203. mui.back = backToWebviewById('admin.html');
  204. // plus已经准备好,可以往下执行
  205. resolve(true);
  206. });
  207. }).then(function() {
  208. // 获取基础环境信息
  209. return getBaseEnvPromise().then(function(env) {
  210. baseEnv = env;
  211. if(baseEnv.backTo) {
  212. backToWebviewById(baseEnv.backTo);
  213. }
  214. }).then(function() {
  215. // 获取登录医生信息
  216. baseInfo = getBaseInfoPromise();
  217. doctorCode = baseInfo.accessData.doctor;
  218. // 显示医生基本信息
  219. showBaseInfo();
  220. // 绑定页面事件
  221. bindEvents();
  222. })
  223. }).catch(function(e) {
  224. plus.nativeUI.closeWaiting();
  225. console && console.error(e);
  226. });
  227. template.helper("setPhoto", function(p) {
  228. return getImgUrl(p);
  229. });