greenChange.vue 3.2 KB

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