index.vue 12 KB

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