index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555
  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. <view class="prize-goods">
  49. <view class="prize-goods-item" :style="{ animation: activeAnimation }">
  50. <view class="flex image-wrap" v-for="(item, index) in prizeList" :key="index" @click="toPrizeGoods(item)">
  51. <image class="img" :src="item.picUrl" lazy-load mode="aspectFill"></image>
  52. </view>
  53. </view>
  54. <view class="prize-goods-item" :style="{ animation: activeAnimation }">
  55. <view class="flex image-wrap" v-for="(item, index) in prizeList" :key="index" @click="toPrizeGoods(item)">
  56. <image class="img" :src="item.picUrl" lazy-load mode="aspectFill"></image>
  57. </view>
  58. </view>
  59. </view>
  60. <!-- 盲票背景 -->
  61. <image class="box-img" src="../../static/icon/index_box.png" mode="" @click="toTicketBox"></image>
  62. <!-- 向左箭头 -->
  63. <image class="index-left" src="../../static/icon/index_left.png" mode="" @click="ticketLeft"></image>
  64. <!-- 向右箭头 -->
  65. <image class="index-right" src="../../static/icon/index_right.png" mode="" @click="ticketRight"></image>
  66. </view>
  67. <!-- 立即开刮 -->
  68. <view class="flex box-ticket-btn">
  69. <view class="box-ticket-btn-content" @click="payment">
  70. <image src="../../static/icon/index_btn.png" mode=""></image>
  71. <view class="flex title">
  72. <text>{{ payInfo.salePrice / 100 }}元立即开刮</text>
  73. </view>
  74. </view>
  75. </view>
  76. </view>
  77. <!-- tabbar组件 -->
  78. <custom-tab-bar :activeValue="'index'" />
  79. <!-- 支付弹框组件 -->
  80. <pay-popup :pay-show="payShow" :pay-info="payInfo" @close="close" @success="toProcess" v-if="payShow" />
  81. </view>
  82. </template>
  83. <script>
  84. import env from '../../config/env.js'
  85. import $http from '@/utils/request.js'
  86. import CustomTabBar from '../../components/custom-tab-bar/custom-tab-bar.vue'
  87. import PayPopup from '../../components/pay-popup/pay-popup.vue'
  88. // import PrizeNews from '../../components/prize-news/prize-news.vue'
  89. export default {
  90. components: {
  91. CustomTabBar,
  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. activeAnimation: 'moveLeft 10s linear infinite normal', // 奖品动画
  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. this.getList()
  121. },
  122. onShow(opthios) {
  123. this.loginState = uni.getStorageSync('token') ? true : false
  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. '?imageView2/2/w/375')
  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] + '?imageView2/2/w/170'
  187. })
  188. this.prizeList = prizeList
  189. // 根据奖品数量动态设置动画时间
  190. let time = Math.ceil(this.prizeList.length / 5 * 10)
  191. this.activeAnimation = `moveLeft ${ time }s linear infinite normal`,
  192. this.payInfo = this.ticketList[this.currentIndex]
  193. }
  194. }).catch(() => {
  195. uni.hideLoading();
  196. })
  197. },
  198. // 立即开刮
  199. payment() {
  200. this.payInfo = this.ticketList[this.currentIndex]
  201. let data = {
  202. userCouponIds: [],
  203. autoCoupon: 1,
  204. boxId: this.payInfo.boxId,
  205. orderNum: 1
  206. }
  207. $http.post('/api/v1/mp/user/ticket/order/settle', data).then(res => {
  208. if (res.code == 0) {
  209. let info = {
  210. ...res.data,
  211. ...this.payInfo,
  212. couponTitle: res.data && res.data.couponList && res.data.couponList.length && res
  213. .data.couponList[0].title,
  214. couponId: res.data && res.data.couponList && res.data.couponList.length && res.data
  215. .couponList[0].id
  216. }
  217. this.payInfo = info
  218. this.payShow = true
  219. }
  220. }).catch(() => {
  221. uni.$u.toast('开刮失败,请重试!');
  222. })
  223. },
  224. // 关闭支付弹框
  225. close() {
  226. this.payShow = false
  227. },
  228. // 盲票选中改变
  229. changeTicket({ detail }) {
  230. this.currentIndex = detail.current
  231. this.getPrize(this.ticketList[this.currentIndex].boxId)
  232. },
  233. changeList() {
  234. let data = {
  235. categoryId: '',
  236. tagId: '',
  237. type: 'online',
  238. noToken: true
  239. }
  240. $http.post(`/api/v1/mp/user/mall/ticket/list?pageNum=${this.pageNum}&pageSize=100`, data).then(
  241. res => {
  242. const boxIdStr = this.ticketList.map(item => item.boxId).join()
  243. let boxIdStrNew = res && res.rows && res.rows.map(item => item.boxId).join()
  244. if (boxIdStr != boxIdStrNew) {
  245. this.currentIndex = 0
  246. this.getList()
  247. }
  248. })
  249. },
  250. // 盲票向左箭头
  251. ticketLeft() {
  252. if ((this.currentIndex >= 0) && (this.currentIndex < (this.ticketList.length - 1))) {
  253. this.currentIndex++
  254. } else if (this.currentIndex == (this.ticketList.length - 1)) {
  255. this.currentIndex = 0
  256. }
  257. this.changeList()
  258. },
  259. // 盲票向右箭头
  260. ticketRight() {
  261. if (this.currentIndex > 0) {
  262. this.currentIndex--
  263. } else if (this.currentIndex == 0) {
  264. this.currentIndex = this.ticketList.length - 1
  265. }
  266. this.changeList()
  267. },
  268. // 线上立即刮票成功,跳转到刮奖过程
  269. toProcess(id) {
  270. this.payShow = false
  271. uni.navigateTo({
  272. url: `/packageOperate/process/index?id=${ id }`
  273. })
  274. },
  275. // 点击盲票,跳转盲票详情
  276. toTicketBox() {
  277. let item = this.ticketList[this.currentIndex]
  278. uni.navigateTo({
  279. url: `/packageGoods/ticket/detail?boxId=${ item.boxId }`
  280. })
  281. },
  282. // 点击奖品,跳转到奖品详情
  283. toPrizeGoods(item) {
  284. if (item.prizeType == "goods") {
  285. uni.navigateTo({
  286. url: `/packagePrize/goods/detail?id=${ item.refId }`
  287. })
  288. }
  289. //门店优惠券
  290. if (item.prizeType == "coupon") {
  291. // if (item.couponType == "1") {
  292. // uni.navigateTo({
  293. // url: `/packagePrize/goods/detail?id=426`
  294. // })
  295. // }
  296. // if (item.couponType == "2") {
  297. // uni.navigateTo({
  298. // url: `/packagePrize/goods/detail?id=425`
  299. // })
  300. // }
  301. uni.navigateTo({
  302. url: `/packagePrize/goods/detail?id=425`
  303. })
  304. }
  305. // 盲豆
  306. if (item.prizeType == "coin") {
  307. uni.navigateTo({
  308. url: `/packagePrize/goods/detail?id=424`
  309. })
  310. }
  311. },
  312. // 点击所有盲票
  313. toTicket() {
  314. uni.navigateTo({
  315. url: '/packageGoods/ticket/index'
  316. })
  317. },
  318. // 点击奖品库
  319. toPrize() {
  320. if (!this.loginState) {
  321. uni.navigateTo({
  322. url: "/pages/login/index"
  323. })
  324. return
  325. }
  326. uni.navigateTo({
  327. url: '/packagePrize/prize/index'
  328. })
  329. },
  330. // 点击规则说明
  331. toRule() {
  332. uni.navigateTo({
  333. url: '/packageOther/rule/index'
  334. })
  335. }
  336. },
  337. onShareAppMessage(res) {
  338. return {
  339. title: '盲票,玩的就是有趣',
  340. path: '/pages/index/index'
  341. }
  342. }
  343. }
  344. </script>
  345. <style lang="scss" scoped>
  346. .status_bar {
  347. width: 100%;
  348. height: var(--status-bar-height);
  349. }
  350. /deep/ .u-tabbar__placeholder {
  351. display: none;
  352. }
  353. </style>
  354. <style lang="scss" scoped>
  355. .box {
  356. width: 100%;
  357. height: calc(100vh - 50px);
  358. background: url(https://mp-public-1310078123.cos.ap-shanghai.myqcloud.com/index_bg.jpeg) center center;
  359. &-top {
  360. position: relative;
  361. display: flex;
  362. justify-content: space-between;
  363. padding: 130rpx 0 0 40rpx;
  364. &-action {
  365. z-index: 20;
  366. display: flex;
  367. &-item {
  368. margin-right: 76rpx;
  369. &-cir {
  370. width: 72rpx;
  371. height: 72rpx;
  372. background-color: #FFC320;
  373. border-radius: 50%;
  374. margin-bottom: 14rpx;
  375. image {
  376. width: 40rpx;
  377. height: 36rpx;
  378. }
  379. }
  380. &-txt {
  381. font-size: 24rpx;
  382. text-align: center;
  383. color: #FFFFFF;
  384. }
  385. }
  386. }
  387. &-tip {
  388. z-index: 20;
  389. display: flex;
  390. flex-direction: column;
  391. align-items: flex-end;
  392. justify-content: flex-end;
  393. &-txt {
  394. font-size: 24rpx;
  395. width: 152rpx;
  396. height: 48rpx;
  397. background-color: #FFC320;
  398. border-radius: 24rpx 0 0 24rpx;
  399. margin-top: 40rpx;
  400. }
  401. &-txt:last-child {
  402. background-color: #FFFFCC;
  403. }
  404. }
  405. &-news {
  406. position: absolute;
  407. left: 0;
  408. bottom: 0;
  409. z-index: 10;
  410. width: 100vw;
  411. }
  412. }
  413. &-ticket {
  414. position: relative;
  415. margin: 40rpx 0 0;
  416. .image-container {
  417. width: 750rpx;
  418. height: 40vh;
  419. .swiper-item {
  420. position: relative;
  421. width: 61vw;
  422. height: 40vh;
  423. display: flex;
  424. justify-content: center;
  425. align-items: center;
  426. }
  427. .image-wrap {
  428. position: relative;
  429. width: 61vw;
  430. height: 40vh;
  431. .img {
  432. width: 61vw;
  433. height: 40vh;
  434. }
  435. }
  436. }
  437. .prize-goods {
  438. display: flex;
  439. width: 100vw;
  440. height: 13vh;
  441. margin-top: 2vh;
  442. overflow: hidden;
  443. .prize-goods-item {
  444. display: flex;
  445. height: 13vh;
  446. .image-wrap {
  447. width: 160rpx;
  448. height: 13vh;
  449. border-radius: 20rpx;
  450. background: linear-gradient(0deg, #e6e6e6, #FFFFFF);
  451. margin-right: 60rpx;
  452. .img {
  453. width: 100%;
  454. height: 76%;
  455. }
  456. }
  457. }
  458. }
  459. .index-left {
  460. position: absolute;
  461. width: 100rpx;
  462. height: 100rpx;
  463. top: 380rpx;
  464. left: 10rpx;
  465. z-index: 20;
  466. }
  467. .index-right {
  468. position: absolute;
  469. width: 100rpx;
  470. height: 100rpx;
  471. top: 380rpx;
  472. right: 10rpx;
  473. z-index: 20;
  474. }
  475. .box-img {
  476. position: absolute;
  477. top: 0;
  478. z-index: 10;
  479. width: 100vw;
  480. height: 70vw;
  481. }
  482. }
  483. &-ticket-btn {
  484. margin-top: 30rpx;
  485. &-content {
  486. position: relative;
  487. width: 420rpx;
  488. height: 142rpx;
  489. image {
  490. width: 420rpx;
  491. height: 142rpx;
  492. }
  493. .title {
  494. position: absolute;
  495. top: 0;
  496. width: 100%;
  497. height: 142rpx;
  498. text {
  499. font-size: 56rpx;
  500. font-weight: bold;
  501. color: #C44906;
  502. text-shadow: 0px 1px 0px rgba(255, 255, 255, 0.76);
  503. }
  504. }
  505. }
  506. }
  507. }
  508. </style>