weixin-pay.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <template>
  2. <div class="weixin-pay">
  3. <div class="content">
  4. <div class="weixin-pay-info">
  5. <div class="item">
  6. <div class="tip-text">{{$t('payment.orderSubmittedSuccessfully')}}!</div>
  7. <div class="act-pay">
  8. {{$t('payment.actualPayment')}}:
  9. <span class="price">¥{{total}}</span>
  10. </div>
  11. </div>
  12. <div class="item">
  13. <div class="time" v-if="isOverTime && $t('language') == 'zh'">
  14. 请在
  15. <span class="warning">{{min}} : {{sec}}</span>内付款,否则交易会被取消。
  16. </div>
  17. <div class="time" v-if="isOverTime && $t('language') == 'en'">
  18. please pay within
  19. <span class="warning">{{min}} : {{sec}}</span>,otherwise the transaction will be cancelled。
  20. </div>
  21. <div class="time" v-if="!isOverTime">{{$t('payment.orderHasExpired')}}</div>
  22. <div class="back-pay" @click="checkOtherPayWay">{{$t('payment.chooseAnotherPaymentMethod')}}</div>
  23. </div>
  24. </div>
  25. <weixin-pay-code v-if="weixinCodeUrl !== ''" :isShowCodeMask="isShowCodeMask" :weixinCodeUrl="weixinCodeUrl" />
  26. </div>
  27. </div>
  28. </template>
  29. <script>
  30. import weixinPayCode from '~/components/weixin-pay-code'
  31. // import QRCode from 'qrcode'
  32. export default {
  33. data () {
  34. return {
  35. orderNumber: '',
  36. total: 0,
  37. endTime: '',
  38. min: '00',
  39. sec: '00',
  40. isShowCodeMask: false, //二维码是否过期
  41. checkIsPay: null,
  42. timer: null,
  43. isOverTime: true,
  44. weixinCodeUrl: '' //微信二维码数据
  45. }
  46. },
  47. mounted () {
  48. this.orderNumber = sessionStorage.getItem("pay_orderNumber")
  49. this.wxPayCode()
  50. this.getEndTime()
  51. this.isPay()
  52. },
  53. components: {
  54. weixinPayCode
  55. },
  56. methods: {
  57. // 请求订单剩余时间
  58. getEndTime () {
  59. this.$axios.get('/p/order/getOrderPayInfoByOrderNumber', {
  60. params: {
  61. orderNumbers: this.orderNumber
  62. }
  63. }).then(({ data }) => {
  64. this.total = data.totalFee
  65. this.endTime = data.endTime
  66. this.countTime()
  67. })
  68. },
  69. // 倒计时
  70. countTime () {
  71. // 获取当前时间
  72. let date = new Date()
  73. let now = date.getTime()
  74. // // 设置截止时间
  75. let end = new Date(this.endTime).getTime()
  76. // 时间差
  77. let leftTime = end - now
  78. // 定义变量 d,h,m,s保存倒计时的时间
  79. if (leftTime >= 0) {
  80. // 分
  81. let m = Math.floor(leftTime / 1000 / 60 % 60)
  82. this.min = m < 10 ? '0' + m : m
  83. // 秒
  84. let s = Math.floor(leftTime / 1000 % 60)
  85. this.sec = s < 10 ? '0' + s : s
  86. } else {
  87. this.min = '00'
  88. this.sec = '00'
  89. this.isOverTime = false
  90. }
  91. // 等于0的时候不调用
  92. if (Number(this.min) === 0 && Number(this.sec) === 0) {
  93. this.isShowCodeMask = true
  94. return this.isOverTime = false
  95. } else {
  96. // 递归每秒调用countTime方法,显示动态时间效果,
  97. this.timer = setTimeout(this.countTime, 1000)
  98. }
  99. },
  100. //选择其他支付方式
  101. checkOtherPayWay () {
  102. this.$router.push({ path: '/payment' })
  103. },
  104. // 生成微信支付二维码
  105. wxPayCode () {
  106. let that = this
  107. this.$axios.post('/p/order/pay', {
  108. payType: 3,
  109. orderNumbers: this.orderNumber
  110. }).then(({ data }) => {
  111. this.$nextTick(function () {
  112. that.weixinCodeUrl = data
  113. })
  114. })
  115. },
  116. //判断是否已经支付
  117. isPay () {
  118. this.checkIsPay = window.setInterval(() => {
  119. this.$axios.get('/p/order/isPay/' + this.orderNumber).then(({ data }) => {
  120. if (data) {
  121. this.$router.push({
  122. path: '/user-center/uc-order'
  123. })
  124. }
  125. })
  126. }, 3000)
  127. }
  128. },
  129. destroyed () {
  130. if (this.timer) { //如果定时器在运行则关闭
  131. clearInterval(this.timer);
  132. }
  133. if (this.checkIsPay) { //如果定时器在运行则关闭
  134. clearInterval(this.checkIsPay);
  135. }
  136. }
  137. }
  138. </script>
  139. <style scoped src='~/assets/css/weixin-pay.css'>
  140. </style>