payment.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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.showModal();
  23. checkUserAgent();
  24. vm.code=JSON.parse(localStorage.getItem("wlyyAgent")).uid
  25. vm.checkType()
  26. $(".c-ser-input").focus()
  27. },
  28. methods: {
  29. //获取列表数据
  30. getData:function(){
  31. var vm=this
  32. sendPost("patient/card/getCardInfo", {id:vm.cardId}, "json", "get",function(){
  33. loading.close();
  34. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请求失败'}).show();
  35. }, function(res){
  36. if(res.status == 200){
  37. loading.close();
  38. vm.data=res.data
  39. if(vm.paytype=="1"){
  40. vm.surplusMoney=vm.data.cardMoney?vm.data.cardMoney:0
  41. vm.cardNo=vm.data.cardNo
  42. }else{
  43. vm.surplusMoney=vm.data.cardInpMoney?vm.data.cardInpMoney:0
  44. vm.cardNo=vm.data.inpCardNo
  45. }
  46. }else{
  47. loading.close();
  48. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'数据获取失败'}).show();
  49. }
  50. })
  51. },
  52. //去支付
  53. toPayment:function(){
  54. var vm=this
  55. loading.showModal();
  56. if(vm.payMoney){
  57. if(judgeWxVersion()){
  58. vm.getWeixinSign()
  59. }
  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 timestamp = 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: timestamp, // 必填,生成签名的时间戳
  82. nonceStr: noncestr, // 必填,生成签名的随机串
  83. signature: signature, // 必填,签名,见附录1
  84. jsApiList: [
  85. 'chooseWXPay',
  86. 'checkJsApi'
  87. ] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
  88. });
  89. wx.ready(function(){
  90. vm.wxReady()
  91. })
  92. }else{
  93. loading.close();
  94. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:res.msg}).show();
  95. }
  96. })
  97. },
  98. wxReady:function(){
  99. var vm=this
  100. var params = {
  101. patient:vm.data.patient,
  102. healthNo:vm.cardNo,
  103. healthType:vm.paytype,
  104. payAmount:parseFloat(vm.payMoney).toFixed(2),
  105. spbillCreateIp:returnCitySN["cip"],
  106. code:getUrlParam("code"),
  107. openid:JSON.parse(localStorage.getItem("wlyyAgent")).openid
  108. };
  109. sendPost("third/hy/pay/createPayOrder", params, "json", "post",function(){
  110. loading.close();
  111. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请求失败'}).show();
  112. }, function(res){
  113. if(res.status == 200) {
  114. loading.close();
  115. var data = res.data;
  116. wx.chooseWXPay({
  117. appId:data.appId,
  118. timestamp: data.timeStamp, // 支付签名时间戳,注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
  119. nonceStr: data.nonceStr, // 支付签名随机串,不长于 32 位
  120. package: data.package, // 统一支付接口返回的prepay_id参数值,提交格式如:prepay_id=***)
  121. signType: data.signType, // 签名方式,默认为'SHA1',使用新版支付需传入'MD5'
  122. paySign: data.sign, // 支付签名
  123. success: function (res) {
  124. // 支付成功后的回调函数
  125.                                window.location.href='../../payment/html/paymentResult.html?seqNo='+data.seqNo;
  126. },
  127. cencel:function(res){
  128. // 支付取消回调函数
  129. //alert("支付过程中用户取消");
  130. },
  131. fail: function(res){
  132. // 支付失败回调函数
  133. var errorparams={seqNo:data.seqNo,wxErrorMsg:res.errMsg}
  134. sendPost("third/hy/pay/setPayLogWxFail", errorparams, "json", "post",function(){
  135. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请求失败'}).show();
  136. }, function(res){
  137. window.location.href='../../payment/html/paymentResult.html?seqNo='+data.seqNo;
  138. })
  139. }
  140. });
  141. }else{
  142. loading.close();
  143. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:res.msg}).show();
  144. }
  145. })
  146. },
  147. //强制设定最多只能输入两位小数
  148. checkNumber:function(payMoney){
  149. var myreg=/^[0][0-9]{1}$/;
  150. if(myreg.test(payMoney)){
  151. payMoney="0"
  152. }
  153. this.payMoney= (payMoney.match(/^\d*(\.?\d{0,2})/g)[0]) || null
  154. },
  155. //判断是否验证登录通过
  156. checkType:function(){
  157. var vm=this
  158. var timer = setInterval(function(){
  159. if(checktype){
  160. clearInterval(timer);
  161. vm.getData()
  162. }
  163. },10);
  164. },
  165. },
  166. })
  167. })()
  168. function queryInit(){
  169. checktype=true
  170. }
  171. function getUrlParam(name){
  172. //构造一个含有目标参数的正则表达式对象
  173. var reg = new RegExp("(^|&)"+name+"=([^&]*)(&|$)");
  174. //匹配目标参数
  175. var r = window.location.search.substr(1).match(reg);
  176. //返回参数值
  177. if (r!=null) return unescape(r[2]); return null;
  178. }
  179. //判断微信版本号
  180. function judgeWxVersion(name){
  181. var ispass=false
  182. var wechatInfo = navigator.userAgent.match(/MicroMessenger\/([\d\.]+)/i)
  183. if(!wechatInfo) {
  184. loading.close();
  185. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'当前不是微信,不支持微信支付'}).show();
  186. }
  187. else
  188. {
  189. if ( wechatInfo[1] < "5.0" ) {
  190. loading.close();
  191. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'当前微信低于5.0,不支持微信支付,请升级后支付'}).show();
  192. }else{
  193. ispass=true
  194. }
  195. }
  196. return ispass
  197. }