show-result.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681
  1. <template>
  2. <uni-popup class="result-popup-main" ref="prize" mode="top" :mask="false">
  3. <view class="result-popup">
  4. <view :class="['prize', explode && 'show']">
  5. <view class="prize_box">
  6. <view class="prize_close" @click="close()"><image src="https://www.chaomangdao.com/image/home/guanbi@2x.png" mode=""></image></view>
  7. <!-- <view class="prize-top" :class="`prize-top-${mode}`">
  8. <image src="/static/image/result/gaizi@2x.png" mode="aspectFit"></image>
  9. </view -->
  10. >
  11. <!-- 1开 -->
  12. <view :class="['prize_shop', 'center', 'onebox', 'tag-' + tag, scale && 'prize_shop_scale']" v-if="mode == 0">
  13. <view class="spining"></view>
  14. <view class="left-top-tag">
  15. <image class="tag-img" :src="tagImg" mode="aspectFit"></image>
  16. <text class="tag-text">{{ tagText }}</text>
  17. </view>
  18. <image class="one" v-if="prizedata && prizedata.prizeInfo" :src="prizedata.prizeInfo[0].image" mode="widthFix"></image>
  19. <text class="colorblack" v-if="prizedata && prizedata.prizeInfo">{{ prizedata.prizeInfo[0].goods_name }}</text>
  20. <text class="colorblack" v-if="prizedata && prizedata.prizeInfo">¥{{ prizedata.prizeInfo[0].coin_price }}</text>
  21. </view>
  22. <!-- 5开or10开 -->
  23. <view class="prize_ul" :class="'prize_ul-' + mode" v-else>
  24. <!-- <scroll-view scroll-x="true" class="scroll-view"> -->
  25. <view :class="['prize_ul_li', 'twobox', 'flex', 'tag-' + tagFun(item)]" v-for="(item, index) in prizedata.prizeInfo" :key="index">
  26. <view class="left-top-tag">
  27. <image class="tag-img" :src="tagImgFun(item)" mode="aspectFit"></image>
  28. <text class="tag-text">{{ tagTextFun(item) }}</text>
  29. </view>
  30. <image class="two" :src="item.image" mode="widthFix"></image>
  31. <view class="a">{{ item.goods_name }}</view>
  32. <view class="price">¥{{ item.coin_price }}</view>
  33. </view>
  34. <!-- </scroll-view> -->
  35. </view>
  36. <view class="prize_footer" :class="'prize_footer-' + mode" v-if="type == 0">
  37. <!-- 立即收下 -->
  38. <view class="btn btn-1" @click="$emit('accept')">立即收下</view>
  39. <!-- 一键回收 -->
  40. <view class="btn btn-0" @click="recycle()">一键回收</view>
  41. </view>
  42. <view class="shiwan center" v-else>试玩结果仅供展示哦~</view>
  43. </view>
  44. </view>
  45. <view v-show="!hide" class="loading-mask" @click="showAnimation">
  46. <view :class="['animation-wrapper', explode && 'explode']">
  47. <view :animation="boxAnimation"><image :src="boxImg" mode="heightFix" class="box"></image></view>
  48. <image src="https://www.chaomangdao.com/image/result/halo.png" mode="heightFix" class="halo"></image>
  49. </view>
  50. <view class="shouzhi" v-if="!isopen"><image src="https://www.chaomangdao.com/image/ss.gif" mode=""></image></view>
  51. </view>
  52. <audio id="result-audio" src="https://www.chaomangdao.com/image/result/1.mp3"></audio>
  53. </view>
  54. </uni-popup>
  55. </template>
  56. <script>
  57. export default {
  58. name: 'show-result',
  59. props: {
  60. //数量
  61. num: Number,
  62. /**
  63. * 类型 0:正式开盒 1:试玩
  64. */
  65. type: {
  66. type: Number,
  67. default: 0
  68. }
  69. },
  70. data() {
  71. return {
  72. //奖品列表
  73. prizedata: [],
  74. //特效
  75. scale: false,
  76. //开盒动画
  77. openLoading: true,
  78. boxImg: 'https://www.chaomangdao.com/image/result/box.png',
  79. //动画
  80. boxAnimation: {},
  81. animationTime: 100,
  82. explode: false,
  83. hide: false,
  84. isopen: false
  85. };
  86. },
  87. computed: {
  88. //开盒模式 0:1抽 1:5抽 2:9抽
  89. mode() {
  90. switch (this.num) {
  91. case 5:
  92. return 1;
  93. case 9:
  94. return 2;
  95. }
  96. return 0;
  97. },
  98. //当前单抽商品
  99. currPrizedata() {
  100. if (!this.prizedata) {
  101. return null;
  102. }
  103. if (!this.prizedata.prizeInfo || this.prizedata.length < 1) {
  104. return null;
  105. }
  106. return this.prizedata.prizeInfo[0];
  107. },
  108. //单抽商品品质
  109. tag() {
  110. return this.tagFun(this.currPrizedata);
  111. },
  112. //单抽品质文本
  113. tagText() {
  114. return this.tagTextFun(this.currPrizedata);
  115. },
  116. //单抽品质角标
  117. tagImg() {
  118. return this.tagImgFun(this.currPrizedata);
  119. }
  120. },
  121. methods: {
  122. //盒子抖动
  123. shake: function(animation) {
  124. let time = 0;
  125. const duration = 90;
  126. for (var i = 0; i < 20; i++) {
  127. let rotate = -10;
  128. let scaleY = 1.1;
  129. if (i % 2 != 0) {
  130. rotate = 0;
  131. scaleY = 1;
  132. }
  133. animation
  134. .rotate(rotate)
  135. .scaleY(scaleY)
  136. .step({
  137. duration
  138. });
  139. time += duration;
  140. }
  141. return time;
  142. },
  143. //盒子压缩
  144. compress: function(animation) {
  145. const duration = 100;
  146. animation
  147. .translateY('5vh')
  148. .scaleY(0.9)
  149. .scaleX(1.2)
  150. .step({
  151. duration
  152. });
  153. return duration;
  154. },
  155. //盒子跳跃
  156. jump: function(animation) {
  157. const duration = 150;
  158. animation
  159. .translateY('-50vh')
  160. .scaleY(1.1)
  161. .scaleX(0.9)
  162. .step({
  163. duration
  164. });
  165. return duration;
  166. },
  167. open(prizedata) {
  168. prizedata.boxImg && (this.boxImg = prizedata.boxImg);
  169. //播放音乐
  170. // this.startAudio();
  171. //打开结果
  172. this.$refs.prize.open();
  173. //加载动画
  174. this.prizedata = prizedata;
  175. // this.$nextTick(() => {
  176. // this.showAnimation();
  177. // });
  178. },
  179. //播放音乐
  180. startAudio() {
  181. setTimeout(() => {
  182. let audio = document.getElementById('result-audio').querySelector('audio');
  183. audio.play();
  184. });
  185. },
  186. showAnimation() {
  187. this.isopen = true;
  188. let animation = uni.createAnimation();
  189. this.animationTime += this.shake(animation);
  190. this.animationTime += this.compress(animation);
  191. this.animationTime += this.jump(animation);
  192. this.animation = animation;
  193. this.boxAnimation = animation.export();
  194. console.log(this.animationTime, '动画时长');
  195. setTimeout(() => {
  196. this.explode = true;
  197. this.hide = true;
  198. // this.hideAnimation();
  199. if (this.tag != 'normal') {
  200. //开启震动
  201. try {
  202. uni.vibrateShort({
  203. success: function() {
  204. console.log('震动');
  205. }
  206. });
  207. } catch (e) {
  208. console.log(e);
  209. }
  210. //开启效果
  211. // this.scale = true
  212. // setTimeout(() => {
  213. // this.scale = false
  214. // }, 1000)
  215. }
  216. }, this.animationTime);
  217. },
  218. hideAnimation() {
  219. setTimeout(() => {
  220. this.hide = true;
  221. }, 1300);
  222. },
  223. //关闭
  224. close() {
  225. this.animationTime = 0;
  226. this.explode = false;
  227. this.hide = false;
  228. this.isopen = false;
  229. this.$emit('close');
  230. this.$refs.prize.close();
  231. },
  232. //商品品质
  233. tagFun(prizeInfo) {
  234. if (!prizeInfo) return null;
  235. return prizeInfo.tag;
  236. },
  237. //品质文本
  238. tagTextFun(prizeInfo) {
  239. if (!prizeInfo) return null;
  240. if (prizeInfo.tag == 'normal') {
  241. return '普通';
  242. }
  243. if (prizeInfo.tag == 'rare') {
  244. return '稀有';
  245. }
  246. if (prizeInfo.tag == 'supreme') {
  247. return '史诗';
  248. }
  249. if (prizeInfo.tag == 'legend') {
  250. return '传说';
  251. }
  252. },
  253. //品质角标
  254. tagImgFun(prizeInfo) {
  255. if (!prizeInfo) return null;
  256. if (prizeInfo.tag == 'normal') {
  257. return 'https://www.chaomangdao.com/image/tag-1.png';
  258. }
  259. if (prizeInfo.tag == 'rare') {
  260. return 'https://www.chaomangdao.com/image/tag-2.png';
  261. }
  262. if (prizeInfo.tag == 'supreme') {
  263. return 'https://www.chaomangdao.com/image/tag-3.png';
  264. }
  265. if (prizeInfo.tag == 'legend') {
  266. return 'https://www.chaomangdao.com/image/tag-4.png';
  267. }
  268. },
  269. recycle() {
  270. this.$refs.prize.close();
  271. uni.showModal({
  272. cancelText: '取消',
  273. confirmText: '确认',
  274. title: '一键回收',
  275. content: '是否确认一键回收?',
  276. success: res => {
  277. if (res.confirm) {
  278. this.$emit('recycle', this.prizedata);
  279. }
  280. }
  281. });
  282. }
  283. },
  284. created() {
  285. // let animation = uni.createAnimation();
  286. // this.animationTime = 0;
  287. // this.animationTime += shake(animation);
  288. // this.animationTime += compress(animation);
  289. // this.animationTime += jump(animation);
  290. // this.animation = animation;
  291. },
  292. destroyed() {
  293. console.log(111);
  294. }
  295. };
  296. </script>
  297. <style lang="scss">
  298. .onebox {
  299. height: 372rpx;
  300. width: 352rpx;
  301. border-radius: 26rpx;
  302. background-color: #fff;
  303. }
  304. .twobox {
  305. width: 176rpx;
  306. border-radius: 13rpx;
  307. background-color: #fff;
  308. }
  309. .result-popup-main {
  310. z-index: 9999;
  311. .result-popup {
  312. background-image: url('https://www.chaomangdao.com/image/kjbg.jpg');
  313. position: fixed;
  314. bottom: 0;
  315. left: 0;
  316. background-repeat: no-repeat;
  317. background-size: 100% 100%;
  318. }
  319. }
  320. .prize {
  321. transform: scale(0);
  322. opacity: 0;
  323. transition: 0.2s;
  324. width: 750rpx;
  325. height: 100vh;
  326. display: flex;
  327. justify-content: center;
  328. &.show {
  329. transform: scale(1);
  330. opacity: 1;
  331. }
  332. .prize_box {
  333. width: 100%;
  334. height: 1120rpx;
  335. position: relative;
  336. flex-direction: column;
  337. // background: url(static/image/result/guang@2x.png) no-repeat;
  338. background-size: 100% auto;
  339. background-position: top;
  340. background-repeat: no-repeat;
  341. .prize_close {
  342. width: 64rpx;
  343. height: 64rpx;
  344. top: 280rpx;
  345. right: 30rpx;
  346. position: absolute;
  347. z-index: 999999;
  348. }
  349. .prize-top {
  350. width: 528rpx;
  351. height: 270rpx;
  352. position: absolute;
  353. top: 120rpx;
  354. left: 118rpx;
  355. &-2 {
  356. top: 40rpx;
  357. }
  358. }
  359. .prize_footer {
  360. width: 100%;
  361. &-2 {
  362. bottom: -200rpx;
  363. }
  364. .btn {
  365. height: 84rpx;
  366. border-radius: 16rpx;
  367. position: absolute;
  368. }
  369. .btn-1 {
  370. bottom: 0rpx;
  371. background-image: -webkit-linear-gradient(0deg, #89f7fe 0%, #66a6ff 100%);
  372. font-size: 38rpx;
  373. text-align: center;
  374. line-height: 86rpx;
  375. width: 159px;
  376. border-radius: 8px;
  377. position: absolute;
  378. left: 40rpx;
  379. color: #ffffff;
  380. font-weight: bold;
  381. }
  382. .btn-0 {
  383. bottom: 0rpx;
  384. background-image: -webkit-linear-gradient(60deg, #ffc8de 0%, #ff67a4 100%);
  385. font-size: 38rpx;
  386. text-align: center;
  387. line-height: 86rpx;
  388. right: 40rpx;
  389. width: 159px;
  390. color: #ffffff;
  391. font-weight: bold;
  392. }
  393. }
  394. }
  395. .shiwan {
  396. background: url(https://www.chaomangdao.com/image/open/tanchuangbeijing@2x.png) no-repeat;
  397. background-size: cover;
  398. }
  399. .prize_ul {
  400. width: 566rpx;
  401. // padding: 0 92rpx;
  402. display: flex;
  403. flex-wrap: wrap;
  404. justify-content: space-between;
  405. position: absolute;
  406. top: 336rpx;
  407. left: 92rpx;
  408. &-2 {
  409. top: 360rpx;
  410. }
  411. &::after {
  412. content: '';
  413. width: 176rpx;
  414. }
  415. }
  416. // .scroll-view {
  417. // width: 522rpx;
  418. // white-space:nowrap;
  419. .prize_ul_li {
  420. margin-bottom: 16rpx;
  421. position: relative;
  422. width: 176rpx;
  423. display: flex;
  424. flex-direction: column;
  425. align-items: center;
  426. justify-content: center;
  427. display: flex;
  428. padding: 8rpx;
  429. // margin-right: 20rpx;
  430. box-sizing: border-box;
  431. .two {
  432. width: 176rpx;
  433. height: 176rpx;
  434. }
  435. .a {
  436. font-size: 24rpx;
  437. // font-family: PingFangSC-Medium, PingFang SC;
  438. font-weight: 500;
  439. color: #171a20;
  440. width: 146rpx;
  441. overflow: hidden;
  442. white-space: nowrap;
  443. text-overflow: ellipsis;
  444. }
  445. .price {
  446. margin-top: 6rpx;
  447. font-size: 24rpx;
  448. font-weight: 500;
  449. color: #171a20;
  450. }
  451. .left-top-tag {
  452. position: absolute;
  453. top: 0;
  454. left: 0;
  455. z-index: 9999999;
  456. width: 3rem;
  457. height: 3rem;
  458. .tag-img {
  459. width: 100%;
  460. height: 100%;
  461. }
  462. .tag-text {
  463. font-size: 0.6rem !important;
  464. position: absolute;
  465. position: absolute;
  466. top: 30%;
  467. left: 30%;
  468. color: #fff !important;
  469. width: auto !important;
  470. transform: translateX(-50%) translateY(-50%) rotate(-45deg);
  471. }
  472. }
  473. }
  474. // }
  475. .prize_shop {
  476. transition: 1s;
  477. position: absolute;
  478. top: 336rpx;
  479. left: 198rpx;
  480. display: flex;
  481. flex-direction: column;
  482. .spining {
  483. z-index: -1;
  484. height: 150vh;
  485. width: 150vh;
  486. background-image: url(https://www.chaomangdao.com/image/result/spining.png);
  487. background-repeat: no-repeat;
  488. background-size: 100% 100%;
  489. position: absolute;
  490. }
  491. image {
  492. width: 174rpx;
  493. height: 235rpx;
  494. margin-bottom: 20rpx;
  495. }
  496. text {
  497. width: 70%;
  498. font-size: 16rpx;
  499. font-family: PingFangSC-Medium, PingFang SC;
  500. font-weight: 500;
  501. color: #171a20;
  502. overflow: hidden;
  503. white-space: nowrap;
  504. text-overflow: ellipsis;
  505. text-align: center;
  506. }
  507. .colorblack {
  508. font-size: 32rpx !important;
  509. font-family: PingFangSC-Medium, PingFang SC;
  510. font-weight: 500;
  511. color: #171a20;
  512. }
  513. .left-top-tag {
  514. position: absolute;
  515. top: -2rpx;
  516. left: -2rpx;
  517. z-index: 9999999;
  518. width: 5rem;
  519. height: 5rem;
  520. .tag-img {
  521. width: 100%;
  522. height: 100%;
  523. }
  524. .tag-text {
  525. font-size: 1rem;
  526. position: absolute;
  527. top: 30%;
  528. left: 30%;
  529. color: #fff !important;
  530. width: auto !important;
  531. transform: translateX(-50%) translateY(-50%) rotate(-45deg);
  532. }
  533. }
  534. }
  535. .tag-normal {
  536. box-shadow: 0 0 40rpx 18rpx #9d85ff;
  537. }
  538. .tag-rare {
  539. box-shadow: 0 0 40rpx 18rpx #47a8ff;
  540. }
  541. .tag-supreme {
  542. box-shadow: 0 0 40rpx 32rpx #feb337;
  543. }
  544. .tag-legend {
  545. box-shadow: 0 0 40rpx 32rpx #fe615e;
  546. }
  547. .shiwan {
  548. width: 399rpx;
  549. height: 48rpx;
  550. color: #ffffff;
  551. font-size: 30rpx;
  552. margin-top: 40rpx;
  553. background: #000000;
  554. border-radius: 27rpx 27rpx 27rpx 27rpx;
  555. }
  556. }
  557. // .left-top-tag {
  558. // z-index: 999999;
  559. // position: absolute;
  560. // left: -2px;
  561. // top: -3px;
  562. // .tag-img {
  563. // height: 100% !important;
  564. // width: 100% !important;
  565. // }
  566. // .tag-text {
  567. // position: absolute;
  568. // top: 30%;
  569. // left: 30%;
  570. // color: #fff !important;
  571. // width: auto !important;
  572. // transform: translateX(-50%) translateY(-50%) rotate(-45deg);
  573. // }
  574. // }
  575. .prize_shop_scale {
  576. transform: scale(1.3);
  577. }
  578. .loading-mask {
  579. z-index: 999;
  580. position: fixed;
  581. top: -180rpx;
  582. left: 0;
  583. height: 100vh;
  584. width: 100vw;
  585. display: flex;
  586. align-items: flex-end;
  587. justify-content: center;
  588. .shouzhi {
  589. position: absolute;
  590. bottom: 100rpx;
  591. width: 400rpx;
  592. height: 400rpx;
  593. }
  594. .animation-wrapper {
  595. margin-bottom: 10vh;
  596. image {
  597. height: 360rpx;
  598. }
  599. .halo {
  600. opacity: 1;
  601. transform: scale(0);
  602. position: absolute;
  603. top: 0;
  604. }
  605. &.explode {
  606. .box {
  607. transition: 0.3s;
  608. opacity: 0;
  609. transform: scale(0);
  610. }
  611. .halo {
  612. transition: 1.2s;
  613. opacity: 0;
  614. transform: scale(5);
  615. }
  616. }
  617. }
  618. }
  619. @keyframes rotate {
  620. from {
  621. transform: rotate(0deg);
  622. }
  623. to {
  624. transform: rotate(360deg);
  625. }
  626. }
  627. .spining {
  628. transition: 0.3s;
  629. animation: rotate 10s linear infinite;
  630. /*开始动画后无限循环,用来控制rotate*/
  631. }
  632. </style>