index.vue 17 KB

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