index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  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] + '?imageView2/2/w/340'
  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. if (data.value == 'goods') {
  172. uni.redirectTo({
  173. url: '/packagePrize/prize/index'
  174. })
  175. }
  176. if (data.value == 'coupon') {
  177. uni.redirectTo({
  178. url: '/packagePrize/prize/index?coupon=1'
  179. })
  180. }
  181. if (data.value == 'coupon_pkg') {
  182. uni.redirectTo({
  183. url: '/packagePrize/prize/index?coupon=1'
  184. })
  185. }
  186. if (data == 'coin') {
  187. uni.switchTab({
  188. url: '/pages/core/index'
  189. })
  190. }
  191. },
  192. again() {
  193. let _this = this
  194. if (_this.type == 'onLine') {
  195. uni.navigateBack({
  196. delta: 1
  197. })
  198. } else if (_this.type == 'offLine') {
  199. uni.scanCode({
  200. scanType: ['qrCode'],
  201. success(res) {
  202. const url = res.result
  203. let serialNo = url.substring(url.length - 21, url.length)
  204. uni.redirectTo({
  205. url: `/packageOperate/lucky/index?id=${ serialNo }&type=offLine`
  206. })
  207. },
  208. fail() {
  209. uni.$u.toast('请扫二维码');
  210. }
  211. });
  212. } else {
  213. _this.toIndex()
  214. }
  215. },
  216. }
  217. }
  218. </script>
  219. <style lang="scss" scoped>
  220. .choice {
  221. width: 100%;
  222. min-height: calc(100vh - 44px - var(--status-bar-height));
  223. background: url(https://mp-public-1310078123.cos.ap-shanghai.myqcloud.com/openprize_bg.png) center center;
  224. padding-bottom: 150rpx;
  225. &-title {
  226. padding-top: 100rpx;
  227. font-size: 56rpx;
  228. font-weight: bold;
  229. text-align: center;
  230. line-height: 84rpx;
  231. margin-bottom: 12rpx;
  232. }
  233. &-all {
  234. text-align: center;
  235. line-height: 40rpx;
  236. }
  237. &-list {
  238. justify-content: space-around;
  239. flex-wrap: wrap;
  240. padding: 60rpx;
  241. &-item {
  242. position: relative;
  243. width: 43%;
  244. height: 440rpx;
  245. margin-bottom: 40rpx;
  246. background-color: #FFFFFF;
  247. border-radius: 10rpx;
  248. .item-info {
  249. height: 100%;
  250. display: flex;
  251. flex-direction: column;
  252. align-items: center;
  253. border: 2px solid #FFFFFF;
  254. border-radius: 10rpx;
  255. }
  256. .confirm {
  257. background: none;
  258. box-shadow: none;
  259. }
  260. .action-icon {
  261. position: absolute;
  262. bottom: -15rpx;
  263. right: -15rpx;
  264. width: 82rpx;
  265. height: 82rpx;
  266. line-height: 82rpx;
  267. background-color: rgba(236, 122, 61, 100);
  268. text-align: center;
  269. box-shadow: 0px 4rpx 12rpx 0px rgba(0, 0, 0, 0.4);
  270. border-radius: 50%;
  271. }
  272. .action {
  273. box-shadow: 0px 2px 6px 0px rgba(0, 0, 0, 0.4);
  274. border: 2px solid rgba(236, 122, 61, 100);
  275. }
  276. .null {
  277. box-shadow: 0px 2px 6px 0px rgba(0, 0, 0, 0.4);
  278. border: 2px solid rgba(187, 187, 187, 54);
  279. }
  280. .info-image {
  281. width: 100%;
  282. min-height: 70%;
  283. background-color: #F8F8F8;
  284. border-top-left-radius: 10rpx;
  285. border-top-right-radius: 10rpx;
  286. }
  287. image {
  288. width: 100%;
  289. height: 80%;
  290. }
  291. .title {
  292. width: 100%;
  293. font-size: 24rpx;
  294. margin: 16rpx 0 0 10rpx;
  295. color: #333;
  296. overflow: hidden;
  297. text-overflow: ellipsis;
  298. display: -webkit-box;
  299. -webkit-box-orient: vertical;
  300. -webkit-line-clamp: 3;
  301. }
  302. .tip {
  303. margin: 16rpx 0 0 10rpx;
  304. font-size: 24rpx;
  305. color: red;
  306. }
  307. }
  308. }
  309. .btn {
  310. margin-top: 200rpx;
  311. .confirm {
  312. width: 400rpx;
  313. height: 80rpx;
  314. font-size: 36rpx;
  315. line-height: 80rpx;
  316. border-radius: 20rpx;
  317. background-color: rgba(235, 112, 9, 100);
  318. color: rgba(255, 255, 255, 100);
  319. text-align: center;
  320. }
  321. }
  322. }
  323. .footer-fixed {
  324. position: fixed;
  325. bottom: var(--window-bottom);
  326. left: 0;
  327. right: 0;
  328. z-index: 11;
  329. box-shadow: 0 -4rpx 40rpx 0 rgba(151, 151, 151, 0.24);
  330. background: #fff;
  331. // 设置ios刘海屏底部横线安全区域
  332. padding-bottom: constant(safe-area-inset-bottom);
  333. padding-bottom: env(safe-area-inset-bottom);
  334. .btn {
  335. padding: 20rpx 0;
  336. /deep/ button {
  337. width: 640rpx;
  338. height: 90rpx;
  339. line-height: 90rpx;
  340. font-size: 36rpx;
  341. color: #fff;
  342. background-color: $uni-bg-color;
  343. border: none;
  344. border-radius: 20rpx;
  345. }
  346. }
  347. }
  348. .null-prize {
  349. display: flex;
  350. flex-direction: column;
  351. align-items: center;
  352. justify-content: center;
  353. width: 80vw;
  354. height: 320rpx;
  355. background-color: #FFFFFF;
  356. border: 1px solid rgba(187, 187, 187, 100);
  357. .btn {
  358. margin-top: 60rpx;
  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(255, 255, 255, 100);
  365. font-size: 28rpx;
  366. text-align: center;
  367. }
  368. }
  369. .confirm-prize {
  370. display: flex;
  371. flex-direction: column;
  372. align-items: center;
  373. justify-content: center;
  374. width: 80vw;
  375. padding: 40rpx 0;
  376. &-info {
  377. width: 80%;
  378. margin-bottom: 60rpx;
  379. justify-content: space-around;
  380. image {
  381. width: 150rpx;
  382. height: 200rpx;
  383. }
  384. .title {
  385. flex: 1;
  386. padding-left: 40rpx;
  387. }
  388. }
  389. &-tip {
  390. text-align: center;
  391. margin-bottom: 60rpx;
  392. text {
  393. padding-left: 24rpx;
  394. color: rgba(32, 163, 242, 100);
  395. }
  396. }
  397. &-btn {
  398. width: 80%;
  399. justify-content: space-around;
  400. .back {
  401. width: 160rpx;
  402. height: 60rpx;
  403. line-height: 60rpx;
  404. border-radius: 8rpx;
  405. color: rgba(235, 112, 9, 100);
  406. font-size: 28rpx;
  407. text-align: center;
  408. font-family: Microsoft Yahei;
  409. border: 1px solid rgba(235, 112, 9, 100);
  410. }
  411. .confirm {
  412. width: 160rpx;
  413. height: 60rpx;
  414. line-height: 60rpx;
  415. border-radius: 8rpx;
  416. background-color: rgba(235, 112, 9, 100);
  417. color: rgba(253, 253, 253, 100);
  418. font-size: 28rpx;
  419. text-align: center;
  420. }
  421. }
  422. }
  423. </style>