payment.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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. },
  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.showModal();
  55. if(vm.payMoney){
  56. // if(judgeWxVersion()){
  57. // vm.getWeixinSign()
  58. // }
  59. vm.getWeixinSign()
  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. ] // 必填,需要使用的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. openid:JSON.parse(localStorage.getItem("wlyyAgent")).openid
  107. };
  108. sendPost("third/hy/pay/createPayOrder", params, "json", "post",function(){
  109. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请求失败'}).show();
  110. }, function(res){
  111. if(res.status == 200) {
  112. loading.close();
  113. var data = res.data;
  114. wx.chooseWXPay({
  115. appId:data.appId,
  116. timestamp: data.timeStamp, // 支付签名时间戳,注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
  117. nonceStr: data.nonceStr, // 支付签名随机串,不长于 32 位
  118. package: data.package, // 统一支付接口返回的prepay_id参数值,提交格式如:prepay_id=***)
  119. signType: data.signType, // 签名方式,默认为'SHA1',使用新版支付需传入'MD5'
  120. paySign: data.sign, // 支付签名
  121. success: function (res) {
  122. // 支付成功后的回调函数
  123. window.location.href='../../payment/html/paymentResult.html?seqNo='+data.seqNo;
  124. },
  125. cencel:function(res){
  126. // 支付取消回调函数
  127. // alert("支付过程中用户取消");
  128. },
  129. fail: function(res){
  130. // 支付失败回调函数
  131. // alert(JSON.stringify(res));
  132. }
  133. });
  134. }else{
  135. loading.close();
  136. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:res.msg}).show();
  137. }
  138. })
  139. },
  140. //强制设定最多只能输入两位小数
  141. checkNumber:function(payMoney){
  142. this.payMoney= (payMoney.match(/^\d*(\.?\d{0,2})/g)[0]) || null
  143. },
  144. //判断是否验证登录通过
  145. checkType:function(){
  146. var vm=this
  147. var timer = setInterval(function(){
  148. if(checktype){
  149. clearInterval(timer);
  150. vm.getData()
  151. }
  152. },10);
  153. },
  154. clearMoney:function(){
  155. this.payMoney = "";
  156. }
  157. },
  158. })
  159. })()
  160. function queryInit(){
  161. checktype=true
  162. }
  163. function getUrlParam(name){
  164. //构造一个含有目标参数的正则表达式对象
  165. var reg = new RegExp("(^|&)"+name+"=([^&]*)(&|$)");
  166. //匹配目标参数
  167. var r = window.location.search.substr(1).match(reg);
  168. //返回参数值
  169. if (r!=null) return unescape(r[2]); return null;
  170. }
  171. //判断微信版本号
  172. function judgeWxVersion(name){
  173. var ispass=false
  174. var wechatInfo = navigator.userAgent.match(/MicroMessenger\/([\d\.]+)/i)
  175. if(!wechatInfo) {
  176. loading.close();
  177. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'当前不是微信,不支持微信支付'}).show();
  178. }
  179. else
  180. {
  181. wx.checkJsApi({
  182. jsApiList: ['chooseWXPay'], // 需要检测的JS接口列表,所有JS接口列表见附录2,
  183. success: function(res) {
  184. if("errMsg"=="checkJsApi:ok"){
  185. if(res.checkResult.chooseWXPay){
  186. ispass=true
  187. }else{
  188. loading.close();
  189. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'当前微信低于5.0,不支持微信支付,请升级后支付'}).show();
  190. }
  191. }else{
  192. if ( wechatInfo[1] < "5.0" ) {
  193. loading.close();
  194. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'当前微信低于5.0,不支持微信支付,请升级后支付'}).show();
  195. }else{
  196. ispass=true
  197. }
  198. }
  199. }
  200. });
  201. }
  202. return ispass
  203. }