index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672
  1. <template>
  2. <view>
  3. <u-navbar :placeholder="true" bgColor="#fff" :autoBack="true" :border="true" title="盲票开启" v-if="rollingShow"></u-navbar>
  4. <view class="rolling" v-if="rollingShow">
  5. <!-- 奖品滚动 -->
  6. <view class="rolling-prize">
  7. <view ref="rolling" class="rolling-prize-list" :animation="animationData">
  8. <view class="rolling-prize-list-item flex" v-for="(item, index) in list" :key="index">
  9. <view class="rolling-prize-list-item__items flex">
  10. <view class="content flex" v-for="(items, indexs) in item" :key="indexs">
  11. <image :src="items.picUrl" mode="aspectFit"></image>
  12. <view class="content-title ells-one" v-if="items.prizeType && items.prizeType.value != 'coin'">{{ items.title }}</view>
  13. <view class="content-title ells-one" v-else>盲豆</view>
  14. <view class="content-price" v-if="items.prizeType && items.prizeType.value != 'coin'">¥{{ $numberFormat(items.value) }}</view>
  15. <view class="content-price" v-else>{{ items.value }}个</view>
  16. </view>
  17. </view>
  18. </view>
  19. </view>
  20. <view class="rolling-prize-list" :animation="animationData">
  21. <view class="rolling-prize-list-item flex" v-for="(item, index) in list" :key="index">
  22. <view class="rolling-prize-list-item__items flex">
  23. <view class="content flex" v-for="(items, indexs) in item" :key="indexs">
  24. <image :src="items.picUrl" mode="aspectFit"></image>
  25. <view class="content-title ells-one" v-if="items.prizeType && items.prizeType.value != 'coin'">{{ items.title }}</view>
  26. <view class="content-title ells-one" v-else>盲豆</view>
  27. <view class="content-price" v-if="items.prizeType && items.prizeType.value != 'coin'">¥{{ $numberFormat(items.value) }}</view>
  28. <view class="content-price" v-else>{{ items.value }}个</view>
  29. </view>
  30. </view>
  31. </view>
  32. </view>
  33. </view>
  34. <!-- 按钮 -->
  35. <view class="rolling-btn flex">
  36. <view class="rolling-btn-content flex" :class="{ 'btn-stop': btnIng }" @click="stop" v-show="btnShow">
  37. <image src="../../static/ticketBox/ticket_btn_center.png" mode="scaleToFill"></image>
  38. <view class="rolling-btn-content-title">停止滚动</view>
  39. </view>
  40. </view>
  41. <!-- 倒计时 -->
  42. <view class="rolling-time flex">
  43. <view class="num">{{ num }}</view>
  44. </view>
  45. </view>
  46. <!-- 奖品显示 -->
  47. <view class="prize" v-else>
  48. <view class="prize-navLeft flex" :style="{ top: statusHeight + 'px' }" @click="back">
  49. <u-icon size="19" color="#fff" name="arrow-left"></u-icon>
  50. </view>
  51. <view class="prize-title flex">
  52. <image src="../../packagePrize/static/rolling_title.png" mode="scaleToFill"></image>
  53. </view>
  54. <view class="prize-box flex">
  55. <view class="prize-box-popup flex">
  56. <view class="prize-box-popup__image flex">
  57. <image :src="prizeInfo.picUrl" mode="aspectFit"></image>
  58. </view>
  59. <image class="prize-box-popup__rotate" src="../static/rolling_bg1.png" mode="" v-if="rotateShow" />
  60. <image class="prize-box-popup__circular" src="../static/rolling_bg2.png" mode="" v-if="circularShow" />
  61. </view>
  62. </view>
  63. <view class="prize-info flex">
  64. <view class="prize-info-content">
  65. <view class="prize-info-content-price" v-if="prizeInfo.prizeType && prizeInfo.prizeType.value != 'coin'"><text>¥</text>{{ $numberFormat(prizeInfo.value) }}</view>
  66. <view class="prize-info-content-price" v-else>{{ prizeInfo.value }}个</view>
  67. <view class="prize-info-content-title ells-one" v-if="prizeInfo.prizeType && prizeInfo.prizeType.value != 'coin'">{{ prizeInfo.title }}</view>
  68. <view class="prize-info-content-title" v-else>盲豆</view>
  69. <view class="prize-info-content-btn flex">
  70. <view class="prize-info-content-btn-content flex" v-if="isTry == 0">
  71. <image src="../../packagePrize/static/rolling_btn.png" mode="aspectFit"></image>
  72. <view class="prize-info-content-btn-content-txt" @click="toPrize(prizeInfo.prizeType)" v-if="prizeInfo.prizeType && prizeInfo.prizeType.value != 'coin'">哇,去瞅瞅我的宝贝</view>
  73. <view class="prize-info-content-btn-content-txt" @click="toPrize(prizeInfo.prizeType)" v-else>哇,去商城兑换商品</view>
  74. </view>
  75. <view class="prize-info-content-btn-content flex" v-else @click="back">
  76. <image src="../../packagePrize/static/rolling_btn.png" mode="aspectFit"></image>
  77. <view class="prize-info-content-btn-content-txt">来把真的</view>
  78. </view>
  79. </view>
  80. </view>
  81. </view>
  82. <view class="prize-tip flex" v-if="isTry == 0" @click="back">
  83. <view class="txt">再来一张</view>
  84. </view>
  85. </view>
  86. </view>
  87. </template>
  88. <script>
  89. import env from '../../config/env.js'
  90. import $http from '@/utils/request.js'
  91. export default {
  92. data() {
  93. return {
  94. animationData: {}, // 动画信息
  95. num: 8, // 动画倒计时
  96. num2: 0, // 动画持续时间
  97. time: null, // 定时器
  98. stopTime: null, //自动停止
  99. list: [],
  100. prizeInfo: {},
  101. btnIng: false,
  102. rollingShow: true,
  103. statusHeight: 30,
  104. btnShow: false,
  105. boxId: '',
  106. isTry: null,
  107. orderId: '',
  108. rotateShow: true,
  109. circularShow: true
  110. }
  111. },
  112. onLoad(options) {
  113. // 创建动画实例
  114. this.animation = uni.createAnimation()
  115. // #ifdef MP-WEIXIN
  116. const res = uni.getMenuButtonBoundingClientRect()
  117. this.statusHeight = res.top //胶囊距离顶部
  118. // #endif
  119. if(options) {
  120. this.boxId = options.boxId
  121. this.isTry = Number(options.isTry)
  122. this.orderId = options.orderId
  123. }
  124. },
  125. onUnload() {
  126. // 移除动画
  127. this.animationData = {}
  128. },
  129. mounted() {
  130. this.getList()
  131. },
  132. methods: {
  133. getList() {
  134. let _this = this
  135. let data = {
  136. boxId: _this.boxId,
  137. isTry: _this.isTry,
  138. orderId: _this.orderId
  139. }
  140. let num = 0
  141. let time = setInterval(() => {
  142. num ++
  143. uni.showLoading({
  144. title: '加载中'
  145. });
  146. $http.post('/api/v1/mp/user/ticket/autoCashPrize', data).then(res => {
  147. if(res.code == 0) {
  148. clearInterval(time)
  149. _this.list = res.data.ticketAwardsPrizeList
  150. _this.list.forEach(item => {
  151. item.forEach(ele => {
  152. ele.picUrl = env.filePublic + ele.picUrl.split(',')[0] + '?imageView2/2/w/170'
  153. ele.prizeType = JSON.parse(ele.prizeType)
  154. })
  155. })
  156. _this.prizeInfo = {
  157. ...res.data,
  158. picUrl: env.filePublic + res.data.picUrl.split(',')[0] + '?imageView2/2/w/340',
  159. prizeType: JSON.parse(res.data.prizeType)
  160. }
  161. setTimeout(()=> {
  162. uni.hideLoading();
  163. _this.btnShow = true
  164. _this.running()
  165. },500)
  166. } else if (res.code == 401 || res.code == 500) {
  167. uni.hideLoading();
  168. clearInterval(time)
  169. uni.navigateBack({
  170. delta: 2
  171. })
  172. }
  173. if (num == 10) {
  174. uni.hideLoading();
  175. clearInterval(time)
  176. }
  177. })
  178. }, 1000)
  179. },
  180. // 动画开始
  181. running() {
  182. // #ifdef H5
  183. // 获取滚动奖品列表长度
  184. this.data = this.$refs.rolling.$el.clientWidth
  185. // 调用 step() 来表示一组动画完成
  186. this.animation.translateX(-this.data).step({
  187. duration: 8000,
  188. timingFunction: 'linear'
  189. })
  190. // export方法导出动画数据
  191. this.animationData = this.animation.export()
  192. // 倒计时
  193. this.time = setInterval(() => {
  194. // 开奖倒计时、页面显示
  195. this.num--
  196. // 记录动画执行时间,停止动画计算移动距离时使用
  197. this.num2++
  198. if (this.num == 0) {
  199. clearInterval(this.time)
  200. }
  201. }, 1000)
  202. // 不手动停止动画,自动停止
  203. this.stopTime = setTimeout(() => {
  204. this.stop()
  205. }, 8000);
  206. // #endif
  207. // #ifdef MP-WEIXIN
  208. // 元素详细信息
  209. uni.createSelectorQuery().in(this).select(".rolling-prize-list").boundingClientRect(info => {
  210. this.data = info.width
  211. // 调用 step() 来表示一组动画完成
  212. this.animation.translateX(-this.data).step({
  213. duration: 8000,
  214. timingFunction: 'linear'
  215. })
  216. // export方法导出动画数据
  217. this.animationData = this.animation.export()
  218. // 倒计时
  219. this.time = setInterval(() => {
  220. // 开奖倒计时、页面显示
  221. this.num--
  222. // 记录动画执行时间,停止动画计算移动距离时使用
  223. this.num2++
  224. if (this.num == 0) {
  225. clearInterval(this.time)
  226. }
  227. }, 1000)
  228. }).exec();
  229. // 不手动停止动画,自动停止
  230. this.stopTime = setTimeout(() => {
  231. this.num = 0
  232. this.stop()
  233. }, 8000);
  234. // #endif
  235. },
  236. // 停止动画
  237. stop() {
  238. // 获取屏幕距离,用于计算停止动画移动距离计算
  239. let screenWidth = null
  240. uni.getSystemInfo({
  241. success: function(res) {
  242. screenWidth = res.screenWidth;
  243. }
  244. });
  245. this.btnIng = true
  246. /**
  247. * 0秒:下标4
  248. * 1秒:下标6
  249. * 2秒:下标8
  250. * 3秒:下标10
  251. * 4秒:下标12
  252. * 5秒:下标14
  253. * 6秒:下标16
  254. * 7秒:下标2
  255. * 8秒:下标2
  256. * */
  257. clearInterval(this.time)
  258. clearTimeout(this.stopTime)
  259. this.animationData = {}
  260. if (this.num2 == 0) {
  261. this.list[3][1] = JSON.parse(JSON.stringify(this.prizeInfo))
  262. } else if (this.num2 == 1) {
  263. this.list[5][1] = JSON.parse(JSON.stringify(this.prizeInfo))
  264. } else if (this.num2 == 2) {
  265. this.list[7][1] = JSON.parse(JSON.stringify(this.prizeInfo))
  266. } else if (this.num2 == 3) {
  267. this.list[9][1] = JSON.parse(JSON.stringify(this.prizeInfo))
  268. } else if (this.num2 == 4) {
  269. this.list[11][1] = JSON.parse(JSON.stringify(this.prizeInfo))
  270. } else if (this.num2 == 5) {
  271. this.list[13][1] = JSON.parse(JSON.stringify(this.prizeInfo))
  272. } else if (this.num2 == 6) {
  273. this.list[15][1] = JSON.parse(JSON.stringify(this.prizeInfo))
  274. } else if (this.num2 == 7) {
  275. this.list[1][1] = JSON.parse(JSON.stringify(this.prizeInfo))
  276. } else if (this.num2 == 8) {
  277. // #ifdef MP-WEIXIN
  278. this.list[1][1] = JSON.parse(JSON.stringify(this.prizeInfo))
  279. // #endif
  280. // #ifdef H5
  281. this.list[3][1] = JSON.parse(JSON.stringify(this.prizeInfo))
  282. // #endif
  283. }
  284. // #ifdef H5
  285. /**
  286. * 根据动画时间移动到指定位置
  287. * this.data / 8 :动画平均移动距离
  288. * this.num2 : 动画执行时间
  289. * screenWidth * 3 :移动3个屏幕距离
  290. */
  291. this.animation.translateX(-(this.data / 8 * this.num2 + screenWidth * 3)).step({
  292. duration: 4000,
  293. timingFunction: 'ease'
  294. })
  295. this.animationData = this.animation.export()
  296. setTimeout(() => {
  297. this.rollingShow = false
  298. },4500)
  299. setTimeout(() => {
  300. this.circularShow = false
  301. },5100)
  302. setTimeout(() => {
  303. this.rotateShow = false
  304. },7500)
  305. // #endif
  306. // #ifdef MP-WEIXIN
  307. uni.createSelectorQuery().in(this).select(".rolling-prize-list").boundingClientRect(info => {
  308. this.data = info.width
  309. this.animation.translateX(-(this.data / 8 * this.num2 + screenWidth * 3)).step({
  310. duration: 4000,
  311. timingFunction: 'ease'
  312. })
  313. this.animationData = this.animation.export()
  314. }).exec();
  315. setTimeout(() => {
  316. this.rollingShow = false
  317. },4500)
  318. setTimeout(() => {
  319. this.circularShow = false
  320. },5100)
  321. setTimeout(() => {
  322. this.rotateShow = false
  323. },7500)
  324. // #endif
  325. },
  326. back() {
  327. uni.navigateBack({
  328. delta: 1
  329. })
  330. },
  331. toPrize(data) {
  332. if (data.value == 'goods') {
  333. uni.redirectTo({
  334. url: '/packagePrize/prize/index'
  335. })
  336. }
  337. if (data.value == 'coupon') {
  338. uni.redirectTo({
  339. url: '/packagePrize/prize/index?coupon=1'
  340. })
  341. }
  342. if (data.value == 'coupon_pkg') {
  343. uni.redirectTo({
  344. url: '/packagePrize/prize/index?coupon=1'
  345. })
  346. }
  347. if (data.value == 'coin') {
  348. uni.switchTab({
  349. url: '/pages/core/index'
  350. })
  351. }
  352. },
  353. },
  354. }
  355. </script>
  356. <style lang="scss" scoped>
  357. .rolling {
  358. width: 100%;
  359. height: calc(100vh - 44px);
  360. background: url(https://mp-public-1310078123.cos.ap-shanghai.myqcloud.com/v2/prize_bkg1.png) center center no-repeat;
  361. background-size: 100vw calc(100vh - 44px);
  362. overflow: hidden;
  363. // 奖品滚动
  364. &-prize {
  365. display: flex;
  366. margin-top: 30vh;
  367. height: 28vh;
  368. background: url(https://mp-public-1310078123.cos.ap-shanghai.myqcloud.com/v2/prize_bkg2.png) center center no-repeat;
  369. background-size: 100vw 28vh;
  370. margin-bottom: 42rpx;
  371. &-list {
  372. display: flex;
  373. margin-top: 76rpx;
  374. height: calc(100% - 76rpx);
  375. &-item {
  376. width: 100vw;
  377. height: 100%;
  378. &__items {
  379. align-items: flex-start;
  380. justify-content: space-evenly;
  381. width: 100vw;
  382. height: 100%;
  383. .content {
  384. flex-direction: column;
  385. width: 30%;
  386. height: 85%;
  387. image {
  388. width: 100%;
  389. height: 60%;
  390. margin-bottom: 16rpx;
  391. }
  392. &-title {
  393. width: 100%;
  394. line-height: 34rpx;
  395. font-size: 26rpx;
  396. text-align: center;
  397. margin-bottom: 20rpx;
  398. }
  399. &-price {
  400. width: 100%;
  401. line-height: 26rpx;
  402. font-size: 26rpx;
  403. text-align: center;
  404. }
  405. }
  406. // .content:nth-child(2) {
  407. // justify-content: flex-start;
  408. // color: #333;
  409. // image {
  410. // width: 100%;
  411. // height: 60%;
  412. // }
  413. // .content-title {
  414. // font-weight: bold;
  415. // }
  416. // .content-price {
  417. // font-weight: bold;
  418. // }
  419. // }
  420. }
  421. }
  422. }
  423. }
  424. // 按钮
  425. &-btn {
  426. height: 160rpx;
  427. margin-bottom: 36rpx;
  428. &-content {
  429. position: relative;
  430. height: 100%;
  431. image {
  432. width: 486rpx;
  433. height: 100%;
  434. }
  435. &-title {
  436. position: absolute;
  437. top: 30rpx;
  438. font-size: 72rpx;
  439. font-family: YouSheBiaoTiHei;
  440. font-weight: 400;
  441. color: #FFFFFF;
  442. line-height: 72rpx;
  443. opacity: 0.99;
  444. }
  445. }
  446. .btn-stop {
  447. animation: scaleBtn 0.2s linear;
  448. }
  449. // 放大缩小动画
  450. @keyframes scaleBtn {
  451. from {
  452. transform: scale(0.9);
  453. }
  454. to {
  455. transform: scale(1);
  456. }
  457. }
  458. }
  459. // 倒计时
  460. &-time {
  461. .num {
  462. font-size: 110rpx;
  463. font-family: YouSheBiaoTiHei;
  464. font-weight: 400;
  465. color: #FFFFFF;
  466. line-height: 110rpx;
  467. }
  468. }
  469. }
  470. // 奖品显示
  471. .prize {
  472. position: relative;
  473. width: 100%;
  474. height: 100vh;
  475. background: url(https://mp-public-1310078123.cos.ap-shanghai.myqcloud.com/v2/hit_bkg.png) center center no-repeat;
  476. background-size: 100vw 100vh;
  477. overflow: hidden;
  478. &-navLeft {
  479. position: absolute;
  480. left: 34rpx;
  481. width: 66rpx;
  482. height: 66rpx;
  483. background-color: rgba(255, 255, 255, .36);
  484. border-radius: 50%;
  485. }
  486. &-title {
  487. padding-top: 15vh;
  488. margin-bottom: 120rpx;
  489. image {
  490. width: 484rpx;
  491. height: 108rpx;
  492. }
  493. }
  494. &-box {
  495. margin-bottom: 34rpx;
  496. &-popup {
  497. position: relative;
  498. flex-direction: column;
  499. width: 75vw;
  500. height: 38vh;
  501. background-color: #FFFFFF;
  502. border-radius: 22rpx;
  503. &__image {
  504. position: relative;
  505. z-index: 10;
  506. width: 65%;
  507. height: 65%;
  508. image {
  509. width: 100%;
  510. height: 100%;
  511. }
  512. }
  513. &__rotate {
  514. position: absolute;
  515. width: 100%;
  516. height: 100%;
  517. z-index: 5;
  518. animation: rotateBg 3s linear;
  519. }
  520. &__circular {
  521. position: absolute;
  522. width: 600rpx;
  523. height: 600rpx;
  524. z-index: 5;
  525. animation: scaleBg 0.7s linear;
  526. }
  527. // 旋转动画
  528. @keyframes rotateBg {
  529. from {
  530. transform: rotate(0);
  531. }
  532. to {
  533. transform: rotate(360deg);
  534. }
  535. }
  536. // 放大动画
  537. @keyframes scaleBg {
  538. from {
  539. transform: scale(0.8);
  540. }
  541. to {
  542. transform: scale(1.8);
  543. }
  544. }
  545. }
  546. }
  547. &-info {
  548. margin-bottom: 40rpx;
  549. &-content {
  550. width: 70vw;
  551. &-price {
  552. text-align: center;
  553. font-size: 40rpx;
  554. line-height: 40rpx;
  555. font-family: PingFang SC;
  556. font-weight: bold;
  557. color: #FFFFFF;
  558. margin-bottom: 20rpx;
  559. text {
  560. font-size: 28rpx;
  561. }
  562. }
  563. &-title {
  564. height: 36rpx;
  565. overflow: hidden;
  566. text-align: center;
  567. font-size: 36rpx;
  568. line-height: 36rpx;
  569. color: #FFFFFF;
  570. margin-bottom: 50rpx;
  571. }
  572. &-btn {
  573. &-content {
  574. position: relative;
  575. width: 70vw;
  576. image {
  577. width: 70vw;
  578. height: 112rpx;
  579. }
  580. &-txt {
  581. position: absolute;
  582. top: 0;
  583. height: 112rpx;
  584. line-height: 112rpx;
  585. font-size: 30rpx;
  586. text-align: center;
  587. color: #FFFFFF;
  588. }
  589. }
  590. }
  591. }
  592. }
  593. &-tip {
  594. .txt {
  595. width: 332rpx;
  596. height: 66rpx;
  597. line-height: 66rpx;
  598. text-align: center;
  599. background: rgba(255, 211, 157, .3);
  600. border-radius: 34rpx;
  601. font-size: 34rpx;
  602. font-weight: 500;
  603. color: #FB930D;
  604. }
  605. }
  606. }
  607. </style>