zixun-doctor-homepage.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. // 基本信息(包括userAgent、上个页面传递的数据)
  5. var baseInfo = null,
  6. // 基础环境信息(包括当前webview)
  7. baseEnv = null;
  8. // 医生code
  9. var doctorCode = "";
  10. var $baseInfoWrapper = $('#base_info_wrap');
  11. // 获取基本信息(包括userAgent、上个页面传递的数据)
  12. var getBaseInfoPromise = function() {
  13. // 登录的相关信息
  14. var userAgent = plus && JSON.parse(plus.storage.getItem("userAgent"))
  15. return {
  16. userAgent: userAgent,
  17. // 上一个页面传递的数据
  18. accessData: baseEnv.webview.accessData
  19. }
  20. },
  21. // 获取基础环境信息
  22. getBaseEnvPromise = function () {
  23. var webview = plus.webview.currentWebview();
  24. var env = {
  25. webview: webview,
  26. // 点击“返回”的webveiw的id(由上一个页面传递)
  27. backTo: webview.backTo
  28. };
  29. return Promise.resolve().then(function(res) {
  30. return env;
  31. });
  32. },
  33. showBaseInfo = function(){
  34. var url = server+"/doctor/baseinfo";
  35. var data={code:doctorCode};
  36. getReqPromise(url,data).then(function(res) {
  37. // TODO 示例后台返回医生数据
  38. //res = doctorData;
  39. doctorData = res;
  40. if(res.status == 200) {
  41. return res.data;
  42. } else {
  43. mui.toast(res.msg);
  44. return null;
  45. }
  46. }).then(function(data) {
  47. if(data) {
  48. var html = template("base_info_tmpl", data);
  49. $baseInfoWrapper.html(html);
  50. }
  51. }).catch(function(e) {
  52. console && console.error(e);
  53. });
  54. },
  55. // 点击“立即咨询”按钮的处理
  56. zixun = function() {
  57. service.hasUnfinishedConsult(doctorCode, function(res){
  58. if(res.data.consult){
  59. var doc = doctorData.data;
  60. mui.confirm("您与"+ doc.name +"医生当前有进行中咨询,不可发起求助,您可直接进入咨询提问",
  61. "提示", ["查看咨询", "我知道了"], function(e){
  62. if(e.index==0){
  63. var wv = mui.openWindow({
  64. url:"../../message/html/p2p.html",
  65. id: "p2p",
  66. extras: {
  67. otherCode: doctorCode,
  68. otherName: doc.name,
  69. otherSex: doc.sex,
  70. otherPhoto: doc.photo,
  71. consultData: res.data
  72. }
  73. })
  74. }
  75. })
  76. } else
  77. checkWorking()
  78. })
  79. },
  80. checkWorking= function(){
  81. var url = server+"/doctor/work_scheduling/is_doctor_working";
  82. var data={doctor:doctorCode};
  83. getReqPromise(url,data).then(function(res) {
  84. if(res.status == 200) {
  85. return res.data;
  86. } else {
  87. mui.toast(res.msg);
  88. return null;
  89. }
  90. }).then(function(data) {
  91. var status = data.status;
  92. if(status) {//0:医生不接受咨询 1:医生接受咨询 2:医生当前不在工作时间
  93. if(status=="0"){
  94. dialog({
  95. content: '对不起,该医生已暂停接受咨询,您可选择其他医生进行咨询',
  96. cancelValue: '我知道了',
  97. cancel: function () {
  98. return;
  99. }
  100. }).showModal();
  101. return false;
  102. }else if(status=="1"){
  103. openWebview("faqizixun.html",{accessData: $.extend({},doctorData.data,{doctor:doctorCode})});
  104. }else if(status=="2"){
  105. dialog({
  106. content: '医生不在工作时间内哦,请在医生咨询计划时间段内咨询',
  107. cancelValue: '我知道了',
  108. cancel: function () {
  109. return;
  110. }
  111. }).showModal();
  112. }
  113. }
  114. }).catch(function(e) {
  115. console && console.error(e);
  116. });
  117. }
  118. // 绑定页面事件
  119. bindEvents = function () {
  120. };
  121. // 页面业务处理流程开始
  122. new Promise(function(resolve, reject) {
  123. mui.plusReady(function() {
  124. var old_back = mui.back;
  125. mui.back = function() {
  126. var webview = plus.webview.getWebviewById("zixun-xuanzeyisheng");
  127. if(webview) {
  128. mui.fire(webview,"refreshPage");
  129. }
  130. old_back();
  131. }
  132. // plus已经准备好,可以往下执行
  133. resolve(true);
  134. });
  135. }).then(function() {
  136. // 获取基础环境信息
  137. return getBaseEnvPromise().then(function(env) {
  138. baseEnv = env;
  139. if(baseEnv.backTo) {
  140. backToWebviewById(baseEnv.backTo);
  141. }
  142. }).then(function() {
  143. // 获取登录医生信息
  144. baseInfo = getBaseInfoPromise();
  145. doctorCode = baseInfo.accessData.doctor;
  146. // 显示医生基本信息
  147. showBaseInfo();
  148. // 绑定页面事件
  149. bindEvents();
  150. })
  151. }).catch(function(e) {
  152. plus.nativeUI.closeWaiting();
  153. console && console.error(e);
  154. });
  155. template.helper("setPhoto", function(p) {
  156. return getImgUrl(p);
  157. });