index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  1. <template>
  2. <view>
  3. <!-- 非H5撑高元素 -->
  4. <!-- <view class="status_bar"></view> -->
  5. <view class="box">
  6. <view class="box-top">
  7. <view class="box-top-action">
  8. <view class="box-top-action-item" @click="toPrize">
  9. <view class="flex box-top-action-item-cir">
  10. <image src="../../static/icon/index_prize.png" mode=""></image>
  11. </view>
  12. <view class="box-top-action-item-txt">奖品库</view>
  13. </view>
  14. </view>
  15. <view class="box-top-tip">
  16. <view class="flex box-top-tip-txt" @click="toRule">
  17. <text>规则说明</text>
  18. </view>
  19. <view class="flex box-top-tip-txt" @click="toTicket">
  20. <text>所有盲票</text>
  21. </view>
  22. </view>
  23. <!-- 弹幕 -->
  24. <view class="box-top-news">
  25. <prize-news :list="prizeNewsListOne" duration="20" v-if="prizeNewsListOne.length" />
  26. <prize-news :list="prizeNewsListTwo" duration="15" v-if="prizeNewsListTwo.length" />
  27. </view>
  28. </view>
  29. <view class="box-ticket">
  30. <!-- 盲票 -->
  31. <swiper class="image-container" circular :vertical="true" :current="currentIndex" :autoplay="false"
  32. @change="changeTicket" v-if="ticketList.length">
  33. <swiper-item class="swiper-item" v-for="(item, index) in ticketList" :key="item.picUrl"
  34. @click="toTicketBox">
  35. <view class="flex image-wrap">
  36. <image class="img" :src="item.picUrl" lazy-load mode=""></image>
  37. </view>
  38. </swiper-item>
  39. </swiper>
  40. <swiper class="image-container" circular :vertical="true" :autoplay="false" v-else>
  41. <swiper-item class="swiper-item">
  42. <view class="flex image-wrap">
  43. <image class="img" src="../../static/icon/ticket_index.png" lazy-load mode=""></image>
  44. </view>
  45. </swiper-item>
  46. </swiper>
  47. <!-- 奖品 -->
  48. <view class="prize-goods">
  49. <view class="prize-goods-item" :style="{ animation: activeAnimation }">
  50. <view class="flex image-wrap" v-for="(item, index) in prizeList" :key="index" @click="toPrizeGoods(item)">
  51. <image class="img" :src="item.picUrl" lazy-load mode="aspectFill"></image>
  52. </view>
  53. </view>
  54. <view class="prize-goods-item" :style="{ animation: activeAnimation }">
  55. <view class="flex image-wrap" v-for="(item, index) in prizeList" :key="index" @click="toPrizeGoods(item)">
  56. <image class="img" :src="item.picUrl" lazy-load mode="aspectFill"></image>
  57. </view>
  58. </view>
  59. </view>
  60. <!-- 盲票背景 -->
  61. <image class="box-img" src="../../static/icon/index_box.png" mode="" @click="toTicketBox"></image>
  62. <!-- 向左箭头 -->
  63. <image class="index-left" src="../../static/icon/index_left.png" mode="" @click="ticketLeft"></image>
  64. <!-- 向右箭头 -->
  65. <image class="index-right" src="../../static/icon/index_right.png" mode="" @click="ticketRight"></image>
  66. </view>
  67. <!-- 立即开刮 -->
  68. <view class="flex box-ticket-btn">
  69. <view class="box-ticket-btn-content" @click="payment">
  70. <image src="../../static/icon/index_btn.png" mode=""></image>
  71. <view class="flex title">
  72. <text>{{ payInfo.salePrice / 100 }}元立即开刮</text>
  73. </view>
  74. </view>
  75. </view>
  76. </view>
  77. <!-- tabbar组件 -->
  78. <custom-tab-bar :activeValue="'index'" />
  79. <!-- 支付弹框组件 -->
  80. <pay-popup :pay-show="payShow" :pay-info="payInfo" @close="close" @success="toProcess" v-if="payShow" />
  81. </view>
  82. </template>
  83. <script>
  84. import env from '../../config/env.js'
  85. import $http from '@/utils/request.js'
  86. import CustomTabBar from '../../components/custom-tab-bar/custom-tab-bar.vue'
  87. import Carousel from '../../components/vear-carousel/vear-carousel'
  88. import PayPopup from '../../components/pay-popup/pay-popup.vue'
  89. import PrizeNews from '../../components/prize-news/prize-news.vue'
  90. export default {
  91. components: {
  92. CustomTabBar,
  93. Carousel,
  94. PayPopup,
  95. PrizeNews,
  96. },
  97. data() {
  98. return {
  99. loginState: false, // 登录状态
  100. ticketList: [], // 盲票列表
  101. prizeList: [], // 奖品列表
  102. prizeNewsListOne: [], // 弹幕列表
  103. prizeNewsListTwo: [], // 弹幕列表
  104. payShow: false, // 支付弹框显示
  105. payInfo: {}, // 支付详情
  106. currentIndex: 0, // 盲票选中下标
  107. activeAnimation: 'moveLeft 10s linear infinite normal', // 奖品动画
  108. };
  109. },
  110. onLoad(opthios) {
  111. /**
  112. * 票赢天下小程序分享盲票跳转接受的参数
  113. * shareUid: 用户ID
  114. * shareType: 分享类型
  115. * */
  116. if (opthios.scene) {
  117. let sceneStr = decodeURIComponent(opthios.scene)
  118. this.sceneArr = sceneStr.split('&')
  119. uni.setStorageSync('shareUid', this.sceneArr[0])
  120. uni.setStorageSync('shareType', this.sceneArr[1])
  121. }
  122. this.getList()
  123. },
  124. onShow(opthios) {
  125. this.loginState = uni.getStorageSync('token') ? true : false
  126. this.getPrizeNews()
  127. },
  128. methods: {
  129. // 获取盲票列表
  130. getList() {
  131. uni.showLoading({
  132. title: '加载中'
  133. });
  134. let data = {
  135. categoryId: '',
  136. tagId: '',
  137. type: 'online',
  138. noToken: true
  139. }
  140. $http.post(`/api/v1/mp/user/mall/ticket/list?pageNum=${this.pageNum}&pageSize=100`, data).then(
  141. res => {
  142. uni.hideLoading();
  143. if (res.code == 0) {
  144. res.rows.forEach(item => item.picUrl = env.filePublic + item.picUrl.split(',')[0] +
  145. '?imageView2/2/w/375')
  146. this.ticketList = res.rows
  147. this.getPrize(this.ticketList[0].boxId)
  148. }
  149. }).catch(() => {
  150. uni.hideLoading();
  151. })
  152. },
  153. // 获取弹幕列表
  154. getPrizeNews() {
  155. $http.post('/api/v1/mp/user/ticket/hitPrizeBarrage', {}).then(res => {
  156. const {
  157. listOne,
  158. listTwo
  159. } = res && res.data
  160. listOne.forEach(item => {
  161. item.avatar = item.avatar ? env.filePublic + item.avatar : env.filePublic +
  162. '70/EJ305PQR2IBE45O9AFAI'
  163. item.prizeInfo = item.prizeInfo && (item.prizeInfo.length > 14) ? item.prizeInfo
  164. .substring(0, 15) + '...' : item.prizeInfo
  165. })
  166. listTwo.forEach(item => {
  167. item.avatar = item.avatar ? env.filePublic + item.avatar : env.filePublic +
  168. '70/EJ305PQR2IBE45O9AFAI'
  169. item.prizeInfo = item.prizeInfo && (item.prizeInfo.length > 14) ? item.prizeInfo
  170. .substring(0, 15) + '...' : item.prizeInfo
  171. })
  172. this.prizeNewsListOne = listOne
  173. this.prizeNewsListTwo = listTwo
  174. })
  175. },
  176. // 获取当前盲票的奖品列表
  177. getPrize(id) {
  178. this.prizeList = []
  179. $http.post('/api/v1/mp/user/mall/ticket/detail', {
  180. boxId: id,
  181. noToken: true
  182. }).then(res => {
  183. uni.hideLoading();
  184. if (res.code == 0) {
  185. let prizeList = res.data.prizeList
  186. prizeList.forEach(item => {
  187. let picUrlArr = item.picUrl.split(',')
  188. item.picUrl = env.filePublic + picUrlArr[0] + '?imageView2/2/w/170'
  189. })
  190. this.prizeList = prizeList
  191. // 根据奖品数量动态设置动画时间
  192. let time = Math.ceil(this.prizeList.length / 5 * 10)
  193. this.activeAnimation = `moveLeft ${ time }s linear infinite normal`,
  194. this.payInfo = this.ticketList[this.currentIndex]
  195. }
  196. }).catch(() => {
  197. uni.hideLoading();
  198. })
  199. },
  200. // 立即开刮
  201. payment() {
  202. this.payInfo = this.ticketList[this.currentIndex]
  203. let data = {
  204. userCouponIds: [],
  205. autoCoupon: 1,
  206. boxId: this.payInfo.boxId,
  207. orderNum: 1
  208. }
  209. $http.post('/api/v1/mp/user/ticket/order/settle', data).then(res => {
  210. if (res.code == 0) {
  211. let info = {
  212. ...res.data,
  213. ...this.payInfo,
  214. couponTitle: res.data && res.data.couponList && res.data.couponList.length && res
  215. .data.couponList[0].title,
  216. couponId: res.data && res.data.couponList && res.data.couponList.length && res.data
  217. .couponList[0].id
  218. }
  219. this.payInfo = info
  220. this.payShow = true
  221. }
  222. }).catch(() => {
  223. uni.$u.toast('开刮失败,请重试!');
  224. })
  225. },
  226. // 关闭支付弹框
  227. close() {
  228. this.payShow = false
  229. },
  230. // 盲票选中改变
  231. changeTicket(e) {
  232. this.getPrize(this.ticketList[this.currentIndex].boxId)
  233. },
  234. changeList() {
  235. let data = {
  236. categoryId: '',
  237. tagId: '',
  238. type: 'online',
  239. noToken: true
  240. }
  241. $http.post(`/api/v1/mp/user/mall/ticket/list?pageNum=${this.pageNum}&pageSize=100`, data).then(
  242. res => {
  243. const boxIdStr = this.ticketList.map(item => item.boxId).join()
  244. let boxIdStrNew = res && res.rows && res.rows.map(item => item.boxId).join()
  245. if (boxIdStr != boxIdStrNew) {
  246. this.currentIndex = 0
  247. this.getList()
  248. }
  249. })
  250. },
  251. // 盲票向左箭头
  252. ticketLeft() {
  253. if ((this.currentIndex >= 0) && (this.currentIndex < (this.ticketList.length - 1))) {
  254. this.currentIndex++
  255. } else if (this.currentIndex == (this.ticketList.length - 1)) {
  256. this.currentIndex = 0
  257. }
  258. this.changeList()
  259. },
  260. // 盲票向右箭头
  261. ticketRight() {
  262. if (this.currentIndex > 0) {
  263. this.currentIndex--
  264. } else if (this.currentIndex == 0) {
  265. this.currentIndex = this.ticketList.length - 1
  266. }
  267. this.changeList()
  268. },
  269. // 线上立即刮票成功,跳转到刮奖过程
  270. toProcess(id) {
  271. this.payShow = false
  272. uni.navigateTo({
  273. url: `/pages/process/index?id=${ id }`
  274. })
  275. },
  276. // 点击盲票,跳转盲票详情
  277. toTicketBox() {
  278. let item = this.ticketList[this.currentIndex]
  279. uni.navigateTo({
  280. url: `/pages/ticketBox/detail?boxId=${ item.boxId }`
  281. })
  282. },
  283. // 点击奖品,跳转到奖品详情
  284. toPrizeGoods(item) {
  285. if (item.prizeType == "goods") {
  286. uni.navigateTo({
  287. url: `/pages/prizeGoods/detail?id=${ item.refId }`
  288. })
  289. }
  290. //门店优惠券
  291. if (item.prizeType == "coupon") {
  292. // if (item.couponType == "1") {
  293. // uni.navigateTo({
  294. // url: `/pages/prizeGoods/detail?id=426`
  295. // })
  296. // }
  297. // if (item.couponType == "2") {
  298. // uni.navigateTo({
  299. // url: `/pages/prizeGoods/detail?id=425`
  300. // })
  301. // }
  302. uni.navigateTo({
  303. url: `/pages/prizeGoods/detail?id=425`
  304. })
  305. }
  306. // 盲豆
  307. if (item.prizeType == "coin") {
  308. uni.navigateTo({
  309. url: `/pages/prizeGoods/detail?id=424`
  310. })
  311. }
  312. },
  313. // 点击所有盲票
  314. toTicket() {
  315. uni.navigateTo({
  316. url: '/pages/ticketBox/index'
  317. })
  318. },
  319. // 点击奖品库
  320. toPrize() {
  321. if (!this.loginState) {
  322. uni.navigateTo({
  323. url: "/pages/login/index"
  324. })
  325. return
  326. }
  327. uni.navigateTo({
  328. url: '/pages/prize/index'
  329. })
  330. },
  331. // 点击规则说明
  332. toRule() {
  333. uni.navigateTo({
  334. url: '/pages/about/rule'
  335. })
  336. }
  337. },
  338. onShareAppMessage(res) {
  339. return {
  340. title: '盲票,玩的就是有趣',
  341. path: '/pages/index/index'
  342. }
  343. }
  344. }
  345. </script>
  346. <style lang="scss" scoped>
  347. .status_bar {
  348. width: 100%;
  349. height: var(--status-bar-height);
  350. }
  351. /deep/ .u-tabbar__placeholder {
  352. display: none;
  353. }
  354. </style>
  355. <style lang="scss" scoped>
  356. .box {
  357. width: 100%;
  358. height: calc(100vh - 50px);
  359. background: url(https://mp-public-1310078123.cos.ap-shanghai.myqcloud.com/index_bg.jpeg) center center;
  360. &-top {
  361. position: relative;
  362. display: flex;
  363. justify-content: space-between;
  364. padding: 130rpx 0 0 40rpx;
  365. &-action {
  366. z-index: 20;
  367. display: flex;
  368. &-item {
  369. margin-right: 76rpx;
  370. &-cir {
  371. width: 72rpx;
  372. height: 72rpx;
  373. background-color: #FFC320;
  374. border-radius: 50%;
  375. margin-bottom: 14rpx;
  376. image {
  377. width: 40rpx;
  378. height: 36rpx;
  379. }
  380. }
  381. &-txt {
  382. font-size: 24rpx;
  383. text-align: center;
  384. color: #FFFFFF;
  385. }
  386. }
  387. }
  388. &-tip {
  389. z-index: 20;
  390. display: flex;
  391. flex-direction: column;
  392. align-items: flex-end;
  393. justify-content: flex-end;
  394. &-txt {
  395. font-size: 24rpx;
  396. width: 152rpx;
  397. height: 48rpx;
  398. background-color: #FFC320;
  399. border-radius: 24rpx 0 0 24rpx;
  400. margin-top: 40rpx;
  401. }
  402. &-txt:last-child {
  403. background-color: #FFFFCC;
  404. }
  405. }
  406. &-news {
  407. position: absolute;
  408. left: 0;
  409. bottom: 0;
  410. z-index: 10;
  411. width: 100vw;
  412. }
  413. }
  414. &-ticket {
  415. position: relative;
  416. margin: 40rpx 0 0;
  417. .image-container {
  418. width: 750rpx;
  419. height: 40vh;
  420. .swiper-item {
  421. position: relative;
  422. width: 61vw;
  423. height: 40vh;
  424. display: flex;
  425. justify-content: center;
  426. align-items: center;
  427. }
  428. .image-wrap {
  429. position: relative;
  430. width: 61vw;
  431. height: 40vh;
  432. .img {
  433. width: 61vw;
  434. height: 40vh;
  435. }
  436. }
  437. }
  438. .prize-goods {
  439. display: flex;
  440. width: 100vw;
  441. height: 13vh;
  442. margin-top: 2vh;
  443. overflow: hidden;
  444. .prize-goods-item {
  445. display: flex;
  446. height: 13vh;
  447. .image-wrap {
  448. width: 160rpx;
  449. height: 13vh;
  450. border-radius: 20rpx;
  451. background: linear-gradient(0deg, #e6e6e6, #FFFFFF);
  452. margin-right: 60rpx;
  453. .img {
  454. width: 100%;
  455. height: 76%;
  456. }
  457. }
  458. }
  459. }
  460. .index-left {
  461. position: absolute;
  462. width: 100rpx;
  463. height: 100rpx;
  464. top: 380rpx;
  465. left: 10rpx;
  466. z-index: 20;
  467. }
  468. .index-right {
  469. position: absolute;
  470. width: 100rpx;
  471. height: 100rpx;
  472. top: 380rpx;
  473. right: 10rpx;
  474. z-index: 20;
  475. }
  476. .box-img {
  477. position: absolute;
  478. top: 0;
  479. z-index: 10;
  480. width: 100vw;
  481. height: 70vw;
  482. }
  483. }
  484. &-ticket-btn {
  485. margin-top: 30rpx;
  486. &-content {
  487. position: relative;
  488. width: 420rpx;
  489. height: 142rpx;
  490. image {
  491. width: 420rpx;
  492. height: 142rpx;
  493. }
  494. .title {
  495. position: absolute;
  496. top: 0;
  497. width: 100%;
  498. height: 142rpx;
  499. text {
  500. font-size: 56rpx;
  501. font-weight: bold;
  502. color: #C44906;
  503. text-shadow: 0px 1px 0px rgba(255, 255, 255, 0.76);
  504. }
  505. }
  506. }
  507. }
  508. }
  509. </style>