detail-appointment.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. var d = dialog({contentType:'load', skin:'bk-popup'});
  2. var pagetype = 23;
  3. $(function(){
  4. var request = GetRequest();
  5. var id = request["id"];
  6. var orgCode = request["orgCode"];
  7. var doctorCode = "";
  8. var deptCode = "";
  9. var toUser = request["toUser"];
  10. var openid = request["openid"];
  11. var toName = decodeURIComponent(Request["toName"]);
  12. var represented = Request["represented"];
  13. var userAgent = window.localStorage.getItem(agentName);
  14. //注册事件
  15. bindEvents();
  16. //初始化数据
  17. initData();
  18. function initData(){
  19. if(!userAgent) {
  20. localStorage.setItem("toUser",toUser);
  21. localStorage.setItem("id",id);
  22. window.location.href = server + "wx/html/home/html/login.html?openid=" + openid+"&type=23";
  23. return false;
  24. }
  25. var newUaObj = JSON.parse(window.localStorage.getItem(agentName))
  26. //判断关系
  27. function hasFamilyRelation(a,b){
  28. return new Promise(function(resolve, reject) {
  29. var data={
  30. patient:a,
  31. familyMember:b
  32. }
  33. sendPost("patient/family/is_authorize", data, "json", "get", function(res){
  34. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请求家庭成员关系失败'}).show();
  35. }, function(res){
  36. if(res.status == 200) {
  37. window.localStorage.setItem('nowPatientName',res.data.name);
  38. resolve(res)
  39. }else if(res.status == 100) {
  40. dialog({
  41. content:'对不起,'+res.data.name+'未授权给您,如需查看,请切换'+res.data.name+'账号登录',
  42. okValue:'切换账号',
  43. ok: function() {
  44. window.localStorage.setItem(pageName, JSON.stringify({pageurl: location.href}))
  45. window.location.href = "../../grzx/html/change-login.html?type=0&openid="+ Request["openid"];
  46. },
  47. cancelValue: '我不看了',
  48. cancel: function () {
  49. wx.closeWindow();
  50. }
  51. }).showModal();
  52. }else{
  53. relogin();
  54. }
  55. })
  56. })
  57. }
  58. //重新登录操作
  59. function relogin(){
  60. dialog({
  61. content:'对不起,该消息是发给'+toName+',如需查看,请切换'+toName+'账号登录',
  62. okValue:'切换账号',
  63. ok: function() {
  64. window.localStorage.setItem(pageName, JSON.stringify({pageurl: location.href}))
  65. window.location.href = "../../grzx/html/change-login.html?type=0&openid="+ Request["openid"];
  66. },
  67. cancelValue: '我不看了',
  68. cancel: function () {
  69. wx.closeWindow();
  70. }
  71. }).showModal();
  72. }
  73. //保存信息
  74. function saveUserInfo(a,b){
  75. Promise.all([hasFamilyRelation(a,b)]).then(function () {
  76. newUaObj.represented = represented;
  77. window.localStorage.setItem(agentName,JSON.stringify(newUaObj));
  78. nextInitData();
  79. })
  80. }
  81. function initFamilyData () {
  82. //从微信模板消息进入
  83. if(represented && userAgent && toUser){
  84. if(toUser == represented){
  85. saveUserInfo(represented,newUaObj.uid)
  86. }else if(toUser != represented && represented == newUaObj.uid){
  87. //本人代理
  88. saveUserInfo(represented,newUaObj.uid)
  89. }else if(toUser != represented && toUser == newUaObj.uid){
  90. //需要判定关系 200有授权 100家人 1无关系
  91. saveUserInfo(represented,newUaObj.uid)
  92. }else{
  93. //重新登录
  94. relogin();
  95. }
  96. }else{
  97. nextInitData();
  98. }
  99. }
  100. initFamilyData();
  101. }
  102. function nextInitData(){
  103. d.show();
  104. var data={};
  105. var loginUser = JSON.parse(window.localStorage.getItem(agentName));
  106. data.regCode = id;
  107. data.orgCode = orgCode;
  108. data.patientCode = loginUser.represented?loginUser.represented:loginUser.uid;
  109. sendPost('third/guahao/GetPatientReservationXm', data, 'json', 'post', getListFail, successFun);
  110. }
  111. function getCanceler(data) {
  112. var name = data.cancelerName;
  113. if(!name) return "";
  114. if(data.cancelerType=='1') {
  115. return name+'(专科医生)';
  116. } else if(data.cancelerType=='2') {
  117. return name+'(全科医生)';
  118. } else if(data.cancelerType=='3') {
  119. return name+'(健康管理师)';
  120. } else if(data.cancelerType=='4') {
  121. return name+'(临时专科)';
  122. } else if(data.cancelerType=='5') {
  123. return name;
  124. }
  125. return name;
  126. }
  127. function successFun(res){
  128. if(res.status==200){
  129. var data = res.data;
  130. //status:0 已撤销 1,2预约成功 3 已就诊 4已停诊
  131. var clazz1 = "cb-47ABEF";
  132. var clazz2 = "c-47ABEF";
  133. var statusNm = "预约成功";
  134. if(data.status=="0"){
  135. clazz1 = "cb-FF6A56";
  136. clazz2 = "c-FF6A56";
  137. statusNm = "已撤销";
  138. var operator = getCanceler(data);
  139. if(operator) {
  140. $('.div-operator').show();
  141. $('#operator_name').text(operator);
  142. }
  143. $(".div-cancel-btn").hide();
  144. $(".div-tongkeshi-btn").removeClass("c-24").addClass("c-50");
  145. $(".div-again-yuyue").removeClass("c-38").addClass("c-50");
  146. }else if(data.status=="3"){
  147. clazz1 = "cb-74BF00";
  148. clazz2 = "c-74BF00";
  149. statusNm = "已就诊";
  150. }else if(data.status=="4"){
  151. clazz1 = "cb-909090";
  152. clazz2 = "c-909090";
  153. statusNm = "已停诊";
  154. }else{//1,2
  155. // TODO 如果预约开始时间早于当前时间,则不显示”取消预约“按钮
  156. var jzStartTimeStr = data.startTime.replace(/-/g,'/');
  157. var jsStartTime = new Date(jzStartTimeStr).getTime();
  158. var curTime = new Date().getTime();
  159. if(curTime>jsStartTime) {
  160. $(".div-cancel-btn").hide();
  161. } else {
  162. $(".div-cancel-btn").show();
  163. $(".div-tongkeshi-btn").removeClass("c-50").addClass("c-24");
  164. $(".div-again-yuyue").removeClass("c-50").addClass("c-38");
  165. }
  166. }
  167. var jiuzhenTime = data.startTime.replace(/\//g,'-').substring(0);//就诊时间
  168. if(data.endTime){
  169. jiuzhenTime = jiuzhenTime + "~"+data.endTime.replace(/\//g,'-').substring(9);
  170. }
  171. $(".left-yuan").addClass(clazz1);
  172. $(".left-status").addClass(clazz2).html(statusNm);
  173. $(".guahao-time").html(data.czrq.substring(0,16));
  174. $(".jiuzheng-time").html(jiuzhenTime);
  175. $(".hospital-name").html(data.orgName);
  176. $(".users-name").html(data.name);
  177. $(".dept-name").html(data.deptName);
  178. $(".doctor-name").html(data.doctorName);
  179. $(".idcard").html(data.idcard);
  180. $(".yibao-num").html(data.ssc);
  181. $(".iphone-num").html(data.phone);
  182. doctorCode = data.doctorCode;
  183. orgCode = data.orgCode;
  184. deptCode = data.deptCode;
  185. }else{
  186. getListFail(res);
  187. }
  188. $(".main").show();
  189. $("#footer").show();
  190. d.close();
  191. }
  192. function getListFail(res){
  193. d.close();
  194. if (res && res.msg) {
  195. if((res.msg).indexOf("SOAP")>=0){
  196. dialog({contentType:'tipsbox', skin:'bk-popup' , content:"医院接口访问异常,请刷新后重试!",bottom:true}).show();
  197. return false;
  198. }
  199. dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg,bottom:true}).show();
  200. } else {
  201. dialog({contentType:'tipsbox', skin:'bk-popup' , content:'加载失败',bottom:true}).show();
  202. }
  203. }
  204. function bindEvents(){
  205. //同科室医生
  206. $(".div-tongkeshi-btn").on("click",function(){
  207. location.href = "select-doctor.html?hospitalId="+orgCode+"&deptId="+deptCode;
  208. });
  209. //撤销预约
  210. $(".div-cancel-btn").on("click",function(){
  211. dialog({
  212. content: '是否撤销该预约?',
  213. okValue:'确认',
  214. ok: function (){
  215. d.show();
  216. sendPost('patient/guahao/CancelOrder', {orderId:id,ssc:$(".yibao-num").text()}, 'json', 'post', getListFail, successCancleFun);
  217. },
  218. cancelValue: '取消',
  219. cancel: function () {
  220. return ;
  221. }
  222. }).showModal();
  223. });
  224. //再次预约
  225. $(".div-again-yuyue").on("click",function(){
  226. location.href = "doctor-detail.html?type=2&id="+id+"&doctorId="+doctorCode+"&hospitalId="+orgCode+"&hosDeptId="+deptCode;
  227. });
  228. }
  229. function successCancleFun(res){
  230. if(res.status==200){
  231. dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg,bottom:true}).show();
  232. //撤销预约成功后跳转到我的预约页面
  233. location.href = "https://open.weixin.qq.com/connect/oauth2/authorize?appid="+appId+"&redirect_uri="+wxurl+"%2fwdyy%2fhtml%2fmy-appointment.html&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect";
  234. }
  235. }
  236. });