index.vue 15 KB

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