pay_flow.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. var d = dialog({
  2. contentType: 'load',
  3. skin: 'bk-popup'
  4. });
  5. var pagetype = 0;
  6. var userAgent = window.localStorage.getItem(agentName);
  7. var Request = new Object();
  8. Request = GetRequest();
  9. //这个页面兼作为绑卡成功后的回调页面,所以在此将url中的参数缓存起来
  10. window.localStorage.setItem('request_info', JSON.stringify(Request));
  11. var toUser = Request["toUser"];
  12. var toName = decodeURIComponent(Request["toName"]);
  13. var represented = Request["represented"];
  14. var openid = Request["openid"];
  15. var newUaObj = JSON.parse(window.localStorage.getItem(agentName))
  16. var signInfo;
  17. $(function(){
  18. //判断接收者是否是本人
  19. if(!userAgent) {
  20. window.location.href = server + "wx/html/home/html/zhmm-login.html?openid=" + openid+"&type="+pagetype;
  21. return false;
  22. }
  23. //判断是否可以在线支付
  24. if(!canPayOnline){
  25. var param = window.location.search;
  26. window.location.replace(server +"wx/html/ssgg/html/doctor-homepage-new.html"+param);
  27. return false;
  28. }
  29. initFamilyData();
  30. });
  31. function initFamilyData () {
  32. //从微信模板消息进入
  33. if(represented && userAgent && toUser){
  34. if(toUser == represented){
  35. saveUserInfo(represented,newUaObj.uid)
  36. }else if(toUser != represented && represented == newUaObj.uid){
  37. //本人代理
  38. saveUserInfo(represented,newUaObj.uid)
  39. }else if(toUser != represented && toUser == newUaObj.uid){
  40. //需要判定关系 200有授权 100家人 1无关系
  41. saveUserInfo(represented,newUaObj.uid)
  42. }else{
  43. //重新登录
  44. relogin();
  45. }
  46. }else{
  47. userInfo = JSON.parse(window.localStorage.getItem(agentName));
  48. bindEvents();
  49. checkStatus();
  50. }
  51. }
  52. //保存信息
  53. function saveUserInfo(a,b){
  54. Promise.all([hasFamilyRelation(a,b)]).then(function () {
  55. newUaObj.represented = represented;
  56. window.localStorage.setItem(agentName,JSON.stringify(newUaObj));
  57. userInfo = JSON.parse(window.localStorage.getItem(agentName));
  58. getSignInfo();
  59. })
  60. }
  61. //重新登录操作
  62. function relogin(){
  63. dialog({
  64. content:'对不起,该消息是发给'+toName+',如需查看,请切换'+toName+'账号登录',
  65. okValue:'切换账号',
  66. ok: function() {
  67. window.localStorage.setItem(pageName, JSON.stringify({pageurl: location.href}))
  68. window.location.href = "../../grzx/html/change-login.html?type=0&openid="+ Request["openid"];
  69. },
  70. cancelValue: '我不看了',
  71. cancel: function () {
  72. wx.closeWindow();
  73. }
  74. }).showModal();
  75. }
  76. //判断关系
  77. function hasFamilyRelation(a,b){
  78. return new Promise(function(resolve, reject) {
  79. var data={
  80. patient:a,
  81. familyMember:b
  82. }
  83. sendPost("patient/family/is_authorize", data, "json", "get", function(res){
  84. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请求家庭成员关系失败'}).show();
  85. }, function(res){
  86. if(res.status == 200) {
  87. window.localStorage.setItem('nowPatientName',res.data.name);
  88. resolve(res)
  89. }else if(res.status == 100) {
  90. dialog({
  91. content:'对不起,'+res.data.name+'未授权给您,如需查看,请切换'+res.data.name+'账号登录',
  92. okValue:'切换账号',
  93. ok: function() {
  94. window.localStorage.setItem(pageName, JSON.stringify({pageurl: location.href}))
  95. window.location.href = "../../grzx/html/change-login.html?type=0&openid="+ Request["openid"];
  96. },
  97. cancelValue: '我不看了',
  98. cancel: function () {
  99. wx.closeWindow();
  100. }
  101. }).showModal();
  102. }else{
  103. relogin();
  104. }
  105. })
  106. })
  107. }
  108. //获取签约信息,计算缴费金额
  109. function getSignInfo(){
  110. d.show();
  111. var url = "/patient/sign/signInfo",
  112. params ={code: Request['signCode']};
  113. sendPost(url, params, 'JSON', 'get', queryFailed, function(res){
  114. if(res.status == 200){
  115. signInfo = res.data;
  116. if(signInfo.expensesStatus == 1){
  117. d.close();
  118. //已缴费,跳转去缴费结果页面
  119. var payParams = {
  120. code: signInfo.code,
  121. teamCode: signInfo.teamCode,
  122. type: signInfo.type,
  123. doctorHealth: signInfo.doctor,
  124. status: signInfo.status,
  125. renew: signInfo.isRenew,
  126. exstatus: signInfo.expensesStatus,
  127. payCode: signInfo.payCode,
  128. showResult: true //标记直接根据交易码获取缴费信息,区别在线支付回调
  129. };
  130. payParams = JSON.stringify(payParams);
  131. window.localStorage.setItem("payParams",payParams);
  132. //删除缓存的链接参数
  133. window.localStorage.removeItem('request_info');
  134. window.location.href = 'pay_result.html';
  135. }else{
  136. //未缴费,判断是否绑卡
  137. checkBindStatus();
  138. }
  139. }else{
  140. queryFailed(res);
  141. }
  142. });
  143. }
  144. //判断是否有绑卡
  145. function checkBindStatus(){
  146. var url = "/patient/bindCard";
  147. sendPost(url, {}, 'json', 'post', queryFailed, function(res){
  148. d.close();
  149. if(res.data.bindStatus == '000000'){ //已绑卡
  150. //跳转去支付页面
  151. //先获取缴费金额信息,然后再组装支付信息
  152. charge();
  153. }else if(res.data.bindStatus == '030007'){//未绑卡
  154. d.close();
  155. //跳转去绑卡链接
  156. var bindUrl = res.data.sicardUrl;
  157. window.location.href = bindUrl;
  158. }
  159. });
  160. }
  161. //发起缴费申请
  162. function charge(){
  163. var url = "/patient/charge",
  164. params = {
  165. orgCode: signInfo.hospital,
  166. chargeType: 1, //签约类型
  167. chargeRelation: signInfo.code, //签约的code
  168. totalAmount: 12000 //固定值
  169. };
  170. sendPost(url, params, 'json', 'post', queryFailed, function(res){
  171. d.close();
  172. if(res.status == 200){
  173. //跳转去缴费页面
  174. window.location.href = res.data;
  175. }else{
  176. queryFailed(res);
  177. }
  178. });
  179. }
  180. function queryFailed(res){
  181. d.close();
  182. if(res && res.msg) {
  183. dialog({
  184. contentType: 'tipsbox',
  185. skin: 'bk-popup',
  186. content: res.msg
  187. }).show();
  188. } else {
  189. dialog({
  190. contentType: 'tipsbox',
  191. skin: 'bk-popup',
  192. content: '加载失败'
  193. }).show();
  194. }
  195. }