index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  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. }
  296. // 盲豆
  297. if (item.prizeType == "coin") {
  298. uni.navigateTo({
  299. url: `/pages/prizeGoods/detail?id=424`
  300. })
  301. }
  302. },
  303. // 点击所有盲票
  304. toTicket() {
  305. uni.navigateTo({
  306. url: '/pages/ticketBox/index'
  307. })
  308. },
  309. // 点击奖品库
  310. toPrize() {
  311. if (!this.loginState) {
  312. uni.navigateTo({
  313. url: "/pages/login/index"
  314. })
  315. return
  316. }
  317. uni.navigateTo({
  318. url: '/pages/prize/index'
  319. })
  320. },
  321. // 点击规则说明
  322. toRule() {
  323. uni.navigateTo({
  324. url: '/pages/about/rule'
  325. })
  326. }
  327. },
  328. onShareAppMessage(res) {
  329. return {
  330. title: '盲票,玩的就是有趣',
  331. path: '/pages/index/index'
  332. }
  333. }
  334. }
  335. </script>
  336. <style lang="scss" scoped>
  337. .status_bar {
  338. width: 100%;
  339. height: var(--status-bar-height);
  340. }
  341. /deep/ .u-tabbar__placeholder {
  342. display: none;
  343. }
  344. </style>
  345. <style lang="scss" scoped>
  346. .box {
  347. width: 100%;
  348. height: calc(100vh - 50px);
  349. background: url(https://mp-public-1310078123.cos.ap-shanghai.myqcloud.com/index_bg.jpeg) center center;
  350. &-top {
  351. position: relative;
  352. display: flex;
  353. justify-content: space-between;
  354. padding: 130rpx 0 0 40rpx;
  355. &-action {
  356. z-index: 20;
  357. display: flex;
  358. &-item {
  359. margin-right: 76rpx;
  360. &-cir {
  361. width: 72rpx;
  362. height: 72rpx;
  363. background-color: #FFC320;
  364. border-radius: 50%;
  365. margin-bottom: 14rpx;
  366. image {
  367. width: 40rpx;
  368. height: 36rpx;
  369. }
  370. }
  371. &-txt {
  372. font-size: 24rpx;
  373. text-align: center;
  374. color: #FFFFFF;
  375. }
  376. }
  377. }
  378. &-tip {
  379. z-index: 20;
  380. display: flex;
  381. flex-direction: column;
  382. align-items: flex-end;
  383. justify-content: flex-end;
  384. &-txt {
  385. font-size: 24rpx;
  386. width: 152rpx;
  387. height: 48rpx;
  388. background-color: #FFC320;
  389. border-radius: 24rpx 0 0 24rpx;
  390. margin-top: 40rpx;
  391. }
  392. &-txt:last-child {
  393. background-color: #FFFFCC;
  394. }
  395. }
  396. &-news {
  397. position: absolute;
  398. left: 0;
  399. bottom: 0;
  400. z-index: 10;
  401. width: 100vw;
  402. }
  403. }
  404. &-ticket {
  405. position: relative;
  406. margin: 40rpx 0 0;
  407. .image-container {
  408. width: 750rpx;
  409. height: 40vh;
  410. .swiper-item {
  411. position: relative;
  412. width: 61vw;
  413. height: 40vh;
  414. display: flex;
  415. justify-content: center;
  416. align-items: center;
  417. }
  418. .image-wrap {
  419. position: relative;
  420. width: 61vw;
  421. height: 40vh;
  422. .img {
  423. width: 61vw;
  424. height: 40vh;
  425. }
  426. }
  427. }
  428. .prize-container {
  429. width: 750rpx;
  430. height: 13vh;
  431. margin-top: 2vh;
  432. .swiper-item {
  433. width: 100rpx;
  434. height: 13vh;
  435. display: flex;
  436. justify-content: flex-start;
  437. align-items: center;
  438. .image-wrap {
  439. width: 160rpx;
  440. height: 13vh;
  441. border-radius: 20rpx;
  442. background: linear-gradient(0deg, #e6e6e6, #FFFFFF);
  443. .img {
  444. width: 100%;
  445. height: 76%;
  446. }
  447. }
  448. }
  449. }
  450. .index-left {
  451. position: absolute;
  452. width: 100rpx;
  453. height: 100rpx;
  454. top: 380rpx;
  455. left: 10rpx;
  456. z-index: 20;
  457. }
  458. .index-right {
  459. position: absolute;
  460. width: 100rpx;
  461. height: 100rpx;
  462. top: 380rpx;
  463. right: 10rpx;
  464. z-index: 20;
  465. }
  466. .box-img {
  467. position: absolute;
  468. top: 0;
  469. z-index: 10;
  470. width: 100vw;
  471. height: 70vw;
  472. }
  473. }
  474. &-ticket-btn {
  475. margin-top: 30rpx;
  476. &-content {
  477. position: relative;
  478. width: 420rpx;
  479. height: 142rpx;
  480. image {
  481. width: 420rpx;
  482. height: 142rpx;
  483. }
  484. .title {
  485. position: absolute;
  486. top: 0;
  487. width: 100%;
  488. height: 142rpx;
  489. text {
  490. font-size: 56rpx;
  491. font-weight: bold;
  492. color: #C44906;
  493. text-shadow: 0px 1px 0px rgba(255, 255, 255, 0.76);
  494. }
  495. }
  496. }
  497. }
  498. }
  499. </style>