index.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  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. <navigator open-type="exit" target="miniProgram" hover-class="none" class="btn">确认</navigator>
  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. this.ticketId = res.data.ticketId
  99. this.total = this.prizeList.length
  100. } else if (res.code == 1018) {
  101. this.tipShow = true
  102. } else {
  103. this.tipShow = true
  104. }
  105. }).catch(() => {
  106. uni.hideLoading();
  107. })
  108. },
  109. selectPrize(item, index) {
  110. if (item.remainQty == 0) {
  111. uni.$u.toast('该奖品已兑完!');
  112. return
  113. }
  114. this.actionIndex = index
  115. },
  116. confirmPrize() {
  117. let _this = this
  118. let item = _this.prizeList[_this.actionIndex]
  119. _this.actionInfo = item
  120. if (_this.prizeList.length > 1) {
  121. uni.showModal({
  122. title: '提示',
  123. content: '确定选择该奖品吗?',
  124. success(res) {
  125. if (res.confirm) {
  126. $http.post('/api/v1/mp/user/ticket/cashPrize', {
  127. ticketId: _this.ticketId,
  128. awardsId: item.awardsId,
  129. prizeId: item.prizeId
  130. }).then(res => {
  131. if (res.code == 0) {
  132. _this.comfirmShow = true
  133. }
  134. })
  135. }
  136. }
  137. })
  138. } else {
  139. $http.post('/api/v1/mp/user/ticket/cashPrize', {
  140. ticketId: _this.ticketId,
  141. awardsId: item.awardsId,
  142. prizeId: item.prizeId
  143. }).then(res => {
  144. if (res.code == 0) {
  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 - 44px - var(--status-bar-height));
  179. background: url(https://mp-public-1310078123.cos.ap-shanghai.myqcloud.com/background.png) center center;
  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. &-item {
  198. position: relative;
  199. width: 43%;
  200. height: 440rpx;
  201. margin-bottom: 40rpx;
  202. background-color: #FFFFFF;
  203. border-radius: 10rpx;
  204. .item-info {
  205. height: 100%;
  206. display: flex;
  207. flex-direction: column;
  208. align-items: center;
  209. border: 2px solid #FFFFFF;
  210. border-radius: 10rpx;
  211. }
  212. .confirm {
  213. background: none;
  214. box-shadow: none;
  215. }
  216. .action-icon {
  217. position: absolute;
  218. bottom: -15rpx;
  219. right: -15rpx;
  220. width: 82rpx;
  221. height: 82rpx;
  222. line-height: 82rpx;
  223. background-color: rgba(236, 122, 61, 100);
  224. text-align: center;
  225. box-shadow: 0px 4rpx 12rpx 0px rgba(0, 0, 0, 0.4);
  226. border-radius: 50%;
  227. }
  228. .action {
  229. box-shadow: 0px 2px 6px 0px rgba(0, 0, 0, 0.4);
  230. border: 2px solid rgba(236, 122, 61, 100);
  231. }
  232. .null {
  233. box-shadow: 0px 2px 6px 0px rgba(0, 0, 0, 0.4);
  234. border: 2px solid rgba(187, 187, 187, 54);
  235. }
  236. .info-image {
  237. width: 100%;
  238. min-height: 75%;
  239. background-color: #F8F8F8;
  240. border-top-left-radius: 10rpx;
  241. border-top-right-radius: 10rpx;
  242. }
  243. image {
  244. width: 100%;
  245. height: 80%;
  246. }
  247. .title {
  248. width: 100%;
  249. font-size: 24rpx;
  250. margin: 16rpx 0 0 10rpx;
  251. color: #333;
  252. }
  253. .tip {
  254. margin: 16rpx 0 0 10rpx;
  255. font-size: 24rpx;
  256. color: red;
  257. }
  258. }
  259. }
  260. .btn {
  261. margin-top: 200rpx;
  262. .confirm {
  263. width: 400rpx;
  264. height: 80rpx;
  265. font-size: 36rpx;
  266. line-height: 80rpx;
  267. border-radius: 20rpx;
  268. background-color: rgba(235, 112, 9, 100);
  269. color: rgba(255, 255, 255, 100);
  270. text-align: center;
  271. }
  272. }
  273. }
  274. .footer-fixed {
  275. position: fixed;
  276. bottom: var(--window-bottom);
  277. left: 0;
  278. right: 0;
  279. z-index: 11;
  280. box-shadow: 0 -4rpx 40rpx 0 rgba(151, 151, 151, 0.24);
  281. background: #fff;
  282. // 设置ios刘海屏底部横线安全区域
  283. padding-bottom: constant(safe-area-inset-bottom);
  284. padding-bottom: env(safe-area-inset-bottom);
  285. .btn {
  286. padding: 20rpx 0;
  287. /deep/ button {
  288. width: 640rpx;
  289. height: 90rpx;
  290. line-height: 90rpx;
  291. font-size: 36rpx;
  292. color: #fff;
  293. background-color: $uni-bg-color;
  294. border: none;
  295. border-radius: 20rpx;
  296. }
  297. }
  298. }
  299. .null-prize {
  300. display: flex;
  301. flex-direction: column;
  302. align-items: center;
  303. justify-content: center;
  304. width: 80vw;
  305. height: 320rpx;
  306. background-color: #FFFFFF;
  307. border: 1px solid rgba(187, 187, 187, 100);
  308. .btn {
  309. margin-top: 60rpx;
  310. width: 160rpx;
  311. height: 60rpx;
  312. line-height: 60rpx;
  313. border-radius: 8rpx;
  314. background-color: rgba(235, 112, 9, 100);
  315. color: rgba(255, 255, 255, 100);
  316. font-size: 28rpx;
  317. text-align: center;
  318. }
  319. }
  320. .confirm-prize {
  321. display: flex;
  322. flex-direction: column;
  323. align-items: center;
  324. justify-content: center;
  325. width: 80vw;
  326. padding: 40rpx 0;
  327. &-info {
  328. width: 80%;
  329. margin-bottom: 60rpx;
  330. justify-content: space-around;
  331. image {
  332. width: 150rpx;
  333. height: 200rpx;
  334. }
  335. .title{
  336. flex: 1;
  337. padding-left: 40rpx;
  338. }
  339. }
  340. &-tip {
  341. text-align: center;
  342. margin-bottom: 60rpx;
  343. }
  344. &-btn {
  345. width: 80%;
  346. justify-content: space-around;
  347. .back {
  348. width: 160rpx;
  349. height: 60rpx;
  350. line-height: 60rpx;
  351. border-radius: 8rpx;
  352. color: rgba(235, 112, 9, 100);
  353. font-size: 28rpx;
  354. text-align: center;
  355. font-family: Microsoft Yahei;
  356. border: 1px solid rgba(235, 112, 9, 100);
  357. }
  358. .confirm {
  359. width: 160rpx;
  360. height: 60rpx;
  361. line-height: 60rpx;
  362. border-radius: 8rpx;
  363. background-color: rgba(235, 112, 9, 100);
  364. color: rgba(253, 253, 253, 100);
  365. font-size: 28rpx;
  366. text-align: center;
  367. }
  368. }
  369. }
  370. </style>