index.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <template>
  2. <view>
  3. <u-navbar title="选择奖品" :border="true" :placeholder="true" :autoBack="true" bgColor="#fff" />
  4. <view class="choice">
  5. <view class="choice-title">恭喜你获得</view>
  6. <view class="choice-all" v-if="total > 1">以下奖品任选其一</view>
  7. <view class="flex choice-list">
  8. <view class="choice-list-item" v-for="(item, index) in prizeList" :key="index"
  9. @click="selectPrize(item, index)">
  10. <view
  11. :class="{'flex action': actionIndex == index, 'flex confirm': actionIndex != index, 'flex null': item.remainQty == 0}">
  12. <view class="info">
  13. <image :src="item.picUrl" mode="aspectFill"></image>
  14. <view class="title">{{ item.title }}</view>
  15. <view class="tip" v-if="item.remainQty == 0">已兑完</view>
  16. </view>
  17. </view>
  18. </view>
  19. </view>
  20. <view class="flex btn">
  21. <view class="confirm" @click="confirmPrize">确认</view>
  22. </view>
  23. </view>
  24. </view>
  25. </template>
  26. <script>
  27. import env from '../../config/env.js'
  28. import $http from '@/utils/request.js'
  29. export default {
  30. data() {
  31. return {
  32. ticketId: '',
  33. prizeList: [],
  34. total: 0,
  35. actionIndex: 0,
  36. };
  37. },
  38. onLoad(options) {
  39. this.ticketId = options.id
  40. this.getPrizeList()
  41. },
  42. methods: {
  43. getPrizeList() {
  44. uni.showLoading({
  45. title: '加载中'
  46. });
  47. $http.post('/api/v1/mp/user/ticket/queryHitPrizeList', {
  48. ticketId: this.ticketId
  49. }).then(res => {
  50. uni.hideLoading();
  51. if (res.code == 0) {
  52. res.data.forEach(item => {
  53. item.picUrl = env.filePublic + item.picUrl
  54. })
  55. this.prizeList = res.data
  56. this.total = res.data.length
  57. console.log(this.total);
  58. }
  59. }).catch(() => {
  60. uni.hideLoading();
  61. })
  62. },
  63. selectPrize(item, index) {
  64. if (item.remainQty == 0) {
  65. uni.$u.toast('该奖品已兑完!');
  66. return
  67. }
  68. this.actionIndex = index
  69. console.log(item, index);
  70. },
  71. confirmPrize() {
  72. let _this = this
  73. let item = _this.prizeList[_this.actionIndex]
  74. console.log(item);
  75. uni.showModal({
  76. title: '提示',
  77. content: '确定选择该奖品吗?',
  78. success(res) {
  79. if (res.confirm) {
  80. $http.post('/api/v1/mp/user/ticket/cashPrize', {
  81. ticketId: _this.ticketId,
  82. awardsId: item.awardsId,
  83. prizeId: item.prizeId
  84. }).then(res => {
  85. if (res.code == 0) {
  86. uni.$u.toast('兑换成功');
  87. setTimeout(() => {
  88. uni.switchTab({
  89. url: '/pages/index/index'
  90. })
  91. }, 500)
  92. }
  93. })
  94. }
  95. }
  96. })
  97. },
  98. }
  99. }
  100. </script>
  101. <style lang="scss" scoped>
  102. .choice {
  103. width: 100%;
  104. min-height: calc(100vh - 50px);
  105. background: url(https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic3.zhimg.com%2F50%2Fv2-a6f5c8b5b66fe87e4e79c1fc82a61a36_hd.jpg&refer=http%3A%2F%2Fpic3.zhimg.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1649658373&t=f216ee4825d5b36e62aa3a490516bfb1) center center;
  106. padding-bottom: 150rpx;
  107. &-title {
  108. padding-top: 100rpx;
  109. font-size: 56rpx;
  110. font-weight: bold;
  111. text-align: center;
  112. line-height: 84rpx;
  113. margin-bottom: 12rpx;
  114. }
  115. &-all {
  116. text-align: center;
  117. line-height: 40rpx;
  118. }
  119. &-list {
  120. justify-content: space-around;
  121. flex-wrap: wrap;
  122. margin-top: 60rpx;
  123. margin-bottom: 60rpx;
  124. &-item {
  125. width: 40%;
  126. height: 440rpx;
  127. margin-bottom: 40rpx;
  128. .confirm {
  129. height: 100%;
  130. background: none;
  131. box-shadow: none;
  132. border: none;
  133. }
  134. .action {
  135. height: 100%;
  136. background-color: #4cd964;
  137. box-shadow: 0px 2px 6px 0px rgba(0, 0, 0, 0.4);
  138. border: 1px solid rgba(187, 187, 187, 54);
  139. }
  140. .null {
  141. height: 100%;
  142. background: #918b8d;
  143. box-shadow: 0px 2px 6px 0px rgba(0, 0, 0, 0.4);
  144. border: 1px solid rgba(187, 187, 187, 54);
  145. }
  146. .info {
  147. width: 80%;
  148. height: 80%;
  149. background-color: #C0C0C0;
  150. }
  151. image {
  152. width: 100%;
  153. height: 60%;
  154. }
  155. .title {
  156. margin-top: 20rpx;
  157. color: #FFFFFF;
  158. text-align: center;
  159. }
  160. .tip {
  161. margin-top: 20rpx;
  162. color: red;
  163. text-align: center;
  164. }
  165. }
  166. }
  167. .btn {
  168. .confirm {
  169. width: 320rpx;
  170. height: 60rpx;
  171. line-height: 60rpx;
  172. border-radius: 8px;
  173. background-color: rgba(235, 112, 9, 100);
  174. color: rgba(255, 255, 255, 100);
  175. font-size: 28rpx;
  176. text-align: center;
  177. }
  178. }
  179. }
  180. </style>