index.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <template>
  2. <page title="充值" ref="pageRef">
  3. <view class="paddingX24 paddingT32">
  4. <view class="input-wrapper flex-align marginT15">
  5. <view class="font5">充值金额:</view>
  6. <input
  7. v-model.trim="money"
  8. type="digit"
  9. class="flex1 marginX10 font5"
  10. placeholder="请输入金额"
  11. />
  12. </view>
  13. <view class="text-center color-2 paddingT36">充值金额可以用于购买手办,宝箱</view>
  14. <view class="text-center color-2 paddingT5 paddingB20">充值金额不可提现</view>
  15. <view>
  16. <cm-button ::height="44" @click="apply">充值</cm-button>
  17. <view
  18. class="color-theme marginT20 text-center"
  19. @click="$router.push('recharge_record')"
  20. >
  21. 充值记录>>
  22. </view>
  23. </view>
  24. </view>
  25. </page>
  26. </template>
  27. <script>
  28. import { throttle } from '@/utils'
  29. import { baseEncode } from '../../utils/utils'
  30. export default {
  31. data() {
  32. return {
  33. money: ''
  34. }
  35. },
  36. computed: {
  37. payInfo() {
  38. return this.$store.state.payInfo
  39. }
  40. },
  41. watch: {
  42. payInfo(val) {
  43. if (val && val.payResult == 'SUCCESS') {
  44. this.paySuccess(val)
  45. } else if (val && val.payResult !== 'SUCCESS') {
  46. }
  47. }
  48. },
  49. methods: {
  50. apply() {
  51. if (!this.$common.checkLogin()) return
  52. if (!this.money) return
  53. throttle.call(() => {
  54. this.realApply()
  55. })
  56. },
  57. async realApply() {
  58. const res = await this.$service.wallet.recharge(this.money, 'WXPAY_JSAPI', 'CASH')
  59. if (res) {
  60. if (res.redirectUrl) {
  61. this.thirdPay(res)
  62. } else {
  63. let payInfo = res.payInfo
  64. wx.requestPayment({
  65. timeStamp: payInfo.timeStamp,
  66. nonceStr: payInfo.nonceStr,
  67. package: payInfo.packageValue,
  68. signType: payInfo.signType,
  69. paySign: payInfo.paySign,
  70. success: (res) => {
  71. this.money = ''
  72. this.$router.push('recharge_record')
  73. },
  74. fail: (res) => {}
  75. })
  76. }
  77. }
  78. },
  79. thirdPay(data) {
  80. let self = this
  81. let redirectUrl = data.redirectUrl
  82. let requestId = data.requestId
  83. const base64Url = encodeURIComponent(baseEncode(redirectUrl))
  84. wx.openEmbeddedMiniProgram({
  85. path: 'pages/pay/order', // 启动目标页面
  86. appId: 'wx0448557563ffc600', // 启动的小程序
  87. envVersion: 'release', // develop | trial | release
  88. verify: 'binding',
  89. extraData: {
  90. title: '订单付款', // 导航Title
  91. tip: `待支付订单付款`, // 支付提示内容
  92. requestId: requestId, // 本次请求ID
  93. action: 'epPay', // 支付模式
  94. payUrl: base64Url // 支付地址, 需要进行Base64转换
  95. },
  96. success: (res) => {
  97. console.info('启动成功', res)
  98. },
  99. fail: (err) => {
  100. console.info('启动失败', err)
  101. }
  102. })
  103. },
  104. paySuccess(payInfo) {
  105. this.money = ''
  106. this.$router.push('recharge_record')
  107. this.$store.state.payInfo = null
  108. }
  109. }
  110. }
  111. </script>
  112. <style>
  113. page {
  114. background: #fff;
  115. }
  116. </style>
  117. <style lang="scss" scoped>
  118. .input-wrapper {
  119. height: 104rpx;
  120. border: 2rpx solid #ddd;
  121. border-radius: 16rpx;
  122. padding: 0 32rpx;
  123. }
  124. </style>