index.vue 15 KB

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