index.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715
  1. <template>
  2. <view class="app-layout">
  3. <app-layout :haveBackground="false">
  4. <view class="pond">
  5. <view class="pond-head"
  6. :style="{'background-image': `url(${ setting.bg_pic})`}">
  7. <view class="p-b" @click="rules">规则</view>
  8. <view class="p-b" @click="share">分享</view>
  9. <app-share-qr-code-poster v-model="shareShow" :url="poster" title="生成海报"></app-share-qr-code-poster>
  10. </view>
  11. <view class="pond-oppty">
  12. <view>您还有
  13. <text>{{ oppty }}</text>
  14. 次抽奖机会
  15. </view>
  16. </view>
  17. <view class="pond-box"
  18. :style="{height: 'calc(100vh - 480rpx - ' + `${bottomHeight}` + 'rpx)',
  19. background: 'linear-gradient(' + setting.bg_color +', '+ (setting.bg_color_type === 'gradient' ? setting.bg_gradient_color: setting.bg_color) + ')'}">
  20. <view class="container-out">
  21. <view
  22. :style="{top: v.topCircle, left: v.leftCircle, background: i%2 === 0 ? colorCircleFirst : colorCircleSecond}"
  23. class="container-circle" v-for="(v,i) in circleList" :key="i"></view>
  24. <view class="container-in">
  25. <view
  26. :style="{top: v.topAward, left: v.leftAward, background: i == indexSelect ? colorAwardSelect : colorAwardDefault}"
  27. class="content-out" v-for="(v,i) in awardList" :key="i">
  28. <image class="img" :src="v.image_url" mode="aspectFit" load-lazy></image>
  29. <view class="name">{{ v.name }}</view>
  30. </view>
  31. <view class="start-btn" @click="startGame">
  32. <image class="pond-start1" src="./../image/pond-button.png" load-lazy></image>
  33. <block v-if="setting.deplete_integral_num > 0">
  34. <view class="pond-start2" :animation="animationData">
  35. <image src="./../image/pond-register.png" load-lazy></image>
  36. </view>
  37. <view class="main-center pond-register">
  38. <view :animation="animationData">
  39. -{{ setting.deplete_integral_num }}积分
  40. </view>
  41. </view>
  42. </block>
  43. <image v-else class="pond-start3" src="./../image/pond-start.png"
  44. :animation="animationData" load-lazy></image>
  45. </view>
  46. </view>
  47. </view>
  48. <view class="dir-left-nowrap main-center cross-center end">
  49. <view @click="home" class="dir-left-nowrap cross-center box-grow-0 left">
  50. <icon class="end-icon home"></icon>
  51. <view>回到首页</view>
  52. </view>
  53. <view @click="prize" class="dir-left-nowrap cross-center box-grow-0">
  54. <view>我的中奖记录</view>
  55. <icon class="end-icon price"></icon>
  56. </view>
  57. </view>
  58. </view>
  59. </view>
  60. <!-- 活动弹窗 -->
  61. <view v-if="status==2">
  62. <view class="act-modal">
  63. <view class="act-modal-bg"></view>
  64. <view class="act-modal-pic cross-center main-center">
  65. <view class="act-modal-info success">
  66. <icon class="image-bg" :style="{'background-image': `url(${appImg.pond_success})`}">></icon>
  67. <view @click="closeActModal">
  68. <icon class="image-close"></icon>
  69. </view>
  70. <view class="main-center">
  71. <text class="text">恭喜\n抽中{{ name }}</text>
  72. </view>
  73. <view class="main-center">
  74. <view class="box main-center">
  75. <app-button @click="closeActModal" color="#FFFFFF" background="#FF4544"
  76. font-size="32"
  77. height="80" width="480"
  78. round>继续抽奖
  79. </app-button>
  80. </view>
  81. </view>
  82. </view>
  83. </view>
  84. </view>
  85. </view>
  86. <view v-if="status==1">
  87. <view class="act-modal show">
  88. <view class="act-modal-bg"></view>
  89. <view class="act-modal-pic cross-center main-center">
  90. <view class="act-modal-info error">
  91. <icon class="image-bg" :style="{'background-image': `url(${appImg.pond_empty})`}">></icon>
  92. <view @click="closeActModal">
  93. <icon class="image-close"></icon>
  94. </view>
  95. <view class="main-center">
  96. <text class="text">谢谢参与\n再换个姿势抽奖</text>
  97. </view>
  98. <view class="main-center">
  99. <view class="box main-center">
  100. <app-button @click="closeActModal" color="#FFFFFF" background="#FF4544"
  101. font-size="32"
  102. height="80" width="480"
  103. round>继续抽奖
  104. </app-button>
  105. </view>
  106. </view>
  107. </view>
  108. </view>
  109. </view>
  110. </view>
  111. </app-layout>
  112. </view>
  113. </template>
  114. <script>
  115. import appShareQrCodePoster from '../../../components/page-component/app-share-qr-code-poster/app-share-qr-code-poster';
  116. import {mapGetters, mapState} from 'vuex';
  117. export default {
  118. name: "index",
  119. components: {appShareQrCodePoster},
  120. computed: {
  121. ...mapState({
  122. tabBarNavs: state => state.mallConfig.navbar.navs,
  123. appImg: state => state.mallConfig.plugin.pond.app_image,
  124. userInfo: state => state.user.info,
  125. }),
  126. ...mapGetters('iPhoneX', {
  127. BotHeight: 'getBotHeight',
  128. getEmpty: 'getEmpty',
  129. }),
  130. bottomHeight() {
  131. let s = this.tabBarNavs.find(item => {
  132. let currentRoute = '/plugins/pond/index/index';
  133. if (currentRoute.includes(item.url.split('?')[0])) {
  134. return true;
  135. }
  136. return false;
  137. })
  138. if (s) {
  139. return this.BotHeight;
  140. } else {
  141. return 0;
  142. }
  143. },
  144. },
  145. data() {
  146. let bout, btn, animation;
  147. return {
  148. bout,
  149. btn,
  150. animation,
  151. circleList: [], //圆点数组
  152. awardList: [], //奖品数组
  153. colorCircleFirst: '#F12416', //圆点颜色1
  154. colorCircleSecond: '#FFFFFF', //圆点颜色2
  155. colorAwardDefault: '#F5F0FC', //奖品默认颜色
  156. colorAwardSelect: '#FFE400', //奖品选中颜色
  157. indexSelect: 0, //被选中的奖品index
  158. prizeIndex: 0, //奖品index
  159. isRunning: false, //是否正在抽奖,
  160. animationData: {},
  161. status: 0,
  162. setting: null,
  163. oppty: 0,
  164. msg: '', //提示文字
  165. name: '',//奖品名称
  166. //海报参数
  167. poster: this.$api.pond.poster,
  168. shareShow: false,
  169. }
  170. },
  171. onShow: function () {
  172. const self = this;
  173. self.$showLoading({title: '加载中'});
  174. self.$request({
  175. url: this.$api.pond.index,
  176. }).then(info => {
  177. self.$hideLoading();
  178. if (!info.data) {
  179. uni.showToast({title: info.msg, icon: 'none'});
  180. return;
  181. }
  182. self.oppty = info.data.oppty;
  183. self.msg = info.msg;
  184. self.setting = info.data.setting;
  185. let list = info.data.list;
  186. let topAward = 18;
  187. let leftAward = 18;
  188. for (let j = 0; j < 8; j++) {
  189. if (j === 0) {
  190. topAward = 18;
  191. leftAward = 18;
  192. } else if (j < 3) {
  193. leftAward = leftAward + 196 + 8;
  194. } else if (j < 5) {
  195. topAward = topAward + 158 + 8;
  196. } else if (j < 7) {
  197. leftAward = leftAward - 196 - 8;
  198. } else if (j < 8) {
  199. topAward = topAward - 158 - 8;
  200. }
  201. list[j].topAward = topAward + 'rpx';
  202. list[j].leftAward = leftAward + 'rpx';
  203. }
  204. self.awardList = list;
  205. //动画
  206. self.boutAnimation();
  207. self.btnAnimation();
  208. }).catch(e => {
  209. self.$hideLoading();
  210. })
  211. },
  212. onShareAppMessage: function () {
  213. return this.$shareAppMessage({
  214. title: this.$children[0].navigationBarTitle,
  215. path: '/plugins/pond/index/index',
  216. params: {}
  217. });
  218. },
  219. onHide: function () {
  220. clearInterval(this.bout);
  221. clearInterval(this.btn);
  222. },
  223. methods: {
  224. home() {
  225. uni.redirectTo({url: `/pages/index/index`});
  226. },
  227. prize() {
  228. uni.navigateTo({url: `/plugins/pond/prize/prize`});
  229. },
  230. rules() {
  231. uni.navigateTo({
  232. url: `/pages/rules/index?url=${encodeURIComponent(this.$api.pond.setting)}&keys=${JSON.stringify(['setting', 'rule'])}`,
  233. });
  234. },
  235. share() {
  236. this.shareShow = true;
  237. },
  238. //开始抽奖
  239. startGame: function () {
  240. const self = this;
  241. if (self.isRunning) return
  242. if (self.msg) {
  243. uni.showToast({title: self.msg, icon: 'none'});
  244. self.isRunning = false;
  245. return;
  246. }
  247. clearInterval(self.btn);
  248. self.animation.translate(0, 0).step();
  249. self.animationData = self.animation.export();
  250. self.isRunning = true;
  251. self.prizeIndex = 0;
  252. //循环
  253. let i = 0;
  254. let indexSelect = self.indexSelect;
  255. let list = self.awardList;
  256. let timer = setInterval(() => {
  257. i += 30;
  258. indexSelect++;
  259. indexSelect = indexSelect % 8;
  260. self.indexSelect = indexSelect;
  261. if (self.prizeIndex > 0 && indexSelect + 1 == self.prizeIndex) {
  262. clearInterval(timer);
  263. self.btnAnimation();
  264. self.isRunning = false;
  265. self.name = list[indexSelect].name;
  266. self.status = list[indexSelect].type == 5 ? 1 : 2;
  267. }
  268. }, (200 + i))
  269. self.$request({
  270. url: self.$api.pond.lottery,
  271. }).then(info => {
  272. if (info.code === 0) {
  273. list.map((item, index, array) => {
  274. if (item.id == info.data.id) {
  275. setTimeout(() => {
  276. self.prizeIndex = index + 1;
  277. self.oppty = info.data.oppty;
  278. self.msg = info.msg;
  279. }, 2000)
  280. }
  281. });
  282. return;
  283. }
  284. clearInterval(timer);
  285. uni.showToast({title: info.msg, icon: 'none'});
  286. self.isRunning = false;
  287. self.btnAnimation();
  288. }).catch(info => {
  289. clearInterval(timer);
  290. self.isRunning = false;
  291. self.btnAnimation();
  292. })
  293. },
  294. //圆点设置
  295. boutAnimation: function () {
  296. const self = this;
  297. let leftCircle = 4;
  298. let topCircle = 4;
  299. let circleList = [];
  300. for (let i = 0; i < 24; i++) {
  301. if (i === 0) {
  302. topCircle = 8;
  303. leftCircle = 8;
  304. } else if (i < 6) {
  305. topCircle = 4;
  306. leftCircle = leftCircle + 110;
  307. } else if (i === 6) {
  308. topCircle = 8
  309. leftCircle = 660;
  310. } else if (i < 12) {
  311. topCircle = topCircle + 92;
  312. leftCircle = 663;
  313. } else if (i === 12) {
  314. topCircle = 545;
  315. leftCircle = 660;
  316. } else if (i < 18) {
  317. topCircle = 550;
  318. leftCircle = leftCircle - 110;
  319. } else if (i === 18) {
  320. topCircle = 545;
  321. leftCircle = 10;
  322. } else if (i < 24) {
  323. topCircle = topCircle - 92;
  324. leftCircle = 5;
  325. } else {
  326. return
  327. }
  328. circleList.push({topCircle: topCircle + 'rpx', leftCircle: leftCircle + 'rpx'});
  329. }
  330. self.circleList = circleList;
  331. //圆点闪烁
  332. self.bout = setInterval(() => {
  333. const temp = self.colorCircleFirst;
  334. self.colorCircleFirst = self.colorCircleSecond;
  335. self.colorCircleSecond = temp;
  336. }, 900)
  337. },
  338. btnAnimation: function () {
  339. const self = this;
  340. let animation = uni.createAnimation({
  341. duration: 500,
  342. timingFunction: "step-start",
  343. delay: 0,
  344. transformOrigin: "50% 50%",
  345. });
  346. self.animation = animation;
  347. let sentinel = true;
  348. self.btn = setInterval(() => {
  349. if (sentinel) {
  350. animation.translate(0, 0).step();
  351. sentinel = false;
  352. } else {
  353. animation.translate(0, -3).step();
  354. sentinel = true;
  355. }
  356. self.animationData = animation.export();
  357. }, 900)
  358. },
  359. closeActModal() {
  360. this.status = 0;
  361. },
  362. }
  363. }
  364. </script>
  365. <style scoped lang="scss">
  366. .app-layout {
  367. min-height: calc(100vh - var(--window-top));
  368. height: calc(100vh - var(--window-top));
  369. }
  370. .app-layout /deep/ .app-layout {
  371. min-height: calc(100vh - var(--window-top));
  372. height: calc(100vh - var(--window-top));
  373. }
  374. .pond {
  375. text-align: center;
  376. .pond-box {
  377. min-height: #{700rpx};
  378. padding-top: #{20rpx};
  379. }
  380. .pond-head {
  381. height: #{480rpx};
  382. width: #{100%};
  383. background-repeat: no-repeat;
  384. background-size: 100% 100%;
  385. .p-b {
  386. color: #FFFFFF;
  387. font-size: $uni-font-size-weak-one;
  388. background: #000000;
  389. text-align: center;
  390. background-color: rgba(0, 0, 0, 0.4);
  391. line-height: #{48rpx};
  392. width: #{92rpx};
  393. border-radius: #{24rpx} 0 0 #{24rpx};
  394. position: absolute;
  395. right: 0;
  396. top: #{40rpx};
  397. }
  398. .p-b:nth-child(2) {
  399. top: #{112rpx}
  400. }
  401. }
  402. .pond-oppty {
  403. line-height: #{56rpx};
  404. font-size: #{28rpx};
  405. position: absolute;
  406. text-align: center;
  407. width: 100vw;
  408. top: #{450rpx};
  409. view {
  410. color: #ffffff;
  411. padding: 0 #{30rpx};
  412. display: inline-block;
  413. background: rgba(0, 0, 0, 0.3);
  414. border-radius: #{28rpx};
  415. }
  416. text {
  417. color: #ffb92a;
  418. }
  419. }
  420. /**小圆球 **/
  421. .container-out {
  422. height: #{566rpx};
  423. width: #{680rpx};
  424. background-color: #F47915;
  425. margin: #{32rpx} auto #{30rpx} auto;
  426. border-radius: #{16rpx};
  427. position: relative;
  428. }
  429. .container-in {
  430. width: #{640rpx};
  431. height: #{526rpx};
  432. background-color: #f12416;
  433. border-radius: #{20rpx};
  434. position: absolute;
  435. left: 0;
  436. right: 0;
  437. top: 0;
  438. bottom: 0;
  439. margin: auto;
  440. }
  441. .container-circle {
  442. position: absolute;
  443. display: block;
  444. border-radius: 50%;
  445. height: #{15rpx};
  446. width: #{15rpx};
  447. }
  448. .content-out {
  449. position: absolute;
  450. height: #{144rpx};
  451. width: #{196rpx};
  452. background-color: #f5f0fc;
  453. border-radius: #{16rpx};
  454. box-shadow: 0 #{16rpx} 0 #FFCEC0;
  455. .img {
  456. position: absolute;
  457. top: #{12rpx};
  458. left: 50%;
  459. margin-left: #{-75rpx};
  460. width: #{150rpx};
  461. height: #{80rpx};
  462. z-index: 1;
  463. }
  464. .name {
  465. position: absolute;
  466. bottom: 0;
  467. top: #{24rpx + 80rpx};;
  468. color: #c62015;
  469. font-size: #{24rpx};
  470. width: #{196rpx};
  471. word-break: break-all;
  472. text-overflow: ellipsis;
  473. display: -webkit-box;
  474. -webkit-box-orient: vertical;
  475. -webkit-line-clamp: 1;
  476. overflow: hidden;
  477. line-height: 1.5;
  478. }
  479. }
  480. /****/
  481. .pond-start1 {
  482. height: #{160rpx};
  483. width: 100%;
  484. }
  485. .pond-start2 {
  486. display: inline;
  487. position: absolute;
  488. left: #{10rpx};
  489. height: #{136rpx};
  490. width: #{178rpx};
  491. }
  492. .pond-start2 image {
  493. height: 100%;
  494. width: 100%;
  495. }
  496. .pond-start3 {
  497. position: absolute;
  498. left: #{10rpx};
  499. height: #{136rpx};
  500. width: #{178rpx};
  501. }
  502. .pond-register {
  503. position: absolute;
  504. top: #{84rpx};
  505. width: 100%;
  506. view {
  507. font-size: #{26rpx};
  508. padding: 0 #{16rpx};
  509. border-radius: #{16rpx};
  510. line-height: #{32rpx};
  511. background: #fff4ba;
  512. }
  513. }
  514. .start-btn {
  515. position: absolute;
  516. margin: auto;
  517. top: 0;
  518. left: 0;
  519. bottom: 0;
  520. right: 0;
  521. border-radius: #{16rpx};
  522. height: #{159rpx};
  523. width: #{196rpx};
  524. color: #f6251e;
  525. text-align: center;
  526. font-weight: bolder;
  527. line-height: #{154rpx};
  528. }
  529. .end {
  530. color: #FFFFFF;
  531. font-size: #{28rpx};
  532. .left {
  533. margin-right: #{160rpx};
  534. }
  535. .end-icon {
  536. background-repeat: no-repeat;
  537. background-size: 100% 100%;
  538. margin: 0 #{16rpx};
  539. }
  540. .end-icon.home {
  541. height: #{30rpx};
  542. width: #{30rpx};
  543. background-image: url('../../../static/image/icon/icon-home-white.png');
  544. }
  545. .end-icon.price {
  546. height: #{22rpx};
  547. width: #{12rpx};
  548. background-image: url('../../../static/image/icon/arrow-right-white.png');
  549. }
  550. }
  551. }
  552. .act-modal {
  553. position: fixed;
  554. left: 0;
  555. top: 0;
  556. width: 100%;
  557. height: 100%;
  558. z-index: 2001;
  559. transition: 200ms;
  560. .show {
  561. visibility: visible;
  562. opacity: 1;
  563. }
  564. .act-modal-bg {
  565. background: rgba(0, 0, 0, 0.5);
  566. position: fixed;
  567. left: 0;
  568. top: 0;
  569. width: 100%;
  570. height: 100%;
  571. z-index: 1;
  572. }
  573. .act-modal-pic {
  574. background: rgba(0, 0, 0, 0.25);
  575. position: fixed;
  576. left: 0;
  577. top: 0;
  578. width: 100%;
  579. height: 100%;
  580. z-index: 1;
  581. }
  582. .act-modal-info {
  583. text-align: center;
  584. position: relative;
  585. }
  586. .success {
  587. top: #{0rpx};
  588. width: 100%;
  589. .image-bg {
  590. height: #{462rpx};
  591. width: 100%;
  592. display: block;
  593. background-repeat: no-repeat;
  594. background-size: 100% 100%;
  595. }
  596. .image-close {
  597. position: absolute;
  598. right: #{80rpx};
  599. top: 0;
  600. height: #{30rpx};
  601. width: #{30rpx};
  602. background-repeat: no-repeat;
  603. background-size: 100% 100%;
  604. background-image: url('../../../static/image/icon/close.png');
  605. }
  606. .text, .box {
  607. width: #{591rpx};
  608. background: #ffffff;
  609. color: #353535;
  610. }
  611. .box {
  612. border-radius: 0 0 #{16rpx} #{16rpx};
  613. text-align: center;
  614. padding: #{64rpx} 0;
  615. }
  616. }
  617. .error {
  618. top: #{0rpx};
  619. width: 100%;
  620. .image-bg {
  621. height: #{240rpx};
  622. width: 100%;
  623. display: block;
  624. background-repeat: no-repeat;
  625. background-size: 100% 100%;
  626. }
  627. .image-close {
  628. position: absolute;
  629. right: #{80rpx};
  630. top: 0;
  631. height: #{30rpx};
  632. width: #{30rpx};
  633. background-repeat: no-repeat;
  634. background-size: 100% 100%;
  635. background-image: url('../../../static/image/icon/close.png');
  636. }
  637. .text, .box {
  638. width: #{591rpx};
  639. background: #ffffff;
  640. color: #353535;
  641. }
  642. .box {
  643. border-radius: 0 0 #{16rpx} #{16rpx};
  644. text-align: center;
  645. padding: #{64rpx} 0;
  646. }
  647. }
  648. }
  649. </style>