index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557
  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({ detail }) {
  232. this.currentIndex = detail.current
  233. this.getPrize(this.ticketList[this.currentIndex].boxId)
  234. },
  235. changeList() {
  236. let data = {
  237. categoryId: '',
  238. tagId: '',
  239. type: 'online',
  240. noToken: true
  241. }
  242. $http.post(`/api/v1/mp/user/mall/ticket/list?pageNum=${this.pageNum}&pageSize=100`, data).then(
  243. res => {
  244. const boxIdStr = this.ticketList.map(item => item.boxId).join()
  245. let boxIdStrNew = res && res.rows && res.rows.map(item => item.boxId).join()
  246. if (boxIdStr != boxIdStrNew) {
  247. this.currentIndex = 0
  248. this.getList()
  249. }
  250. })
  251. },
  252. // 盲票向左箭头
  253. ticketLeft() {
  254. if ((this.currentIndex >= 0) && (this.currentIndex < (this.ticketList.length - 1))) {
  255. this.currentIndex++
  256. } else if (this.currentIndex == (this.ticketList.length - 1)) {
  257. this.currentIndex = 0
  258. }
  259. this.changeList()
  260. },
  261. // 盲票向右箭头
  262. ticketRight() {
  263. if (this.currentIndex > 0) {
  264. this.currentIndex--
  265. } else if (this.currentIndex == 0) {
  266. this.currentIndex = this.ticketList.length - 1
  267. }
  268. this.changeList()
  269. },
  270. // 线上立即刮票成功,跳转到刮奖过程
  271. toProcess(id) {
  272. this.payShow = false
  273. uni.navigateTo({
  274. url: `/pages/process/index?id=${ id }`
  275. })
  276. },
  277. // 点击盲票,跳转盲票详情
  278. toTicketBox() {
  279. let item = this.ticketList[this.currentIndex]
  280. uni.navigateTo({
  281. url: `/pages/ticketBox/detail?boxId=${ item.boxId }`
  282. })
  283. },
  284. // 点击奖品,跳转到奖品详情
  285. toPrizeGoods(item) {
  286. if (item.prizeType == "goods") {
  287. uni.navigateTo({
  288. url: `/pages/prizeGoods/detail?id=${ item.refId }`
  289. })
  290. }
  291. //门店优惠券
  292. if (item.prizeType == "coupon") {
  293. // if (item.couponType == "1") {
  294. // uni.navigateTo({
  295. // url: `/pages/prizeGoods/detail?id=426`
  296. // })
  297. // }
  298. // if (item.couponType == "2") {
  299. // uni.navigateTo({
  300. // url: `/pages/prizeGoods/detail?id=425`
  301. // })
  302. // }
  303. uni.navigateTo({
  304. url: `/pages/prizeGoods/detail?id=425`
  305. })
  306. }
  307. // 盲豆
  308. if (item.prizeType == "coin") {
  309. uni.navigateTo({
  310. url: `/pages/prizeGoods/detail?id=424`
  311. })
  312. }
  313. },
  314. // 点击所有盲票
  315. toTicket() {
  316. uni.navigateTo({
  317. url: '/pages/ticketBox/index'
  318. })
  319. },
  320. // 点击奖品库
  321. toPrize() {
  322. if (!this.loginState) {
  323. uni.navigateTo({
  324. url: "/pages/login/index"
  325. })
  326. return
  327. }
  328. uni.navigateTo({
  329. url: '/pages/prize/index'
  330. })
  331. },
  332. // 点击规则说明
  333. toRule() {
  334. uni.navigateTo({
  335. url: '/pages/about/rule'
  336. })
  337. }
  338. },
  339. onShareAppMessage(res) {
  340. return {
  341. title: '盲票,玩的就是有趣',
  342. path: '/pages/index/index'
  343. }
  344. }
  345. }
  346. </script>
  347. <style lang="scss" scoped>
  348. .status_bar {
  349. width: 100%;
  350. height: var(--status-bar-height);
  351. }
  352. /deep/ .u-tabbar__placeholder {
  353. display: none;
  354. }
  355. </style>
  356. <style lang="scss" scoped>
  357. .box {
  358. width: 100%;
  359. height: calc(100vh - 50px);
  360. background: url(https://mp-public-1310078123.cos.ap-shanghai.myqcloud.com/index_bg.jpeg) center center;
  361. &-top {
  362. position: relative;
  363. display: flex;
  364. justify-content: space-between;
  365. padding: 130rpx 0 0 40rpx;
  366. &-action {
  367. z-index: 20;
  368. display: flex;
  369. &-item {
  370. margin-right: 76rpx;
  371. &-cir {
  372. width: 72rpx;
  373. height: 72rpx;
  374. background-color: #FFC320;
  375. border-radius: 50%;
  376. margin-bottom: 14rpx;
  377. image {
  378. width: 40rpx;
  379. height: 36rpx;
  380. }
  381. }
  382. &-txt {
  383. font-size: 24rpx;
  384. text-align: center;
  385. color: #FFFFFF;
  386. }
  387. }
  388. }
  389. &-tip {
  390. z-index: 20;
  391. display: flex;
  392. flex-direction: column;
  393. align-items: flex-end;
  394. justify-content: flex-end;
  395. &-txt {
  396. font-size: 24rpx;
  397. width: 152rpx;
  398. height: 48rpx;
  399. background-color: #FFC320;
  400. border-radius: 24rpx 0 0 24rpx;
  401. margin-top: 40rpx;
  402. }
  403. &-txt:last-child {
  404. background-color: #FFFFCC;
  405. }
  406. }
  407. &-news {
  408. position: absolute;
  409. left: 0;
  410. bottom: 0;
  411. z-index: 10;
  412. width: 100vw;
  413. }
  414. }
  415. &-ticket {
  416. position: relative;
  417. margin: 40rpx 0 0;
  418. .image-container {
  419. width: 750rpx;
  420. height: 40vh;
  421. .swiper-item {
  422. position: relative;
  423. width: 61vw;
  424. height: 40vh;
  425. display: flex;
  426. justify-content: center;
  427. align-items: center;
  428. }
  429. .image-wrap {
  430. position: relative;
  431. width: 61vw;
  432. height: 40vh;
  433. .img {
  434. width: 61vw;
  435. height: 40vh;
  436. }
  437. }
  438. }
  439. .prize-goods {
  440. display: flex;
  441. width: 100vw;
  442. height: 13vh;
  443. margin-top: 2vh;
  444. overflow: hidden;
  445. .prize-goods-item {
  446. display: flex;
  447. height: 13vh;
  448. .image-wrap {
  449. width: 160rpx;
  450. height: 13vh;
  451. border-radius: 20rpx;
  452. background: linear-gradient(0deg, #e6e6e6, #FFFFFF);
  453. margin-right: 60rpx;
  454. .img {
  455. width: 100%;
  456. height: 76%;
  457. }
  458. }
  459. }
  460. }
  461. .index-left {
  462. position: absolute;
  463. width: 100rpx;
  464. height: 100rpx;
  465. top: 380rpx;
  466. left: 10rpx;
  467. z-index: 20;
  468. }
  469. .index-right {
  470. position: absolute;
  471. width: 100rpx;
  472. height: 100rpx;
  473. top: 380rpx;
  474. right: 10rpx;
  475. z-index: 20;
  476. }
  477. .box-img {
  478. position: absolute;
  479. top: 0;
  480. z-index: 10;
  481. width: 100vw;
  482. height: 70vw;
  483. }
  484. }
  485. &-ticket-btn {
  486. margin-top: 30rpx;
  487. &-content {
  488. position: relative;
  489. width: 420rpx;
  490. height: 142rpx;
  491. image {
  492. width: 420rpx;
  493. height: 142rpx;
  494. }
  495. .title {
  496. position: absolute;
  497. top: 0;
  498. width: 100%;
  499. height: 142rpx;
  500. text {
  501. font-size: 56rpx;
  502. font-weight: bold;
  503. color: #C44906;
  504. text-shadow: 0px 1px 0px rgba(255, 255, 255, 0.76);
  505. }
  506. }
  507. }
  508. }
  509. }
  510. </style>