payment.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. var Request = GetRequest();
  2. var checktype=false;
  3. var loading = dialog({
  4. contentType: 'load',
  5. skin: 'bk-popup'
  6. });
  7. (function() {
  8. new Vue({
  9. el: "#app",
  10. data: {
  11. dataList:[],
  12. cardId:Request.id,
  13. payMoney:"",
  14. cardNo:"",
  15. paytype:Request.paytype, //paytype 1为门诊缴费 2为住院缴费
  16. surplusMoney:"",
  17. data:{},
  18. code:"",
  19. },
  20. mounted: function() {
  21. var vm = this
  22. loading.show();
  23. checkUserAgent();
  24. vm.code=JSON.parse(localStorage.getItem("wlyyAgent")).uid
  25. vm.checkType()
  26. },
  27. methods: {
  28. //获取列表数据
  29. getData:function(){
  30. var vm=this
  31. sendPost("patient/card/getCardInfo", {id:vm.cardId}, "json", "get",function(){
  32. loading.close();
  33. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请求失败'}).show();
  34. }, function(res){
  35. if(res.status == 200){
  36. loading.close();
  37. vm.data=res.data
  38. if(vm.paytype=="1"){
  39. vm.surplusMoney=vm.data.cardMoney
  40. vm.cardNo=vm.data.cardNo
  41. }else{
  42. vm.surplusMoney=vm.data.cardInpMoney
  43. vm.cardNo=vm.data.inpCardNo
  44. }
  45. }else{
  46. loading.close();
  47. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'数据获取失败'}).show();
  48. }
  49. })
  50. },
  51. //去支付
  52. toPayment:function(){
  53. var vm=this
  54. loading.show();
  55. if(vm.payMoney){
  56. // if(judgeWxVersion()){
  57. // vm.getWeixinSign()
  58. // }
  59. vm.wxReady()
  60. }else{
  61. loading.close();
  62. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请输入充值金额'}).show();
  63. }
  64. },
  65. //获得微信sdk信息
  66. getWeixinSign:function() {
  67. var vm=this
  68. var params = {};
  69. params.pageUrl = window.location.href;
  70. sendPost("weixin/getSign", params, "json", "post",function(){
  71. loading.close();
  72. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请求失败'}).show();
  73. }, function(res){
  74. if(res.status == 200) {
  75. var t = res.data.timestamp;
  76. var noncestr = res.data.noncestr;
  77. var signature = res.data.signature;
  78. wx.config({
  79. //debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
  80. appId: appId, // 必填,公众号的唯一标识
  81. timestamp: t, // 必填,生成签名的时间戳
  82. nonceStr: noncestr, // 必填,生成签名的随机串
  83. signature: signature, // 必填,签名,见附录1
  84. jsApiList: [
  85. 'chooseWXPay',
  86. ] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
  87. });
  88. wx.ready(function(){
  89. vm.wxReady()
  90. })
  91. }else{
  92. loading.close();
  93. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:res.msg}).show();
  94. }
  95. })
  96. },
  97. wxReady:function(){
  98. var vm=this
  99. var params = {
  100. patientName:vm.data.name,
  101. healthNo:vm.cardNo,
  102. healthType:vm.paytype,
  103. payAmount:parseFloat(vm.payMoney).toFixed(2),
  104. spbillCreateIp:returnCitySN["cip"],
  105. code:getUrlParam("code"),
  106. };
  107. sendPost("/hy/pay/createPayOrder", params, "json", "post",function(){
  108. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请求失败'}).show();
  109. }, function(res){
  110. if(res.status == 200) {
  111. loading.close();
  112. var t = res.data.timestamp;
  113. var noncestr = res.data.noncestr;
  114. var package ="prepay_id="+res.data.prepayid;
  115. var paySign = res.data.paySign;
  116. wx.chooseWXPay({
  117. timestamp: t, // 支付签名时间戳,注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
  118. nonceStr: noncestr, // 支付签名随机串,不长于 32 位
  119. package: package, // 统一支付接口返回的prepay_id参数值,提交格式如:prepay_id=***)
  120. signType: 'MD5', // 签名方式,默认为'SHA1',使用新版支付需传入'MD5'
  121. paySign: paySign, // 支付签名
  122. success: function (res) {
  123. // 支付成功后的回调函数
  124. window.location.href='../../payment/html/paymentResult.html';
  125. },error:function(res){
  126. window.location.href='../../payment/html/paymentResult.html';
  127. }
  128. });
  129. }else{
  130. loading.close();
  131. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:res.msg}).show();
  132. }
  133. })
  134. },
  135. //强制设定最多只能输入两位小数
  136. checkNumber:function(payMoney){
  137. this.payMoney= (payMoney.match(/^\d*(\.?\d{0,2})/g)[0]) || null
  138. },
  139. //判断是否验证登录通过
  140. checkType:function(){
  141. var vm=this
  142. var timer = setInterval(function(){
  143. if(checktype){
  144. clearInterval(timer);
  145. vm.getData()
  146. }
  147. },10);
  148. },
  149. },
  150. })
  151. })()
  152. function queryInit(){
  153. checktype=true
  154. }
  155. function getUrlParam(name){
  156. //构造一个含有目标参数的正则表达式对象
  157. var reg = new RegExp("(^|&)"+name+"=([^&]*)(&|$)");
  158. //匹配目标参数
  159. var r = window.location.search.substr(1).match(reg);
  160. //返回参数值
  161. if (r!=null) return unescape(r[2]); return null;
  162. }
  163. //判断微信版本号
  164. function judgeWxVersion(name){
  165. var ispass=false
  166. var wechatInfo = navigator.userAgent.match(/MicroMessenger\/([\d\.]+)/i)
  167. if(!wechatInfo) {
  168. loading.close();
  169. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'当前不是微信,不支持微信支付'}).show();
  170. }
  171. else
  172. {
  173. wx.checkJsApi({
  174. jsApiList: ['chooseWXPay'], // 需要检测的JS接口列表,所有JS接口列表见附录2,
  175. success: function(res) {
  176. if("errMsg"=="checkJsApi:ok"){
  177. if(res.checkResult.chooseWXPay){
  178. ispass=true
  179. }else{
  180. loading.close();
  181. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'当前微信低于5.0,不支持微信支付,请升级后支付'}).show();
  182. }
  183. }else{
  184. if ( wechatInfo[1] < "5.0" ) {
  185. loading.close();
  186. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'当前微信低于5.0,不支持微信支付,请升级后支付'}).show();
  187. }else{
  188. ispass=true
  189. }
  190. }
  191. }
  192. });
  193. }
  194. return ispass
  195. }