isRepresented.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. //需要 dialog插件,wx插件 //目前采用pagetype = 0
  2. var d = dialog({contentType:'load', skin:'bk-popup'});
  3. var Request = new Object();
  4. Request = GetRequest();
  5. var userAgent = window.localStorage.getItem(agentName);
  6. var toUser = Request["toUser"];
  7. var toName = decodeURIComponent(Request["toName"]);
  8. var openid = Request["openid"];
  9. var represented = Request["represented"];
  10. var params = {};
  11. params.pageUrl = window.location.href;
  12. $.ajax(server + "weixin/getSign", {
  13. data: params,
  14. dataType: "json",
  15. type: "post",
  16. success: function(res){
  17. if (res.status == 200) {
  18. var t = res.data.timestamp;
  19. var noncestr = res.data.noncestr;
  20. var signature = res.data.signature;
  21. wx.config({
  22. //debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
  23. appId: appId, // 必填,公众号的唯一标识
  24. timestamp: t, // 必填,生成签名的时间戳
  25. nonceStr: noncestr, // 必填,生成签名的随机串
  26. signature: signature,// 必填,签名,见附录1
  27. jsApiList: [
  28. 'closeWindow'
  29. ] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
  30. })
  31. }
  32. }
  33. })
  34. function isRepresent(fun){
  35. if(!userAgent) {
  36. window.localStorage.setItem(pageName, JSON.stringify({pageurl: location.href}))
  37. window.location.href = server + "wx/html/home/html/zhmm-login.html?type=0&openid=" + openid;
  38. return false;
  39. }
  40. var newUaObj = typeof(userAgent)=='object'?userAgent:JSON.parse(userAgent)
  41. //判断关系
  42. function hasFamilyRelation(a,b){
  43. return new Promise(function(resolve, reject) {
  44. var data={
  45. patient:a,
  46. familyMember:b
  47. }
  48. sendPost("patient/family/is_authorize", data, "json", "get", function(res){
  49. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请求家庭成员关系失败'}).show();
  50. }, function(res){
  51. if(res.status == 200) {
  52. window.localStorage.setItem('nowPatientName',res.data.name);
  53. resolve(res)
  54. }else if(res.status == 100) {
  55. dialog({
  56. content:'对不起,'+res.data.name+'未授权给您,如需查看,请切换'+res.data.name+'账号登录',
  57. okValue:'切换账号',
  58. ok: function() {
  59. window.localStorage.setItem(pageName, JSON.stringify({pageurl: location.href}))
  60. window.location.href = "../../grzx/html/change-login.html?type=0&openid="+openid;
  61. },
  62. cancelValue: '我不看了',
  63. cancel: function () {
  64. wx.closeWindow();
  65. }
  66. }).showModal();
  67. }else{
  68. relogin();
  69. }
  70. })
  71. })
  72. }
  73. //重新登录操作
  74. function relogin(){
  75. dialog({
  76. content:'对不起,该消息是发给'+toName+',如需查看,请切换'+toName+'账号登录',
  77. okValue:'切换账号',
  78. ok: function() {
  79. window.localStorage.setItem(pageName, JSON.stringify({pageurl: location.href}))
  80. window.location.href = "../../grzx/html/change-login.html?type=0&openid="+openid;
  81. },
  82. cancelValue: '我不看了',
  83. cancel: function () {
  84. wx.closeWindow();
  85. }
  86. }).showModal();
  87. }
  88. //保存信息
  89. function saveUserInfo(a,b){
  90. Promise.all([hasFamilyRelation(a,b)]).then(function () {
  91. newUaObj.represented = represented;
  92. window.localStorage.setItem(agentName,JSON.stringify(newUaObj));
  93. fun && fun.call(this);
  94. })
  95. }
  96. function initFamilyData () {
  97. if(!represented){
  98. fun && fun.call(this);
  99. return
  100. }
  101. //从微信模板消息进入
  102. if(represented && userAgent && toUser){
  103. if(toUser == represented){
  104. saveUserInfo(represented,newUaObj.uid)
  105. }else if(toUser != represented && represented == newUaObj.uid){
  106. //本人代理
  107. saveUserInfo(represented,newUaObj.uid)
  108. }else if(toUser != represented && toUser == newUaObj.uid){
  109. //需要判定关系 200有授权 100家人 1无关系
  110. saveUserInfo(represented,newUaObj.uid)
  111. }else{
  112. //重新登录
  113. relogin();
  114. }
  115. }
  116. }
  117. initFamilyData();
  118. }