index.vue 13 KB

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