coupon-buy.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <template>
  2. <ax-body blank="0">
  3. <view class="page-background">
  4. <image :src="pageBg" mode="widthFix"></image>
  5. </view>
  6. <view style="height: 324rpx;"></view>
  7. <view class="body">
  8. <!-- 统计卡 -->
  9. <view class="app-flex c-between" style="padding-top: 10rpx;">
  10. <view class="sta-card">
  11. <view class="value">{{ userinfo.integral }}</view>
  12. <view class="name">我的积分</view>
  13. <image src="@/static/img/my-sta-bg01.png" mode="heightFix" class="bg"></image>
  14. </view>
  15. <view class="sta-card">
  16. <view class="value">{{ userinfo.accountBalance }}</view>
  17. <view class="name">可抵扣余量</view>
  18. <image src="@/static/img/my-sta-bg03.png" mode="heightFix" class="bg"></image>
  19. <view class="overflow-payment" v-if="order_info != null" @click="topage_order">
  20. <text v-if="order_info.maspStatus === 1">超{{ (order_info.maspAmount +
  21. order_info.maspRealAmount).toFixed(2) || '0.00' }}元</text>
  22. <text class="ax ax-iconline i-arrow-right icon"></text>
  23. </view>
  24. </view>
  25. </view>
  26. <!-- 购券 -->
  27. <view class="card">
  28. <view class="title">
  29. <view>请选择抵扣券</view>
  30. <template v-if="order_info != null">
  31. <view class="title-text" v-if="order_info.maspStatus === 1">
  32. 至少充值{{ (3 + ((order_info.maspAmount + order_info.maspRealAmount))).toFixed(2) || '0.00'
  33. }}元(超充{{ (order_info.maspAmount + order_info.maspRealAmount).toFixed(2) || '0.00'
  34. }}元,余量需大于3元才能启动)
  35. </view>
  36. </template>
  37. </view>
  38. <view class="new-coupons-box">
  39. <view v-for="(item, index) in coupons.data" :key="index"
  40. :class="{ newCouponsActive: coupons.index == index }" class="new-coupons"
  41. @click="choose(item, index)">
  42. <!-- :style="{ opacity: `${(3 + (order_info.maspAmount + order_info.maspRealAmount)).toFixed(2) > item.levelMoney ? '0.4' : ''}` }" -->
  43. <view class="new-coupons-price">{{ item.money }}<text style="font-size: 22rpx;">元</text>
  44. </view>
  45. <view class="new-coupons-text">充电券</view>
  46. </view>
  47. </view>
  48. </view>
  49. <!-- 提示 -->
  50. <view class="card tips">
  51. <view class="title">温馨提示</view>
  52. <view class="li">1. 抵扣券仅用于充电结算中抵扣资费,未使用完的余量,可手动发起退还</view>
  53. <view class="li">2. 抵扣券为专属专用不可转赠和出售</view>
  54. <view class="li">3. 抵扣券金额未抵扣完结,可累计到下次继续抵扣</view>
  55. <view class="li">4. 使用时可抵扣按照当前电价进行预估计算</view>
  56. <view class="li">5. 实际结算价以具体充电时段为准</view>
  57. </view>
  58. <view style="height: 100rpx;"></view>
  59. <view class="footer">
  60. <template v-if="order_info != null">
  61. <view class="payment-tips" v-if="coupons.index >= 0">
  62. 购买{{ select_num }}元,补缴{{ (order_info.maspAmount + order_info.maspRealAmount).toFixed(2) }}元,剩余{{
  63. (select_num - (order_info.maspAmount + order_info.maspRealAmount)).toFixed(2) }}元
  64. </view>
  65. </template>
  66. <button @click="pay()" class="pay" :disabled="coupons.index < 0">立即支付购买</button>
  67. <ax-ios-indicator></ax-ios-indicator>
  68. </view>
  69. </view>
  70. </ax-body>
  71. </template>
  72. <script>
  73. export default {
  74. data() {
  75. return {
  76. pageBg: 'https://national-motion.oss-cn-beijing.aliyuncs.com/20260106/900829d6fae247979389f8d75967cf21.png',
  77. userinfo: {},
  78. select_num: null,
  79. payment: null,
  80. order_info: null,
  81. coupons: {
  82. index: -1,
  83. data: []
  84. }
  85. }
  86. },
  87. onShow() {
  88. this.getMyAccount()
  89. this.getLevel()
  90. // this.select_orderstatus()
  91. // this.get_orderPayment()
  92. },
  93. onLoad(options) {
  94. this.payment = options.payment
  95. },
  96. methods: {
  97. getLevel() {
  98. this.$api.base("get", "/applet/v1/order/getReChargeLevel", {}, {}).then(res => {
  99. this.coupons.data = res.data;
  100. })
  101. },
  102. choose(item, index) {
  103. if (this.order_info != null) {
  104. let num = ((this.order_info.maspAmount + this.order_info.maspRealAmount) + 3).toFixed(2)
  105. if (num > item.levelMoney) {
  106. this.$app.popup.toast(`购买金额必须大于${num}元`)
  107. return
  108. }
  109. }
  110. this.coupons.index = this.coupons.index != index ? index : -1;
  111. this.select_num = item.levelMoney
  112. },
  113. pay() {
  114. if (!this.userinfo.appletUserId) {
  115. this.$app.url.goto('/pages/login/login')
  116. return;
  117. }
  118. // this.$app.popup.toast('充值入口正在维护,敬请期待!')
  119. // return
  120. this.$api.base("post", "/applet/v1/wft/order/createOrder", {
  121. levelId: this.coupons.data[this.coupons.index].id
  122. }, {}).then(addRes => {
  123. console.log(addRes, '创建订单返回');
  124. if (addRes.data.orderId) {
  125. this.$api.base("put", `/applet/v1/wft/order/payOrder/${addRes.data.orderId}`, {}, {}).then(res => {
  126. var payInfo = JSON.parse(res.data.params.pay_info)
  127. console.log(payInfo, '11');
  128. uni.requestPayment({
  129. provider: 'wxpay',
  130. timeStamp: payInfo.timeStamp,
  131. nonceStr: payInfo.nonceStr,
  132. package: payInfo.package,
  133. signType: payInfo.signType,
  134. paySign: payInfo.paySign,
  135. success: (res) => {
  136. console.log('success:', res);
  137. // 查询支付状态
  138. this.$api.base("get", `/applet/v1/wft/order/query/${addRes.data.orderNo}`, {}, {}).then(queryRes => {
  139. console.log(queryRes, '查询订单返回');
  140. if (queryRes.data) {
  141. setTimeout(() => {
  142. this.$app.popup.alert('支付成功', '温馨提示', {
  143. showCancel: false
  144. }).then(() => {
  145. this.$app.url.back()
  146. });
  147. }, 1000)
  148. } else {
  149. this.$app.popup.alert('支付失败,请稍后重试', '温馨提示', {
  150. showCancel: false
  151. }).then(() => {
  152. this.$app.url.back()
  153. });
  154. }
  155. })
  156. },
  157. fail: (err) => {
  158. console.log('fail:', err);
  159. this.$api.base("put", `/applet/v1/wft/order/closeOrder/${addRes.data.orderNo}`, {}, {}).then(cancelRes => {
  160. console.log(cancelRes, '取消订单返回');
  161. if (cancelRes.data) {
  162. this.$app.popup.alert('支付已取消', '温馨提示', {
  163. showCancel: false
  164. });
  165. }
  166. });
  167. //注册一个用户取消支付的事件
  168. }
  169. });
  170. })
  171. }
  172. })
  173. },
  174. get_orderPayment() {
  175. // maspStatus(1:待补缴,2:已补缴)realPredictServiceCost平台;maspAmount第三方
  176. this.$api.base("post", "/chargeApi/queryOrderList-arrearage", {}, {}).then(res => {
  177. this.order_info = res.data
  178. })
  179. },
  180. topage_order() {
  181. this.$app.url.goto('/subPackages/order/order-detail/order-detail?orderId=' + this.order_info.id);
  182. },
  183. getMyAccount() {
  184. this.$api.base("get", "/applet/v1/user/getUserInfo", {}, {}).then(res => {
  185. this.userinfo = res.data
  186. })
  187. },
  188. }
  189. }
  190. </script>
  191. <style scoped>
  192. @import url("coupon-buy.css");
  193. </style>