index.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  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 || total == 1, 'item-info null': item.remainQty == 0}">
  12. <view class="flex info-image">
  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. },
  73. onShow() {
  74. this.getPrizeList()
  75. },
  76. methods: {
  77. getPrizeList() {
  78. uni.showLoading({
  79. title: '加载中'
  80. });
  81. let data = {
  82. ticketId: this.ticketId
  83. }
  84. $http.post('/api/v1/mp/user/ticket/queryHitPrizeList', data).then(res => {
  85. uni.hideLoading();
  86. if (res.code == 0) {
  87. res.data.prizeList.forEach(item => {
  88. let picUrlArr = item.picUrl.split(',')
  89. item.picUrl = env.filePublic + picUrlArr[0]
  90. item.prizeType = JSON.parse(item.prizeType)
  91. })
  92. this.prizeList = res.data.prizeList
  93. console.log(this.prizeList);
  94. this.ticketId = res.data.ticketId
  95. this.total = this.prizeList.length
  96. } else if (res.code == 1018) {
  97. this.tipShow = true
  98. } else {
  99. this.tipShow = true
  100. }
  101. }).catch(() => {
  102. uni.hideLoading();
  103. })
  104. },
  105. selectPrize(item, index) {
  106. if (item.remainQty == 0) {
  107. uni.$u.toast('该奖品已兑完!');
  108. return
  109. }
  110. this.actionIndex = index
  111. },
  112. confirmPrize() {
  113. let _this = this
  114. let item = _this.prizeList[_this.actionIndex]
  115. _this.actionInfo = item
  116. if (_this.prizeList.length > 1) {
  117. uni.showModal({
  118. title: '提示',
  119. content: '确定选择该奖品吗?',
  120. success(res) {
  121. if (res.confirm) {
  122. $http.post('/api/v1/mp/user/ticket/cashPrize', {
  123. ticketId: _this.ticketId,
  124. awardsId: item.awardsId,
  125. prizeId: item.prizeId
  126. }).then(res => {
  127. if (res.code == 0) {
  128. _this.comfirmShow = true
  129. }
  130. })
  131. }
  132. }
  133. })
  134. } else {
  135. $http.post('/api/v1/mp/user/ticket/cashPrize', {
  136. ticketId: _this.ticketId,
  137. awardsId: item.awardsId,
  138. prizeId: item.prizeId
  139. }).then(res => {
  140. if (res.code == 0) {
  141. _this.comfirmShow = true
  142. }
  143. })
  144. }
  145. },
  146. toIndex() {
  147. uni.switchTab({
  148. url: '/pages/index/index'
  149. })
  150. },
  151. back() {
  152. let pages = getCurrentPages();
  153. if (pages.length > 1) {
  154. uni.navigateBack({
  155. delta: 1
  156. })
  157. } else {
  158. uni.switchTab({
  159. url: '/pages/core/index'
  160. })
  161. }
  162. },
  163. toPrize() {
  164. uni.switchTab({
  165. url: '/pages/user/index'
  166. })
  167. }
  168. }
  169. }
  170. </script>
  171. <style lang="scss" scoped>
  172. .choice {
  173. width: 100%;
  174. min-height: calc(100vh - 44px - var(--status-bar-height));
  175. background: url(https://mp-public-1310078123.cos.ap-shanghai.myqcloud.com/background.png) center center;
  176. &-title {
  177. padding-top: 100rpx;
  178. font-size: 56rpx;
  179. font-weight: bold;
  180. text-align: center;
  181. line-height: 84rpx;
  182. margin-bottom: 12rpx;
  183. }
  184. &-all {
  185. text-align: center;
  186. line-height: 40rpx;
  187. }
  188. &-list {
  189. justify-content: space-around;
  190. flex-wrap: wrap;
  191. padding: 60rpx;
  192. &-item {
  193. position: relative;
  194. width: 43%;
  195. height: 440rpx;
  196. margin-bottom: 40rpx;
  197. background-color: #FFFFFF;
  198. border-radius: 10rpx;
  199. .item-info {
  200. height: 100%;
  201. display: flex;
  202. flex-direction: column;
  203. align-items: center;
  204. border: 2px solid #FFFFFF;
  205. border-radius: 10rpx;
  206. }
  207. .confirm {
  208. background: none;
  209. box-shadow: none;
  210. }
  211. .action-icon {
  212. position: absolute;
  213. bottom: -15rpx;
  214. right: -15rpx;
  215. width: 82rpx;
  216. height: 82rpx;
  217. line-height: 82rpx;
  218. background-color: rgba(236, 122, 61, 100);
  219. text-align: center;
  220. box-shadow: 0px 4rpx 12rpx 0px rgba(0, 0, 0, 0.4);
  221. border-radius: 50%;
  222. }
  223. .action {
  224. box-shadow: 0px 2px 6px 0px rgba(0, 0, 0, 0.4);
  225. border: 2px solid rgba(236, 122, 61, 100);
  226. }
  227. .null {
  228. box-shadow: 0px 2px 6px 0px rgba(0, 0, 0, 0.4);
  229. border: 2px solid rgba(187, 187, 187, 54);
  230. }
  231. .info-image {
  232. width: 100%;
  233. min-height: 75%;
  234. background-color: #F8F8F8;
  235. border-top-left-radius: 10rpx;
  236. border-top-right-radius: 10rpx;
  237. }
  238. image {
  239. width: 100%;
  240. height: 80%;
  241. }
  242. .title {
  243. width: 100%;
  244. font-size: 24rpx;
  245. margin: 16rpx 0 0 10rpx;
  246. color: #333;
  247. }
  248. .tip {
  249. margin: 16rpx 0 0 10rpx;
  250. font-size: 24rpx;
  251. color: red;
  252. }
  253. }
  254. }
  255. .btn {
  256. margin-top: 200rpx;
  257. .confirm {
  258. width: 400rpx;
  259. height: 80rpx;
  260. font-size: 36rpx;
  261. line-height: 80rpx;
  262. border-radius: 20rpx;
  263. background-color: rgba(235, 112, 9, 100);
  264. color: rgba(255, 255, 255, 100);
  265. text-align: center;
  266. }
  267. }
  268. }
  269. .null-prize {
  270. display: flex;
  271. flex-direction: column;
  272. align-items: center;
  273. justify-content: center;
  274. width: 80vw;
  275. height: 320rpx;
  276. background-color: #FFFFFF;
  277. border: 1px solid rgba(187, 187, 187, 100);
  278. .btn {
  279. margin-top: 60rpx;
  280. width: 160rpx;
  281. height: 60rpx;
  282. line-height: 60rpx;
  283. border-radius: 8rpx;
  284. background-color: rgba(235, 112, 9, 100);
  285. color: rgba(255, 255, 255, 100);
  286. font-size: 28rpx;
  287. text-align: center;
  288. }
  289. }
  290. .confirm-prize {
  291. display: flex;
  292. flex-direction: column;
  293. align-items: center;
  294. justify-content: center;
  295. width: 80vw;
  296. padding: 40rpx 0;
  297. &-info {
  298. width: 80%;
  299. margin-bottom: 60rpx;
  300. justify-content: space-around;
  301. image {
  302. width: 150rpx;
  303. height: 200rpx;
  304. }
  305. }
  306. &-tip {
  307. text-align: center;
  308. margin-bottom: 60rpx;
  309. }
  310. &-btn {
  311. width: 80%;
  312. justify-content: space-around;
  313. .back {
  314. width: 160rpx;
  315. height: 60rpx;
  316. line-height: 60rpx;
  317. border-radius: 8rpx;
  318. color: rgba(235, 112, 9, 100);
  319. font-size: 28rpx;
  320. text-align: center;
  321. font-family: Microsoft Yahei;
  322. border: 1px solid rgba(235, 112, 9, 100);
  323. }
  324. .confirm {
  325. width: 160rpx;
  326. height: 60rpx;
  327. line-height: 60rpx;
  328. border-radius: 8rpx;
  329. background-color: rgba(235, 112, 9, 100);
  330. color: rgba(253, 253, 253, 100);
  331. font-size: 28rpx;
  332. text-align: center;
  333. }
  334. }
  335. }
  336. </style>