zixun-doctor-homepage.js 4.1 KB

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