coupon-buy.vue 3.7 KB

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