index.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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" v-if="!tipShow">恭喜你获得</view>
  6. <view class="choice-all" v-if="total > 1 && !tipShow">以下奖品任选其一</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" v-if="!tipShow">确认</view>
  22. </view>
  23. </view>
  24. <u-popup :show="tipShow" :round="10" mode="center">
  25. <view class="null-prize">
  26. <view class="title">该盲票已被他人买走了</view>
  27. <view class="btn" @click="toIndex">确认</view>
  28. </view>
  29. </u-popup>
  30. </view>
  31. </template>
  32. <script>
  33. import env from '../../config/env.js'
  34. import $http from '@/utils/request.js'
  35. export default {
  36. data() {
  37. return {
  38. ticketId: '',
  39. prizeList: [],
  40. total: 0,
  41. actionIndex: 0,
  42. tipShow: false
  43. };
  44. },
  45. onLoad(options) {
  46. this.ticketId = options.id
  47. this.orderId = options.orderId
  48. },
  49. onShow() {
  50. this.getPrizeList()
  51. },
  52. methods: {
  53. getPrizeList() {
  54. uni.showLoading({
  55. title: '加载中'
  56. });
  57. let data = this.orderId ? {
  58. orderId: this.orderId
  59. } : {
  60. ticketId: this.ticketId
  61. }
  62. $http.post('/api/v1/mp/user/ticket/queryHitPrizeList', data).then(res => {
  63. uni.hideLoading();
  64. if (res.code == 0) {
  65. res.data.prizeList.forEach(item => {
  66. let picUrlArr = item.picUrl.split(',')
  67. item.picUrl = env.filePublic + picUrlArr[0]
  68. })
  69. this.prizeList = res.data.prizeList
  70. this.ticketId = res.data.ticketId
  71. this.total = res.data.length
  72. } else if (res.code == 1018) {
  73. this.tipShow = true
  74. }else{
  75. this.tipShow = true
  76. }
  77. }).catch(() => {
  78. uni.hideLoading();
  79. })
  80. },
  81. selectPrize(item, index) {
  82. if (item.remainQty == 0) {
  83. uni.$u.toast('该奖品已兑完!');
  84. return
  85. }
  86. this.actionIndex = index
  87. },
  88. confirmPrize() {
  89. let _this = this
  90. let item = _this.prizeList[_this.actionIndex]
  91. uni.showModal({
  92. title: '提示',
  93. content: '确定选择该奖品吗?',
  94. success(res) {
  95. if (res.confirm) {
  96. $http.post('/api/v1/mp/user/ticket/cashPrize', {
  97. ticketId: _this.ticketId,
  98. awardsId: item.awardsId,
  99. prizeId: item.prizeId
  100. }).then(res => {
  101. if (res.code == 0) {
  102. uni.$u.toast('兑换成功');
  103. setTimeout(() => {
  104. uni.switchTab({
  105. url: '/pages/index/index'
  106. })
  107. }, 500)
  108. }
  109. })
  110. }
  111. }
  112. })
  113. },
  114. toIndex() {
  115. uni.switchTab({
  116. url: '/pages/index/index'
  117. })
  118. },
  119. }
  120. }
  121. </script>
  122. <style lang="scss" scoped>
  123. .choice {
  124. width: 100%;
  125. min-height: calc(100vh - 50px);
  126. background-image: linear-gradient(to right, #ebbba7 0%, #cfc7f8 100%);
  127. padding-bottom: 150rpx;
  128. &-title {
  129. padding-top: 100rpx;
  130. font-size: 56rpx;
  131. font-weight: bold;
  132. text-align: center;
  133. line-height: 84rpx;
  134. margin-bottom: 12rpx;
  135. }
  136. &-all {
  137. text-align: center;
  138. line-height: 40rpx;
  139. }
  140. &-list {
  141. justify-content: space-around;
  142. flex-wrap: wrap;
  143. margin-top: 60rpx;
  144. margin-bottom: 60rpx;
  145. &-item {
  146. width: 40%;
  147. height: 440rpx;
  148. margin-bottom: 40rpx;
  149. .confirm {
  150. height: 100%;
  151. background: none;
  152. box-shadow: none;
  153. border: none;
  154. }
  155. .action {
  156. height: 100%;
  157. background-color: #4cd964;
  158. box-shadow: 0px 2px 6px 0px rgba(0, 0, 0, 0.4);
  159. border: 1px solid rgba(187, 187, 187, 54);
  160. }
  161. .null {
  162. height: 100%;
  163. background: #918b8d;
  164. box-shadow: 0px 2px 6px 0px rgba(0, 0, 0, 0.4);
  165. border: 1px solid rgba(187, 187, 187, 54);
  166. }
  167. .info {
  168. width: 80%;
  169. height: 80%;
  170. background-color: #C0C0C0;
  171. }
  172. image {
  173. width: 100%;
  174. height: 60%;
  175. }
  176. .title {
  177. margin-top: 20rpx;
  178. color: #FFFFFF;
  179. text-align: center;
  180. }
  181. .tip {
  182. margin-top: 20rpx;
  183. color: red;
  184. text-align: center;
  185. }
  186. }
  187. }
  188. .btn {
  189. .confirm {
  190. width: 320rpx;
  191. height: 60rpx;
  192. line-height: 60rpx;
  193. border-radius: 8px;
  194. background-color: rgba(235, 112, 9, 100);
  195. color: rgba(255, 255, 255, 100);
  196. font-size: 28rpx;
  197. text-align: center;
  198. }
  199. }
  200. }
  201. .null-prize {
  202. display: flex;
  203. flex-direction: column;
  204. align-items: center;
  205. justify-content: center;
  206. width: 80vw;
  207. height: 320rpx;
  208. background-color: #FFFFFF;
  209. border: 1px solid rgba(187, 187, 187, 100);
  210. .btn {
  211. margin-top: 60rpx;
  212. width: 160rpx;
  213. height: 60rpx;
  214. line-height: 60rpx;
  215. border-radius: 8rpx;
  216. background-color: rgba(235, 112, 9, 100);
  217. color: rgba(255, 255, 255, 100);
  218. font-size: 28rpx;
  219. text-align: center;
  220. }
  221. }
  222. </style>