index.vue 17 KB

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