index.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  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="{'item-info action': actionIndex == index && total > 1, 'item-info confirm': actionIndex != index, 'item-info null': item.remainQty == 0}">
  12. <view class="flex info">
  13. <image :src="item.picUrl" mode="aspectFill"></image>
  14. </view>
  15. <view class="title" v-if="item.prizeType && item.prizeType.value != 'coin'">{{ item.title }}
  16. </view>
  17. <view class="title" v-else>盲豆x {{ item.value }}</view>
  18. <view class="tip" v-if="item.remainQty == 0">已兑完</view>
  19. <view class="flex action-icon" v-if="actionIndex == index && total > 1">
  20. <u-icon name="checkmark" color="#fff" size="24"></u-icon>
  21. </view>
  22. </view>
  23. </view>
  24. </view>
  25. <view class="flex btn">
  26. <view class="confirm" @click="confirmPrize" v-if="!tipShow">确认</view>
  27. </view>
  28. </view>
  29. <u-popup :show="tipShow" :round="10" mode="center">
  30. <view class="null-prize">
  31. <view class="title">该盲票已被他人买走了</view>
  32. <view class="btn" @click="toIndex">确认</view>
  33. </view>
  34. </u-popup>
  35. <u-popup :show="comfirmShow" :round="10" mode="center">
  36. <view class="confirm-prize">
  37. <view class="flex confirm-prize-info">
  38. <image :src="actionInfo.picUrl" mode="aspectFill"></image>
  39. <view class="title" v-if="actionInfo.prizeType && actionInfo.prizeType.value != 'coin'">
  40. {{ actionInfo.title }}
  41. </view>
  42. <view class="title" v-else>盲豆x {{ actionInfo.value }}</view>
  43. </view>
  44. <view class="confirm-prize-tip" v-if="actionInfo.prizeType && actionInfo.prizeType.value != 'coin'">
  45. 已放入我的奖品库</view>
  46. <view class="confirm-prize-tip" v-else>已放入“我的盲豆”</view>
  47. <view class="flex confirm-prize-btn">
  48. <view class="back" @click="back">返回</view>
  49. <view class="confirm" @click="toPrize">前往查看</view>
  50. </view>
  51. </view>
  52. </u-popup>
  53. </view>
  54. </template>
  55. <script>
  56. import env from '../../config/env.js'
  57. import $http from '@/utils/request.js'
  58. export default {
  59. data() {
  60. return {
  61. ticketId: '',
  62. prizeList: [],
  63. total: 0,
  64. actionIndex: 0,
  65. tipShow: false,
  66. comfirmShow: false,
  67. actionInfo: {}
  68. };
  69. },
  70. onLoad(options) {
  71. this.ticketId = options.id
  72. this.orderId = options.orderId
  73. },
  74. onShow() {
  75. this.getPrizeList()
  76. },
  77. methods: {
  78. getPrizeList() {
  79. uni.showLoading({
  80. title: '加载中'
  81. });
  82. let data = this.orderId ? {
  83. orderId: this.orderId
  84. } : {
  85. ticketId: this.ticketId
  86. }
  87. $http.post('/api/v1/mp/user/ticket/queryHitPrizeList', data).then(res => {
  88. uni.hideLoading();
  89. if (res.code == 0) {
  90. res.data.prizeList.forEach(item => {
  91. let picUrlArr = item.picUrl.split(',')
  92. item.picUrl = env.filePublic + picUrlArr[0]
  93. item.prizeType = JSON.parse(item.prizeType)
  94. })
  95. this.prizeList = res.data.prizeList
  96. this.ticketId = res.data.ticketId
  97. this.total = this.prizeList.length
  98. } else if (res.code == 1018) {
  99. this.tipShow = true
  100. } else {
  101. this.tipShow = true
  102. }
  103. }).catch(() => {
  104. uni.hideLoading();
  105. })
  106. },
  107. selectPrize(item, index) {
  108. if (item.remainQty == 0) {
  109. uni.$u.toast('该奖品已兑完!');
  110. return
  111. }
  112. this.actionIndex = index
  113. },
  114. confirmPrize() {
  115. let _this = this
  116. let item = _this.prizeList[_this.actionIndex]
  117. _this.actionInfo = item
  118. if (_this.prizeList.length > 1) {
  119. uni.showModal({
  120. title: '提示',
  121. content: '确定选择该奖品吗?',
  122. success(res) {
  123. if (res.confirm) {
  124. $http.post('/api/v1/mp/user/ticket/cashPrize', {
  125. ticketId: _this.ticketId,
  126. awardsId: item.awardsId,
  127. prizeId: item.prizeId
  128. }).then(res => {
  129. if (res.code == 0) {
  130. uni.$u.toast('兑换成功');
  131. _this.comfirmShow = true
  132. }
  133. })
  134. }
  135. }
  136. })
  137. } else {
  138. $http.post('/api/v1/mp/user/ticket/cashPrize', {
  139. ticketId: _this.ticketId,
  140. awardsId: item.awardsId,
  141. prizeId: item.prizeId
  142. }).then(res => {
  143. if (res.code == 0) {
  144. uni.$u.toast('兑换成功');
  145. _this.comfirmShow = true
  146. }
  147. })
  148. }
  149. },
  150. toIndex() {
  151. uni.switchTab({
  152. url: '/pages/index/index'
  153. })
  154. },
  155. back() {
  156. let pages = getCurrentPages();
  157. if (pages.length > 1) {
  158. uni.navigateBack({
  159. delta: 1
  160. })
  161. } else {
  162. uni.switchTab({
  163. url: '/pages/core/index'
  164. })
  165. }
  166. },
  167. toPrize() {
  168. uni.switchTab({
  169. url: '/pages/user/index'
  170. })
  171. }
  172. }
  173. }
  174. </script>
  175. <style lang="scss" scoped>
  176. .choice {
  177. width: 100%;
  178. min-height: calc(100vh - 50px);
  179. background-image: linear-gradient(to right, #ebbba7 0%, #cfc7f8 100%);
  180. padding-bottom: 150rpx;
  181. &-title {
  182. padding-top: 100rpx;
  183. font-size: 56rpx;
  184. font-weight: bold;
  185. text-align: center;
  186. line-height: 84rpx;
  187. margin-bottom: 12rpx;
  188. }
  189. &-all {
  190. text-align: center;
  191. line-height: 40rpx;
  192. }
  193. &-list {
  194. justify-content: space-around;
  195. flex-wrap: wrap;
  196. padding: 60rpx;
  197. margin-bottom: 60rpx;
  198. &-item {
  199. position: relative;
  200. width: 43%;
  201. height: 440rpx;
  202. margin-bottom: 40rpx;
  203. background-color: #FFFFFF;
  204. border-radius: 10rpx;
  205. .item-info {
  206. height: 100%;
  207. display: flex;
  208. flex-direction: column;
  209. align-items: center;
  210. border: 2px solid #FFFFFF;
  211. border-radius: 10rpx;
  212. }
  213. .confirm {
  214. background: none;
  215. box-shadow: none;
  216. }
  217. .action-icon{
  218. position: absolute;
  219. bottom: -15rpx;
  220. right: -15rpx;
  221. width: 82rpx;
  222. height: 82rpx;
  223. line-height: 82rpx;
  224. background-color: rgba(236, 122, 61, 100);
  225. text-align: center;
  226. box-shadow: 0px 4rpx 12rpx 0px rgba(0, 0, 0, 0.4);
  227. border-radius: 50%;
  228. }
  229. .action {
  230. box-shadow: 0px 2px 6px 0px rgba(0, 0, 0, 0.4);
  231. border: 2px solid rgba(236, 122, 61, 100);
  232. }
  233. .null {
  234. box-shadow: 0px 2px 6px 0px rgba(0, 0, 0, 0.4);
  235. border: 2px solid rgba(187, 187, 187, 54);
  236. }
  237. .info {
  238. width: 100%;
  239. height: 75%;
  240. background-color: #F8F8F8;
  241. border-top-left-radius: 10rpx;
  242. border-top-right-radius: 10rpx;
  243. }
  244. image {
  245. width: 100%;
  246. height: 80%;
  247. }
  248. .title {
  249. width: 100%;
  250. font-size: 24rpx;
  251. margin: 16rpx 0 0 10rpx;
  252. color: #333;
  253. }
  254. .tip {
  255. margin: 16rpx 0 0 10rpx;
  256. font-size: 24rpx;
  257. color: red;
  258. }
  259. }
  260. }
  261. .btn {
  262. .confirm {
  263. width: 400rpx;
  264. height: 80rpx;
  265. line-height: 80rpx;
  266. border-radius: 8px;
  267. background-color: rgba(235, 112, 9, 100);
  268. color: rgba(255, 255, 255, 100);
  269. font-size: 28rpx;
  270. text-align: center;
  271. }
  272. }
  273. }
  274. .null-prize {
  275. display: flex;
  276. flex-direction: column;
  277. align-items: center;
  278. justify-content: center;
  279. width: 80vw;
  280. height: 320rpx;
  281. background-color: #FFFFFF;
  282. border: 1px solid rgba(187, 187, 187, 100);
  283. .btn {
  284. margin-top: 60rpx;
  285. width: 160rpx;
  286. height: 60rpx;
  287. line-height: 60rpx;
  288. border-radius: 8rpx;
  289. background-color: rgba(235, 112, 9, 100);
  290. color: rgba(255, 255, 255, 100);
  291. font-size: 28rpx;
  292. text-align: center;
  293. }
  294. }
  295. .confirm-prize {
  296. display: flex;
  297. flex-direction: column;
  298. align-items: center;
  299. justify-content: center;
  300. width: 80vw;
  301. padding: 40rpx 0;
  302. &-info {
  303. width: 80%;
  304. margin-bottom: 60rpx;
  305. justify-content: space-around;
  306. image {
  307. width: 150rpx;
  308. height: 200rpx;
  309. }
  310. }
  311. &-tip {
  312. text-align: center;
  313. margin-bottom: 60rpx;
  314. }
  315. &-btn {
  316. width: 80%;
  317. justify-content: space-around;
  318. .back {
  319. width: 160rpx;
  320. height: 60rpx;
  321. line-height: 60rpx;
  322. border-radius: 8rpx;
  323. color: rgba(235, 112, 9, 100);
  324. font-size: 28rpx;
  325. text-align: center;
  326. font-family: Microsoft Yahei;
  327. border: 1px solid rgba(235, 112, 9, 100);
  328. }
  329. .confirm {
  330. width: 160rpx;
  331. height: 60rpx;
  332. line-height: 60rpx;
  333. border-radius: 8rpx;
  334. background-color: rgba(235, 112, 9, 100);
  335. color: rgba(253, 253, 253, 100);
  336. font-size: 28rpx;
  337. text-align: center;
  338. }
  339. }
  340. }
  341. </style>