index.vue 15 KB

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