index.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  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, 'item-info confirm': actionIndex != index, '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">
  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. <view class="footer-fixed" v-if="!tipShow">
  30. <view class="flex btn">
  31. <button type="default" @click="confirmPrize">确认</button>
  32. </view>
  33. </view>
  34. <u-popup :show="tipShow" :round="10" mode="center" :safeAreaInsetBottom="false">
  35. <view class="null-prize">
  36. <view class="title">该盲票已被他人买走了</view>
  37. <view class="btn" @click="toIndex">确认</view>
  38. </view>
  39. </u-popup>
  40. <u-popup :show="comfirmShow" :round="10" mode="center" :safeAreaInsetBottom="false">
  41. <view class="confirm-prize">
  42. <view class="flex confirm-prize-info">
  43. <image :src="actionInfo.picUrl" mode="aspectFill"></image>
  44. <view class="title" v-if="actionInfo.prizeType && actionInfo.prizeType.value != 'coin'">
  45. {{ actionInfo.title }}
  46. </view>
  47. <view class="title" v-else>盲豆x {{ actionInfo.value }}</view>
  48. </view>
  49. <view class="confirm-prize-tip" v-if="actionInfo.prizeType && actionInfo.prizeType.value != 'coin'">
  50. 已放入我的奖品库</view>
  51. <view class="confirm-prize-tip" v-else>已放入“我的盲豆”</view>
  52. <view class="flex confirm-prize-btn">
  53. <view class="back" @click="back">返回</view>
  54. <view class="confirm" @click="toPrize">前往查看</view>
  55. </view>
  56. </view>
  57. </u-popup>
  58. </view>
  59. </template>
  60. <script>
  61. import env from '../../config/env.js'
  62. import $http from '@/utils/request.js'
  63. export default {
  64. data() {
  65. return {
  66. ticketId: '',
  67. prizeList: [],
  68. total: 0,
  69. actionIndex: 0,
  70. tipShow: false,
  71. comfirmShow: false,
  72. actionInfo: {}
  73. };
  74. },
  75. onLoad(options) {
  76. this.ticketId = options.id
  77. },
  78. onShow() {
  79. this.getPrizeList()
  80. },
  81. methods: {
  82. getPrizeList() {
  83. uni.showLoading({
  84. title: '加载中'
  85. });
  86. let data = {
  87. ticketId: this.ticketId
  88. }
  89. $http.post('/api/v1/mp/user/ticket/queryHitPrizeList', data).then(res => {
  90. uni.hideLoading();
  91. if (res.code == 0) {
  92. res.data.prizeList.forEach(item => {
  93. let picUrlArr = item.picUrl.split(',')
  94. item.picUrl = env.filePublic + picUrlArr[0]
  95. item.prizeType = JSON.parse(item.prizeType)
  96. })
  97. this.prizeList = res.data.prizeList
  98. console.log(this.prizeList);
  99. this.ticketId = res.data.ticketId
  100. this.total = this.prizeList.length
  101. } else if (res.code == 1018) {
  102. this.tipShow = true
  103. } else {
  104. this.tipShow = true
  105. }
  106. }).catch(() => {
  107. uni.hideLoading();
  108. })
  109. },
  110. selectPrize(item, index) {
  111. if (item.remainQty == 0) {
  112. uni.$u.toast('该奖品已兑完!');
  113. return
  114. }
  115. this.actionIndex = index
  116. },
  117. confirmPrize() {
  118. let _this = this
  119. let item = _this.prizeList[_this.actionIndex]
  120. _this.actionInfo = item
  121. if (_this.prizeList.length > 1) {
  122. uni.showModal({
  123. title: '提示',
  124. content: '确定选择该奖品吗?',
  125. success(res) {
  126. if (res.confirm) {
  127. $http.post('/api/v1/mp/user/ticket/cashPrize', {
  128. ticketId: _this.ticketId,
  129. awardsId: item.awardsId,
  130. prizeId: item.prizeId
  131. }).then(res => {
  132. if (res.code == 0) {
  133. _this.comfirmShow = true
  134. }
  135. })
  136. }
  137. }
  138. })
  139. } else {
  140. $http.post('/api/v1/mp/user/ticket/cashPrize', {
  141. ticketId: _this.ticketId,
  142. awardsId: item.awardsId,
  143. prizeId: item.prizeId
  144. }).then(res => {
  145. if (res.code == 0) {
  146. _this.comfirmShow = true
  147. }
  148. })
  149. }
  150. },
  151. toIndex() {
  152. uni.switchTab({
  153. url: '/pages/index/index'
  154. })
  155. },
  156. back() {
  157. let pages = getCurrentPages();
  158. if (pages.length > 1) {
  159. uni.navigateBack({
  160. delta: 1
  161. })
  162. } else {
  163. uni.switchTab({
  164. url: '/pages/core/index'
  165. })
  166. }
  167. },
  168. toPrize() {
  169. uni.switchTab({
  170. url: '/pages/user/index'
  171. })
  172. }
  173. }
  174. }
  175. </script>
  176. <style lang="scss" scoped>
  177. .choice {
  178. width: 100%;
  179. min-height: calc(100vh - 44px - var(--status-bar-height));
  180. background: url(https://mp-public-1310078123.cos.ap-shanghai.myqcloud.com/background.png) center center;
  181. padding-bottom: 150rpx;
  182. &-title {
  183. padding-top: 100rpx;
  184. font-size: 56rpx;
  185. font-weight: bold;
  186. text-align: center;
  187. line-height: 84rpx;
  188. margin-bottom: 12rpx;
  189. }
  190. &-all {
  191. text-align: center;
  192. line-height: 40rpx;
  193. }
  194. &-list {
  195. justify-content: space-around;
  196. flex-wrap: wrap;
  197. padding: 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-image {
  238. width: 100%;
  239. min-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. margin-top: 200rpx;
  263. .confirm {
  264. width: 400rpx;
  265. height: 80rpx;
  266. font-size: 36rpx;
  267. line-height: 80rpx;
  268. border-radius: 20rpx;
  269. background-color: rgba(235, 112, 9, 100);
  270. color: rgba(255, 255, 255, 100);
  271. text-align: center;
  272. }
  273. }
  274. }
  275. .footer-fixed {
  276. position: fixed;
  277. bottom: var(--window-bottom);
  278. left: 0;
  279. right: 0;
  280. z-index: 11;
  281. box-shadow: 0 -4rpx 40rpx 0 rgba(151, 151, 151, 0.24);
  282. background: #fff;
  283. // 设置ios刘海屏底部横线安全区域
  284. padding-bottom: constant(safe-area-inset-bottom);
  285. padding-bottom: env(safe-area-inset-bottom);
  286. .btn {
  287. padding: 20rpx 0;
  288. /deep/ button {
  289. width: 640rpx;
  290. height: 90rpx;
  291. line-height: 90rpx;
  292. font-size: 36rpx;
  293. color: #fff;
  294. background-color: $uni-bg-color;
  295. border: none;
  296. border-radius: 20rpx;
  297. }
  298. }
  299. }
  300. .null-prize {
  301. display: flex;
  302. flex-direction: column;
  303. align-items: center;
  304. justify-content: center;
  305. width: 80vw;
  306. height: 320rpx;
  307. background-color: #FFFFFF;
  308. border: 1px solid rgba(187, 187, 187, 100);
  309. .btn {
  310. margin-top: 60rpx;
  311. width: 160rpx;
  312. height: 60rpx;
  313. line-height: 60rpx;
  314. border-radius: 8rpx;
  315. background-color: rgba(235, 112, 9, 100);
  316. color: rgba(255, 255, 255, 100);
  317. font-size: 28rpx;
  318. text-align: center;
  319. }
  320. }
  321. .confirm-prize {
  322. display: flex;
  323. flex-direction: column;
  324. align-items: center;
  325. justify-content: center;
  326. width: 80vw;
  327. padding: 40rpx 0;
  328. &-info {
  329. width: 80%;
  330. margin-bottom: 60rpx;
  331. justify-content: space-around;
  332. image {
  333. width: 150rpx;
  334. height: 200rpx;
  335. }
  336. .title{
  337. flex: 1;
  338. padding-left: 40rpx;
  339. }
  340. }
  341. &-tip {
  342. text-align: center;
  343. margin-bottom: 60rpx;
  344. }
  345. &-btn {
  346. width: 80%;
  347. justify-content: space-around;
  348. .back {
  349. width: 160rpx;
  350. height: 60rpx;
  351. line-height: 60rpx;
  352. border-radius: 8rpx;
  353. color: rgba(235, 112, 9, 100);
  354. font-size: 28rpx;
  355. text-align: center;
  356. font-family: Microsoft Yahei;
  357. border: 1px solid rgba(235, 112, 9, 100);
  358. }
  359. .confirm {
  360. width: 160rpx;
  361. height: 60rpx;
  362. line-height: 60rpx;
  363. border-radius: 8rpx;
  364. background-color: rgba(235, 112, 9, 100);
  365. color: rgba(253, 253, 253, 100);
  366. font-size: 28rpx;
  367. text-align: center;
  368. }
  369. }
  370. }
  371. </style>