coupon-buy.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <template>
  2. <ax-body>
  3. <view class="page-background">
  4. <image src="@/static/img/page-bg01.png" mode="widthFix"></image>
  5. </view>
  6. <view class="body">
  7. <!-- 统计卡 -->
  8. <view class="app-flex c-between">
  9. <view class="sta-card">
  10. <view class="value">{{userinfo.integralNum}}</view>
  11. <view class="name">我的积分</view>
  12. <image src="@/static/img/my-sta-bg01.png" mode="heightFix" class="bg"></image>
  13. </view>
  14. <view class="sta-card">
  15. <view class="value">{{userinfo.params.balance}}</view>
  16. <view class="name">可抵扣余量</view>
  17. <image src="@/static/img/my-sta-bg03.png" mode="heightFix" class="bg"></image>
  18. </view>
  19. </view>
  20. <!-- 购券 -->
  21. <view class="card">
  22. <view class="title">
  23. <view>请选择抵扣券</view>
  24. </view>
  25. <view class="coupons">
  26. <view v-for="(item,index) in coupons.data" :key="index" :class="{active:coupons.index==index}"
  27. @click="choose(item,index)" class="coupon-item">
  28. <view class="ticket">
  29. <view class="value"><text class="val">{{item.levelMoney}}</text>
  30. <view class="unit">元</view>
  31. </view>
  32. <view class="line-wrap">
  33. <view class="circle"></view>
  34. <view class="line"></view>
  35. <view class="circle"></view>
  36. </view>
  37. <view class="margin"></view>
  38. </view>
  39. <view class="trapezium"></view>
  40. <view class="text">充电券</view>
  41. </view>
  42. </view>
  43. </view>
  44. <!-- 提示 -->
  45. <view class="card tips">
  46. <view class="title">温馨提示</view>
  47. <view class="li">1. 抵扣券仅用于充电结算中抵扣资费,未使用完的余量,可手动发起退还</view>
  48. <view class="li">2. 抵扣券为专属专用不可转赠和出售</view>
  49. <view class="li">3. 抵扣券金额未抵扣完结,可累计到下次继续抵扣</view>
  50. <view class="li">4. 使用时可抵扣按照当前电价进行预估计算</view>
  51. <view class="li">5. 实际结算价以具体充电时段为准</view>
  52. </view>
  53. <view class="footer">
  54. <button @click="pay()" class="pay" :disabled="coupons.index<0">立即支付购买</button>
  55. <ax-ios-indicator></ax-ios-indicator>
  56. </view>
  57. </view>
  58. </ax-body>
  59. </template>
  60. <script>
  61. export default {
  62. data() {
  63. return {
  64. userinfo: {},
  65. coupons: {
  66. index: -1,
  67. data: []
  68. }
  69. }
  70. },
  71. onShow() {
  72. this.getMyAccount()
  73. this.getLevel()
  74. },
  75. methods: {
  76. getLevel() {
  77. this.$api.base("post", "/orderApi/getReChargeLevel", {}, {}).then(res => {
  78. this.coupons.data = res.levels;
  79. })
  80. },
  81. choose(item, index) {
  82. this.coupons.index = this.coupons.index != index ? index : -1;
  83. },
  84. pay() {
  85. if (!this.userinfo.phone) {
  86. this.$app.url.goto('/pages/login/login')
  87. return;
  88. }
  89. this.$api.base("post", "/orderApi/addOrder", {
  90. levelId: this.coupons.data[this.coupons.index].id
  91. }, {}).then(addRes => {
  92. if (addRes.orderId) {
  93. this.$api.base("post", "/orderApi/payOrder", {
  94. orderId: addRes.orderId
  95. }, {}).then(res => {
  96. var payInfo = JSON.parse(res.wx.wx.pay_info)
  97. uni.requestPayment({
  98. provider: 'wxpay',
  99. timeStamp: payInfo.timeStamp,
  100. nonceStr: payInfo.nonceStr,
  101. package: payInfo.package,
  102. signType: payInfo.signType,
  103. paySign: payInfo.paySign,
  104. success: (res) => {
  105. console.log('success:', res);
  106. //注册一个用户支付成功后点确定的事件
  107. this.$app.popup.alert('支付成功', '温馨提示', {
  108. showCancel: false
  109. }).then(() => {
  110. this.$app.url.back()
  111. });
  112. },
  113. fail: (err) => {
  114. console.log('fail:', err);
  115. //注册一个用户取消支付的事件
  116. }
  117. });
  118. })
  119. }
  120. })
  121. },
  122. getMyAccount() {
  123. this.$api.base("post", "/userApi/getUserAccount", {}, {}).then(res => {
  124. this.userinfo = res.accountInfo
  125. })
  126. },
  127. }
  128. }
  129. </script>
  130. <style scoped>
  131. @import url("coupon-buy.css");
  132. </style>