index.vue 4.2 KB

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