show-result.vue 12 KB

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