payment.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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. cardlenght:0,
  20. },
  21. mounted: function() {
  22. var vm = this
  23. loading.showModal();
  24. checkUserAgent();
  25. vm.code=JSON.parse(localStorage.getItem("wlyyAgent")).uid
  26. vm.checkType()
  27. $(".c-ser-input").focus()
  28. },
  29. methods: {
  30. //获取列表数据
  31. getData:function(){
  32. var vm=this
  33. sendPost("patient/card/getCardList", {patient:vm.code}, "json", "get",function(){
  34. loading.close();
  35. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请求失败'}).show();
  36. }, function(res){
  37. if(res.status == 200){
  38. if(res.data.length>0){
  39. vm.cardlenght=res.data.length
  40. if(Request.id){
  41. vm.data=res.data.filter(function(item){
  42. return item.id==Request.id
  43. })[0]
  44. if(!vm.data){
  45. vm.data=res.data.filter(function(item){
  46. return item.isDefault==1
  47. })[0]
  48. }
  49. }else{
  50. vm.data=res.data.filter(function(item){
  51. return item.isDefault==1
  52. })[0]
  53. }
  54. if(!vm.data){
  55. vm.data=res.data[0]
  56. }
  57. vm.cardId=vm.data.id
  58. vm.getCardInfo()
  59. }else{
  60. dialog({
  61. content: "请先绑定就诊卡!",
  62. okValue: '确定',
  63. ok: function(){
  64. window.location.href='../../payment/html/patientIDCards.html';
  65. },
  66. }).showModal()
  67. }
  68. }else{
  69. loading.close();
  70. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'数据获取失败'}).show();
  71. }
  72. })
  73. },
  74. //获取列表数据
  75. getCardInfo:function(){
  76. var vm=this
  77. sendPost("patient/card/getCardInfo", {id:vm.cardId}, "json", "get",function(){
  78. loading.close();
  79. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请求失败'}).show();
  80. }, function(res){
  81. if(res.status == 200){
  82. loading.close();
  83. vm.data=res.data
  84. if(vm.paytype=="2"){
  85. vm.surplusMoney=vm.data.cardInpMoney?vm.data.cardInpMoney:0
  86. vm.cardNo=vm.data.inpCardNo
  87. }else{
  88. vm.surplusMoney=vm.data.cardMoney?vm.data.cardMoney:0
  89. vm.cardNo=vm.data.cardNo
  90. }
  91. }else{
  92. loading.close();
  93. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'数据获取失败'}).show();
  94. }
  95. })
  96. },
  97. //去支付
  98. toPayment:function(){
  99. var vm=this
  100. loading.showModal();
  101. if(vm.payMoney){
  102. if(judgeWxVersion()){
  103. vm.getWeixinSign()
  104. }
  105. }else{
  106. loading.close();
  107. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请输入充值金额'}).show();
  108. }
  109. },
  110. //获得微信sdk信息
  111. getWeixinSign:function() {
  112. var vm=this
  113. var params = {};
  114. params.pageUrl = window.location.href;
  115. sendPost("weixin/getSign", params, "json", "post",function(){
  116. loading.close();
  117. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请求失败'}).show();
  118. }, function(res){
  119. if(res.status == 200) {
  120. var timestamp = res.data.timestamp;
  121. var noncestr = res.data.noncestr;
  122. var signature = res.data.signature;
  123. wx.config({
  124. //debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
  125. appId: appId, // 必填,公众号的唯一标识
  126. timestamp: timestamp, // 必填,生成签名的时间戳
  127. nonceStr: noncestr, // 必填,生成签名的随机串
  128. signature: signature, // 必填,签名,见附录1
  129. jsApiList: [
  130. 'chooseWXPay',
  131. 'checkJsApi'
  132. ] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
  133. });
  134. wx.ready(function(){
  135. vm.wxReady()
  136. })
  137. }else{
  138. loading.close();
  139. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:res.msg}).show();
  140. }
  141. })
  142. },
  143. wxReady:function(){
  144. var vm=this
  145. var params = {
  146. patient:vm.data.patient,
  147. healthNo:vm.cardNo,
  148. healthType:vm.paytype,
  149. payAmount:parseFloat(vm.payMoney).toFixed(2),
  150. spbillCreateIp:returnCitySN["cip"],
  151. // code:getUrlParam("code"),
  152. openid:JSON.parse(localStorage.getItem("wlyyAgent")).openid
  153. };
  154. sendPost("third/hy/pay/createPayOrder", params, "json", "post",function(){
  155. loading.close();
  156. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请求失败'}).show();
  157. }, function(res){
  158. if(res.status == 200) {
  159. loading.close();
  160. var data = res.data;
  161. wx.chooseWXPay({
  162. appId:data.appId,
  163. timestamp: data.timeStamp, // 支付签名时间戳,注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
  164. nonceStr: data.nonceStr, // 支付签名随机串,不长于 32 位
  165. package: data.package, // 统一支付接口返回的prepay_id参数值,提交格式如:prepay_id=***)
  166. signType: data.signType, // 签名方式,默认为'SHA1',使用新版支付需传入'MD5'
  167. paySign: data.sign, // 支付签名
  168. success: function (res) {
  169. // 支付成功后的回调函数
  170.                                window.location.href='../../payment/html/paymentResult.html?seqNo='+data.seqNo;
  171. },
  172. cencel:function(res){
  173. // 支付取消回调函数
  174. //alert("支付过程中用户取消");
  175. },
  176. fail: function(res){
  177. // 支付失败回调函数
  178. var errorparams={seqNo:data.seqNo,wxErrorMsg:res.errMsg}
  179. sendPost("third/hy/pay/setPayLogWxFail", errorparams, "json", "post",function(){
  180. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请求失败'}).show();
  181. }, function(res){
  182. window.location.href='../../payment/html/paymentResult.html?seqNo='+data.seqNo;
  183. })
  184. }
  185. });
  186. }else{
  187. loading.close();
  188. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:res.msg}).show();
  189. }
  190. })
  191. },
  192. //强制设定最多只能输入两位小数
  193. checkNumber:function(payMoney){
  194. var myreg=/^[0][0-9]{1}$/;
  195. if(myreg.test(payMoney)){
  196. payMoney="0"
  197. }
  198. this.payMoney= (payMoney.match(/^\d*(\.?\d{0,2})/g)[0]) || null
  199. if(this.payMoney>20000){
  200. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:"支付金额不得超过20000"}).show();
  201. this.payMoney=20000
  202. }
  203. },
  204. //跳转切换就诊卡
  205. changeCards:function(){
  206. window.location.href='../../payment/html/changeCards.html?pre=payment&paytype='+Request.paytype;
  207. },
  208. //判断是否验证登录通过
  209. checkType:function(){
  210. var vm=this
  211. var timer = setInterval(function(){
  212. if(checktype){
  213. clearInterval(timer);
  214. vm.getData()
  215. }
  216. },10);
  217. },
  218. },
  219. })
  220. })()
  221. function queryInit(){
  222. checktype=true
  223. }
  224. function getUrlParam(name){
  225. //构造一个含有目标参数的正则表达式对象
  226. var reg = new RegExp("(^|&)"+name+"=([^&]*)(&|$)");
  227. //匹配目标参数
  228. var r = window.location.search.substr(1).match(reg);
  229. //返回参数值
  230. if (r!=null) return unescape(r[2]); return null;
  231. }
  232. //判断微信版本号
  233. function judgeWxVersion(name){
  234. var ispass=false
  235. var wechatInfo = navigator.userAgent.match(/MicroMessenger\/([\d\.]+)/i)
  236. if(!wechatInfo) {
  237. loading.close();
  238. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'当前不是微信,不支持微信支付'}).show();
  239. }
  240. else
  241. {
  242. if ( wechatInfo[1] < "5.0" ) {
  243. loading.close();
  244. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'当前微信低于5.0,不支持微信支付,请升级后支付'}).show();
  245. }else{
  246. ispass=true
  247. }
  248. }
  249. return ispass
  250. }