greenChange.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <template>
  2. <view class="content">
  3. <view class="tab flex">
  4. <view class="tab-name">可用于兑换的水滴:</view>
  5. <view class="tab-val">{{ userInfo.green_integral || '0' }}</view>
  6. </view>
  7. <view class="tab flex">
  8. <view class="tab-name">兑换比例:</view>
  9. <view class="tab-val">{{ bl }}: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 { getGreenBl, getUserInfo, exchangeGreen } 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.getGreenBl();
  39. },
  40. onReachBottom() {},
  41. onReady() {},
  42. computed: {
  43. ...mapState('user', ['userInfo']),
  44. could() {
  45. if (this.userInfo.green_integral == 0) {
  46. return 0;
  47. } else {
  48. return Math.floor(this.userInfo.green_integral / this.bl);
  49. }
  50. }
  51. },
  52. methods: {
  53. ...mapMutations('user', ['setUserInfo']),
  54. getGreenBl() {
  55. getGreenBl().then(res => {
  56. console.log(res);
  57. this.bl = res.data.bl;
  58. this.getUserInfo();
  59. });
  60. },
  61. getUserInfo() {
  62. let obj = this;
  63. getUserInfo().then(res => {
  64. obj.setUserInfo(res.data);
  65. obj.load = false;
  66. });
  67. },
  68. exchangeGreen() {
  69. let obj = this;
  70. if (obj.load) {
  71. return;
  72. }
  73. if (obj.changeNum == '') {
  74. return obj.$api.msg('请输入兑换绿卡数量');
  75. }
  76. if (obj.userInfo.green_integral == 0) {
  77. return obj.$api.msg('您的绿积分不足');
  78. }
  79. if (obj.changeNum * 1 > obj.could) {
  80. return obj.$api.msg('您的绿积分不足');
  81. }
  82. obj.load = true;
  83. exchangeGreen({
  84. num: obj.changeNum
  85. })
  86. .then(({ data }) => {
  87. console.log(data);
  88. uni.showToast({
  89. title: '提交成功',
  90. duration: 2000,
  91. position: 'top'
  92. });
  93. obj.getGreenBl();
  94. // obj.load = false
  95. })
  96. .catch(err => {
  97. obj.load = false;
  98. });
  99. }
  100. }
  101. };
  102. </script>
  103. <style lang="scss">
  104. .tab {
  105. font-size: 32rpx;
  106. font-weight: 500;
  107. color: #333333;
  108. line-height: 110rpx;
  109. border-bottom: 1px solid #eee;
  110. width: 710rpx;
  111. margin: auto;
  112. .tab-name {
  113. flex-shrink: 0;
  114. }
  115. .tab-val {
  116. flex-grow: 1;
  117. text-align: right;
  118. font-size: 48rpx;
  119. font-weight: bold;
  120. }
  121. }
  122. .sub {
  123. width: 670rpx;
  124. line-height: 88rpx;
  125. background: #ff4c4c;
  126. border-radius: 10rpx;
  127. font-size: 32rpx;
  128. font-weight: bold;
  129. color: #ffffff;
  130. text-align: center;
  131. margin: 60rpx auto 0;
  132. }
  133. .loading {
  134. background: #999;
  135. }
  136. </style>