index.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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.orderId = options.orderId
  41. this.getPrizeList()
  42. },
  43. methods: {
  44. getPrizeList() {
  45. uni.showLoading({
  46. title: '加载中'
  47. });
  48. let data = this.orderId ? { orderId: this.orderId } : { ticketId: this.ticketId }
  49. $http.post('/api/v1/mp/user/ticket/queryHitPrizeList', data).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. }
  58. }).catch(() => {
  59. uni.hideLoading();
  60. })
  61. },
  62. selectPrize(item, index) {
  63. if (item.remainQty == 0) {
  64. uni.$u.toast('该奖品已兑完!');
  65. return
  66. }
  67. this.actionIndex = index
  68. },
  69. confirmPrize() {
  70. let _this = this
  71. let item = _this.prizeList[_this.actionIndex]
  72. uni.showModal({
  73. title: '提示',
  74. content: '确定选择该奖品吗?',
  75. success(res) {
  76. if (res.confirm) {
  77. $http.post('/api/v1/mp/user/ticket/cashPrize', {
  78. ticketId: _this.ticketId,
  79. awardsId: item.awardsId,
  80. prizeId: item.prizeId
  81. }).then(res => {
  82. if (res.code == 0) {
  83. uni.$u.toast('兑换成功');
  84. setTimeout(() => {
  85. uni.switchTab({
  86. url: '/pages/index/index'
  87. })
  88. }, 500)
  89. }
  90. })
  91. }
  92. }
  93. })
  94. },
  95. }
  96. }
  97. </script>
  98. <style lang="scss" scoped>
  99. .choice {
  100. width: 100%;
  101. min-height: calc(100vh - 50px);
  102. 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;
  103. padding-bottom: 150rpx;
  104. &-title {
  105. padding-top: 100rpx;
  106. font-size: 56rpx;
  107. font-weight: bold;
  108. text-align: center;
  109. line-height: 84rpx;
  110. margin-bottom: 12rpx;
  111. }
  112. &-all {
  113. text-align: center;
  114. line-height: 40rpx;
  115. }
  116. &-list {
  117. justify-content: space-around;
  118. flex-wrap: wrap;
  119. margin-top: 60rpx;
  120. margin-bottom: 60rpx;
  121. &-item {
  122. width: 40%;
  123. height: 440rpx;
  124. margin-bottom: 40rpx;
  125. .confirm {
  126. height: 100%;
  127. background: none;
  128. box-shadow: none;
  129. border: none;
  130. }
  131. .action {
  132. height: 100%;
  133. background-color: #4cd964;
  134. box-shadow: 0px 2px 6px 0px rgba(0, 0, 0, 0.4);
  135. border: 1px solid rgba(187, 187, 187, 54);
  136. }
  137. .null {
  138. height: 100%;
  139. background: #918b8d;
  140. box-shadow: 0px 2px 6px 0px rgba(0, 0, 0, 0.4);
  141. border: 1px solid rgba(187, 187, 187, 54);
  142. }
  143. .info {
  144. width: 80%;
  145. height: 80%;
  146. background-color: #C0C0C0;
  147. }
  148. image {
  149. width: 100%;
  150. height: 60%;
  151. }
  152. .title {
  153. margin-top: 20rpx;
  154. color: #FFFFFF;
  155. text-align: center;
  156. }
  157. .tip {
  158. margin-top: 20rpx;
  159. color: red;
  160. text-align: center;
  161. }
  162. }
  163. }
  164. .btn {
  165. .confirm {
  166. width: 320rpx;
  167. height: 60rpx;
  168. line-height: 60rpx;
  169. border-radius: 8px;
  170. background-color: rgba(235, 112, 9, 100);
  171. color: rgba(255, 255, 255, 100);
  172. font-size: 28rpx;
  173. text-align: center;
  174. }
  175. }
  176. }
  177. </style>