index.vue 12 KB

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