index.vue 23 KB

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