123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312 |
- <template>
- <view class="app-container">
- <view class="nav" :style="{'padding-top': statusBarHeight + 'px'}">
- <uni-icons type="back" style="font-size: 48rpx" @click="close" />
- <text class="title">积分抽奖</text>
- </view>
- <!-- 每次消耗多少积分 -->
- <view class="every">{{lotteryConsumePoint}}积分/次</view>
- <!-- 转盘 -->
- <LuckyWheel class="lucky" ref="lucky" width="568rpx" height="568rpx" :prizes="prizes" :buttons="buttons"
- :defaultStyle="defaultStyle" @start="startCallBack" @end="endCallBack" />
- <!-- 剩余抽奖次数和积分 -->
- <view class="tips">
- <view>今日剩余抽奖机会:{{ hasLotteryCount }}</view>
- <view>可用积分:{{ maySignPoint }}</view>
- </view>
- <!-- 活动规则 -->
- <view class="rules">
- <view class="title">活动规则</view>
- <view v-for="(item, index) in rule" :key="index">{{ item }}</view>
- </view>
- <!-- 弹窗 -->
- <uni-popup ref="popup" type="center">
- <view v-if="this.hasLotteryCount <= 0" class="popup" style="justify-content: space-around">
- <view>
- <view>很遗憾!</view>
- <view>今日抽奖次数已用光</view>
- </view>
- <img src="../../static/lottery/noChance.png" />
- </view>
- <view v-else class="popup">
- <view>{{ form.resultGoodName }}</view>
- <img :src="form.resultGoodPic" />
- <button v-if="form.resultGoodType === 4" @click="getSubmit">领取</button>
- <button v-if="form.resultGoodType === 5" @click="getAgain">再抽一次</button>
- <button v-if="form.resultGoodType === 3" @click="getDetail">填写收货信息</button>
- </view>
- </uni-popup>
- </view>
- </template>
- <script>
- import { page, result, receive } from '@/api/lottery.js'
- import LuckyWheel from '@lucky-canvas/uni/lucky-wheel'
- export default {
- components: {
- LuckyWheel
- },
- data() {
- return {
- // 状态栏
- statusBarHeight: getApp().globalData.statusBarHeight,
- // 转盘
- prizes: [],
- buttons: [{
- radius: '45%',
- background: '#ffffff40',
- imgs: [{
- src: '../../static/lottery/btn.png',
- top: '-75px',
- width: '96px',
- height: '124px'
- }]
- }],
- defaultStyle: {
- fontSize: '26rpx'
- },
- // 可用积分
- maySignPoint: 0,
- // 每次消耗积分
- lotteryConsumePoint: 0,
- // 今日剩余抽奖机会
- hasLotteryCount: 0,
- // 活动规则
- rule: '',
- // 表单
- form: {},
- // 防止连点
- disabled: true
- }
- },
- onLoad() {
- this.getList()
- },
- methods: {
- // 获取页面信息
- getList() {
- this.prizes = []
- page(getApp().globalData.userInfo).then(res => {
- if (res.data.code === 0) {
- const j = res.data.data
- // 可用积分
- this.maySignPoint = j.maySignPoint
- // 每次消耗积分
- this.lotteryConsumePoint = j.lotteryConsumePoint
- // 今日剩余抽奖机会
- this.hasLotteryCount = j.hasLotteryCount
- // 奖品列表
- j.userLotteryDatas.map(i => {
- this.prizes.push({
- background: i.sort % 2 === 0 ? '#fff7a6' : '#9cc6a5',
- fonts: [{
- text: i.name,
- fontColor: i.sort % 2 === 0 ? '#ff8831' : '#fff',
- top: '10%'
- }],
- imgs: [{
- src: i.pic,
- top: '30%',
- width: '108rpx',
- height: '108rpx'
- }]
- })
- })
- // 活动规则
- this.rule = j.rule.split('\n')
- }
- })
- },
- close() {
- closePage.postMessage('关闭页面')
- },
- // 点击抽奖按钮触发回调
- startCallBack() {
- if (this.hasLotteryCount > 0) {
- if (this.maySignPoint >= this.lotteryConsumePoint) {
- if (this.disabled) {
- this.$refs.lucky.play()
- this.disabled = false
- result(getApp().globalData.userInfo).then(res => {
- if (res.data.code === 0) {
- setTimeout(() => {
- this.$refs.lucky.stop(res.data.data.resultGoodSort - 1)
- this.form = res.data.data
- }, 3000)
- } else {
- this.$refs.lucky.stop()
- uni.showToast({
- icon: 'error',
- title: res.data.message
- })
- }
- })
- }
- } else {
- uni.showToast({
- icon: 'error',
- title: '可用积分不足'
- })
- }
- } else {
- this.$refs.popup.open()
- }
- },
- // 抽奖结束触发回调
- endCallBack() {
- this.$nextTick(() => {
- this.$refs.popup.open()
- this.disabled = true
- this.getList()
- })
- },
- // 再抽一次
- getAgain() {
- this.$refs.popup.close()
- this.startCallBack()
- },
- // 领取
- getSubmit() {
- if (this.disabled) {
- this.disabled = false
- receive(getApp().globalData.userInfo, {
- prizeId: this.form.resultGoodId,
- lotteryCode: this.form.lotteryCode
- }).then(res => {
- if (res.data.code === 0) {
- this.$refs.popup.close()
- uni.showToast({
- title: '领取成功!'
- })
- this.getList()
- setTimeout(() => {
- this.disabled = true
- }, 2000)
- }
- })
- }
- },
- // 填写收货信息
- getDetail() {
- uni.redirectTo({
- url: `/pages/lottery/detail?prizeId=${this.form.resultGoodId}&lotteryCode=` + encodeURIComponent(this.form.lotteryCode)
- })
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .app-container {
- position: relative;
- background: url('@/static/lottery/bg.png');
- background-size: cover;
- background-repeat: no-repeat;
- width: 100%;
- height: 1880rpx;
- padding: 0 32rpx 32rpx;
- .nav {
- height: 88rpx;
- display: flex;
- align-items: center;
- color: #333333;
- font-weight: bold;
- font-size: 36rpx;
- position: relative;
- box-sizing: content-box;
- .title {
- position: absolute;
- left: 50%;
- transform: translate(-50%);
- }
- }
- .every {
- position: absolute;
- left: 50%;
- top: 380rpx;
- transform: translate(-50%);
- color: #1a5509;
- font-weight: bold;
- }
- .lucky {
- position: absolute;
- top: 496rpx;
- left: 50%;
- transform: translate(-50%);
- }
- .tips {
- position: absolute;
- top: 62%;
- left: 50%;
- transform: translate(-50%);
- text-align: center;
- line-height: 50rpx;
- }
- .rules {
- width: 100%;
- position: absolute;
- left: 0;
- bottom: 40rpx;
- color: #192b24;
- padding: 0 64rpx;
- font-size: 28rpx;
- font-weight: bold;
- .title {
- font-weight: bold;
- font-size: 38rpx;
- text-align: center;
- margin-bottom: 32rpx;
- }
- view {
- margin-bottom: 20rpx;
- }
- }
- .popup {
- width: 576rpx;
- height: 600rpx;
- background: #fff;
- border-radius: 32rpx;
- color: #000;
- font-weight: bold;
- text-align: center;
- padding: 48rpx 0;
- display: flex;
- flex-direction: column;
- justify-content: space-between;
- align-items: center;
- img {
- width: 328rpx;
- height: 236rpx;
- }
- button {
- background: linear-gradient(180deg, #72cdae 0%, #599f82 100%);
- color: #fff;
- width: 320rpx;
- height: 80rpx;
- line-height: 80rpx;
- border-radius: 50rpx;
- font-size: 32rpx;
- }
- }
- }
- </style>
|