index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  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. 已放入我的奖品库<text @click="toPrize(actionInfo.prizeType)">前往查看</text></view>
  51. <view class="confirm-prize-tip" v-else>已放入“我的盲豆”<text @click="toPrize('coin')">前往查看</text></view>
  52. <view class="flex confirm-prize-btn">
  53. <view class="back" @click="back">返回</view>
  54. <view class="confirm" @click="again">再来一张</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. type: ''
  74. };
  75. },
  76. onLoad(options) {
  77. this.ticketId = options.id
  78. this.type = options.type
  79. },
  80. onShow() {
  81. this.getPrizeList()
  82. },
  83. methods: {
  84. getPrizeList() {
  85. uni.showLoading({
  86. title: '加载中'
  87. });
  88. let data = {
  89. ticketId: this.ticketId
  90. }
  91. $http.post('/api/v1/mp/user/ticket/queryHitPrizeList', data).then(res => {
  92. uni.hideLoading();
  93. if (res.code == 0) {
  94. res.data.prizeList.forEach(item => {
  95. let picUrlArr = item.picUrl.split(',')
  96. item.picUrl = env.filePublic + picUrlArr[0]
  97. item.prizeType = JSON.parse(item.prizeType)
  98. })
  99. this.prizeList = res.data.prizeList
  100. this.ticketId = res.data.ticketId
  101. this.total = this.prizeList.length
  102. } else if (res.code == 1018) {
  103. this.tipShow = true
  104. } else {
  105. this.tipShow = true
  106. }
  107. }).catch(() => {
  108. uni.hideLoading();
  109. })
  110. },
  111. selectPrize(item, index) {
  112. if (item.remainQty == 0) {
  113. uni.$u.toast('该奖品已兑完!');
  114. return
  115. }
  116. this.actionIndex = index
  117. },
  118. confirmPrize() {
  119. let _this = this
  120. let item = _this.prizeList[_this.actionIndex]
  121. _this.actionInfo = item
  122. console.log(this.actionInfo)
  123. if (_this.prizeList.length > 1) {
  124. uni.showModal({
  125. title: '提示',
  126. content: '确定选择该奖品吗?',
  127. success(res) {
  128. if (res.confirm) {
  129. $http.post('/api/v1/mp/user/ticket/cashPrize', {
  130. ticketId: _this.ticketId,
  131. awardsId: item.awardsId,
  132. prizeId: item.prizeId
  133. }).then(res => {
  134. if (res.code == 0) {
  135. _this.comfirmShow = true
  136. }
  137. })
  138. }
  139. }
  140. })
  141. } else {
  142. $http.post('/api/v1/mp/user/ticket/cashPrize', {
  143. ticketId: _this.ticketId,
  144. awardsId: item.awardsId,
  145. prizeId: item.prizeId
  146. }).then(res => {
  147. if (res.code == 0) {
  148. _this.comfirmShow = true
  149. }
  150. })
  151. }
  152. },
  153. toIndex() {
  154. uni.switchTab({
  155. url: '/pages/index/index'
  156. })
  157. },
  158. back() {
  159. let pages = getCurrentPages();
  160. if (pages.length > 1) {
  161. uni.navigateBack({
  162. delta: 1
  163. })
  164. } else {
  165. uni.switchTab({
  166. url: '/pages/core/index'
  167. })
  168. }
  169. },
  170. toPrize(data) {
  171. console.log(data)
  172. if (data.value == 'goods') {
  173. uni.redirectTo({
  174. url: '/pages/prize/index'
  175. })
  176. console.log(data.value)
  177. }
  178. if (data.value == 'coupon') {
  179. uni.redirectTo({
  180. url: '/pages/prize/index?coupon=1'
  181. })
  182. console.log(data.value)
  183. }
  184. if (data == 'coin') {
  185. uni.redirectTo({
  186. url: '/pages/bean/index'
  187. })
  188. }
  189. },
  190. again() {
  191. let _this = this
  192. if (_this.type == 'onLine') {
  193. uni.navigateBack({
  194. delta: 1
  195. })
  196. } else if (_this.type == 'offLine') {
  197. uni.scanCode({
  198. scanType: ['qrCode'],
  199. success(res) {
  200. const url = res.result
  201. let serialNo = url.substring(url.length - 21, url.length)
  202. uni.redirectTo({
  203. url: `/pages/lucky/index?id=${ serialNo }&type=offLine`
  204. })
  205. },
  206. fail() {
  207. uni.$u.toast('请扫二维码');
  208. }
  209. });
  210. } else {
  211. _this.toIndex()
  212. }
  213. },
  214. }
  215. }
  216. </script>
  217. <style lang="scss" scoped>
  218. .choice {
  219. width: 100%;
  220. min-height: calc(100vh - 44px - var(--status-bar-height));
  221. background: url(https://mp-public-1310078123.cos.ap-shanghai.myqcloud.com/openprize_bg.png) center center;
  222. padding-bottom: 150rpx;
  223. &-title {
  224. padding-top: 100rpx;
  225. font-size: 56rpx;
  226. font-weight: bold;
  227. text-align: center;
  228. line-height: 84rpx;
  229. margin-bottom: 12rpx;
  230. }
  231. &-all {
  232. text-align: center;
  233. line-height: 40rpx;
  234. }
  235. &-list {
  236. justify-content: space-around;
  237. flex-wrap: wrap;
  238. padding: 60rpx;
  239. &-item {
  240. position: relative;
  241. width: 43%;
  242. height: 440rpx;
  243. margin-bottom: 40rpx;
  244. background-color: #FFFFFF;
  245. border-radius: 10rpx;
  246. .item-info {
  247. height: 100%;
  248. display: flex;
  249. flex-direction: column;
  250. align-items: center;
  251. border: 2px solid #FFFFFF;
  252. border-radius: 10rpx;
  253. }
  254. .confirm {
  255. background: none;
  256. box-shadow: none;
  257. }
  258. .action-icon {
  259. position: absolute;
  260. bottom: -15rpx;
  261. right: -15rpx;
  262. width: 82rpx;
  263. height: 82rpx;
  264. line-height: 82rpx;
  265. background-color: rgba(236, 122, 61, 100);
  266. text-align: center;
  267. box-shadow: 0px 4rpx 12rpx 0px rgba(0, 0, 0, 0.4);
  268. border-radius: 50%;
  269. }
  270. .action {
  271. box-shadow: 0px 2px 6px 0px rgba(0, 0, 0, 0.4);
  272. border: 2px solid rgba(236, 122, 61, 100);
  273. }
  274. .null {
  275. box-shadow: 0px 2px 6px 0px rgba(0, 0, 0, 0.4);
  276. border: 2px solid rgba(187, 187, 187, 54);
  277. }
  278. .info-image {
  279. width: 100%;
  280. min-height: 70%;
  281. background-color: #F8F8F8;
  282. border-top-left-radius: 10rpx;
  283. border-top-right-radius: 10rpx;
  284. }
  285. image {
  286. width: 100%;
  287. height: 80%;
  288. }
  289. .title {
  290. width: 100%;
  291. font-size: 24rpx;
  292. margin: 16rpx 0 0 10rpx;
  293. color: #333;
  294. }
  295. .tip {
  296. margin: 16rpx 0 0 10rpx;
  297. font-size: 24rpx;
  298. color: red;
  299. }
  300. }
  301. }
  302. .btn {
  303. margin-top: 200rpx;
  304. .confirm {
  305. width: 400rpx;
  306. height: 80rpx;
  307. font-size: 36rpx;
  308. line-height: 80rpx;
  309. border-radius: 20rpx;
  310. background-color: rgba(235, 112, 9, 100);
  311. color: rgba(255, 255, 255, 100);
  312. text-align: center;
  313. }
  314. }
  315. }
  316. .footer-fixed {
  317. position: fixed;
  318. bottom: var(--window-bottom);
  319. left: 0;
  320. right: 0;
  321. z-index: 11;
  322. box-shadow: 0 -4rpx 40rpx 0 rgba(151, 151, 151, 0.24);
  323. background: #fff;
  324. // 设置ios刘海屏底部横线安全区域
  325. padding-bottom: constant(safe-area-inset-bottom);
  326. padding-bottom: env(safe-area-inset-bottom);
  327. .btn {
  328. padding: 20rpx 0;
  329. /deep/ button {
  330. width: 640rpx;
  331. height: 90rpx;
  332. line-height: 90rpx;
  333. font-size: 36rpx;
  334. color: #fff;
  335. background-color: $uni-bg-color;
  336. border: none;
  337. border-radius: 20rpx;
  338. }
  339. }
  340. }
  341. .null-prize {
  342. display: flex;
  343. flex-direction: column;
  344. align-items: center;
  345. justify-content: center;
  346. width: 80vw;
  347. height: 320rpx;
  348. background-color: #FFFFFF;
  349. border: 1px solid rgba(187, 187, 187, 100);
  350. .btn {
  351. margin-top: 60rpx;
  352. width: 160rpx;
  353. height: 60rpx;
  354. line-height: 60rpx;
  355. border-radius: 8rpx;
  356. background-color: rgba(235, 112, 9, 100);
  357. color: rgba(255, 255, 255, 100);
  358. font-size: 28rpx;
  359. text-align: center;
  360. }
  361. }
  362. .confirm-prize {
  363. display: flex;
  364. flex-direction: column;
  365. align-items: center;
  366. justify-content: center;
  367. width: 80vw;
  368. padding: 40rpx 0;
  369. &-info {
  370. width: 80%;
  371. margin-bottom: 60rpx;
  372. justify-content: space-around;
  373. image {
  374. width: 150rpx;
  375. height: 200rpx;
  376. }
  377. .title {
  378. flex: 1;
  379. padding-left: 40rpx;
  380. }
  381. }
  382. &-tip {
  383. text-align: center;
  384. margin-bottom: 60rpx;
  385. text {
  386. padding-left: 24rpx;
  387. color: rgba(32, 163, 242, 100);
  388. }
  389. }
  390. &-btn {
  391. width: 80%;
  392. justify-content: space-around;
  393. .back {
  394. width: 160rpx;
  395. height: 60rpx;
  396. line-height: 60rpx;
  397. border-radius: 8rpx;
  398. color: rgba(235, 112, 9, 100);
  399. font-size: 28rpx;
  400. text-align: center;
  401. font-family: Microsoft Yahei;
  402. border: 1px solid rgba(235, 112, 9, 100);
  403. }
  404. .confirm {
  405. width: 160rpx;
  406. height: 60rpx;
  407. line-height: 60rpx;
  408. border-radius: 8rpx;
  409. background-color: rgba(235, 112, 9, 100);
  410. color: rgba(253, 253, 253, 100);
  411. font-size: 28rpx;
  412. text-align: center;
  413. }
  414. }
  415. }
  416. </style>