change.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <template>
  2. <view class="content">
  3. <view class="tab flex">
  4. <view class="tab-name">可用于兑换的积分:</view>
  5. <view class="tab-val">{{ userInfo.integral || '0' }}</view>
  6. </view>
  7. <view class="tab flex">
  8. <view class="tab-name">兑换比例:</view>
  9. <view class="tab-val">{{ userInfo.integral_to_order_integral_ratio }}:1</view>
  10. </view>
  11. <view class="tab flex">
  12. <view class="tab-name">可兑换入场券数量:</view>
  13. <view class="tab-val">{{ could }}</view>
  14. </view>
  15. <view class="tab flex">
  16. <view class="tab-name">申请兑换入场券数量:</view>
  17. <input type="number" class="tab-val" placeholder="请输入兑换入场券数量" placeholder-style="font-size:28rpx;" v-model="changeNum" />
  18. <!-- <view class="tab-val">
  19. {{sqss}}
  20. </view> -->
  21. </view>
  22. <view class="sub" :class="{ loading: load }" @click="exchangeGreen">立即兑换</view>
  23. </view>
  24. </template>
  25. <script>
  26. import { mapState, mapMutations } from 'vuex';
  27. import { getUserInfo, exchange } from '@/api/user.js';
  28. export default {
  29. data() {
  30. return {
  31. bl: 0,
  32. load: true,
  33. changeNum: ''
  34. };
  35. },
  36. onLoad() {},
  37. onShow() {
  38. this.getUserInfo();
  39. },
  40. onReachBottom() {},
  41. onReady() {},
  42. computed: {
  43. ...mapState('user', ['userInfo']),
  44. could() {
  45. if (this.userInfo.integral == 0) {
  46. return 0;
  47. } else {
  48. return Math.floor(this.userInfo.integral / this.userInfo.integral_to_order_integral_ratio);
  49. }
  50. }
  51. },
  52. methods: {
  53. ...mapMutations('user', ['setUserInfo']),
  54. getUserInfo() {
  55. let obj = this;
  56. getUserInfo().then(res => {
  57. obj.setUserInfo(res.data);
  58. obj.load = false;
  59. });
  60. },
  61. exchangeGreen() {
  62. let obj = this;
  63. if (obj.load) {
  64. return;
  65. }
  66. if (obj.changeNum == '') {
  67. return obj.$api.msg('请输入兑换入场券数量');
  68. }
  69. if (obj.changeNum * 1 > obj.could) {
  70. return obj.$api.msg('您的积分不足');
  71. }
  72. obj.load = true;
  73. exchange({
  74. num: obj.changeNum
  75. })
  76. .then(({ data }) => {
  77. console.log(data);
  78. obj.load = false;
  79. obj.changeNum = '';
  80. uni.showToast({
  81. title: '提交成功',
  82. duration: 2000,
  83. position: 'top'
  84. });
  85. obj.getUserInfo();
  86. })
  87. .catch(err => {
  88. obj.load = false;
  89. });
  90. }
  91. }
  92. };
  93. </script>
  94. <style lang="scss">
  95. .tab {
  96. font-size: 32rpx;
  97. font-weight: 500;
  98. color: #333333;
  99. line-height: 110rpx;
  100. border-bottom: 1px solid #eee;
  101. width: 710rpx;
  102. margin: auto;
  103. .tab-name {
  104. flex-shrink: 0;
  105. }
  106. .tab-val {
  107. flex-grow: 1;
  108. text-align: right;
  109. font-size: 48rpx;
  110. font-weight: bold;
  111. }
  112. }
  113. .sub {
  114. width: 670rpx;
  115. line-height: 88rpx;
  116. background: #ff4c4c;
  117. border-radius: 10rpx;
  118. font-size: 32rpx;
  119. font-weight: bold;
  120. color: #ffffff;
  121. text-align: center;
  122. margin: 60rpx auto 0;
  123. }
  124. .loading {
  125. background: #999;
  126. }
  127. </style>