index.vue 13 KB

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