
<template>
<view class="index">
<image src="../../static/img/158.png" mode="" class="banner">image>
<view class="title">绿色积分加倍卡拿到手软view>
<almost-lottery
:lotteryBg="lotteryBg"
:actionBg="actionBg"
:colors="['#fff','#FFDFD4']"
:strFontColors="['#FF4100','#FF4100']"
:strMarginOutside="30"
:imgMarginStr="50"
:imgWidth="62"
:imgHeight="38"
:imgCircled="false"
:lottery-size="lotteryConfig.lotterySize"
:action-size="lotteryConfig.actionSize"
:ring-count="6"
:duration="4"
:self-rotaty="false"
:img-circled="true" :canvasCached="true" :prize-list="prizeList" :prize-index="prizeIndex"
@reset-index="prizeIndex = -1" @draw-before="handleDrawBefore" @draw-start="handleDrawStart"
@draw-end="handleDrawEnd" @finish="handleDrawFinish" v-if="prizeList.length" />
<u-button :ripple="true" class="btn" @click="submit" :loading="loading">立即抽奖({{freeNum}}次)u-button>
view>
template>
<script>
import AlmostLottery from '@/uni_modules/almost-lottery/components/almost-lottery/almost-lottery.vue'
import {
clearCacheFile,
clearStore
} from '@/uni_modules/almost-lottery/utils/almost-utils.js'
export default {
name: 'Home',
components: {
AlmostLottery
},
data() {
return {
isDev: false,
lotteryConfig: {
lotterySize: 600,
actionSize: 200
},
lotteryBg: require('../../static/img/156.png'),
actionBg: require('../../static/img/157.png'),
prizeList: [],
prizeIndex: -1,
prizeing: false,
freeNum: 0,
loading:false,
rules:[]
}
},
onLoad() {
this.prizeList = []
this.getPrizeList()
},
onShow() {
this.$http.get('/api/turntable/index').then(res=>{
if(res.code == 1){
this.freeNum = res.data.lottery_count;
this.rules = res.data.rules;
}
})
},
onUnload() {
uni.hideLoading()
},
methods: {
async getPrizeList() {
uni.showLoading({
title: '奖品准备中...'
})
this.$http.get('/api/turntable/prizes').then(res=>{
if(res.code == 1){
res.data.prizes.forEach(item=>{
if(item.multiple == 0){
this.prizeList.push({
prizeId: item.id,
prizeName: '谢谢参与',
prizeImage: item.image,
name:item.name
})
}else{
this.prizeList.push({
prizeId: item.id,
prizeName: item.name,
prizeImage: item.image,
name:item.name
})
}
})
}
})
},
handleDrawBefore(callback) {
if (this.freeNum > 0) {
this.handleDrawStart()
} else {
this.$toast('抽奖次数已用完')
}
},
handleDrawStart() {
console.log('触发抽奖按钮')
if (this.prizeing) return
this.prizeing = true
this.tryLotteryDraw()
},
tryLotteryDraw() {
this.$http.post('/api/turntable/lottery').then(res=>{
if(res.code == 1){
this.freeNum--
this.prizeList.forEach((item,index)=>{
if(item.prizeId == res.data.prize_id){
this.prizeIndex = index;
}
})
console.log('本次抽中奖品 =>', this.prizeList[this.prizeIndex].prizeName)
}
})
},
handleDrawEnd() {
console.log('旋转结束,执行拿到结果后到逻辑')
let prizeName = this.prizeList[this.prizeIndex].name
let tipContent = ''
if (prizeName === '谢谢参与') {
tipContent = '很遗憾,没有中奖,请再接再厉!'
} else {
tipContent = `恭喜您,获得 ${prizeName} !`
}
uni.showModal({
content: tipContent,
showCancel: false,
complete: () => {
this.prizeing = false
}
})
},
handleDrawFinish(res) {
console.log('抽奖转盘绘制完成', res)
if (res.ok) {
if (console.timeEnd) {
console.timeEnd('绘制转盘用时')
}
}
let stoTimer = setTimeout(() => {
stoTimer = null
uni.hideLoading()
uni.showToast({
title: res.msg,
mask: true,
icon: 'none'
})
}, 50)
},
submit(){
if (this.freeNum > 0) {
this.handleDrawStart()
} else {
this.$toast('抽奖次数已用完')
}
},
},
}
script>
<style lang="scss" scoped>
.index {
min-height: 100vh;
background: url('../../static/img/153.png')no-repeat left top #D8231C;
background-size:750rpx 1334rpx ;
.navRight{
width: 144rpx;
height: 46rpx;
background: rgba(0,0,0,0.1);
border-radius: 40rpx 0rpx 0rpx 40rpx;
padding-left: 20rpx;
display: flex;
align-items: center;
uni-text{
font-size: 24rpx;
color: #fff;
}
uni-image{
width: 10rpx;
height: 17rpx;
margin-left: 4rpx;
}
}
.banner{
display: block;
width: 586rpx;
height: 93rpx;
margin: 20rpx auto 40rpx;
}
.title{
text-align: center;
font-size: 48rpx;
font-weight: bold;
color: #fff;
margin-bottom: 20rpx;
}
.btn{
width: 596rpx;
height: 120rpx;
background: url('../../static/img/154.png')no-repeat center;
background-size: 596rpx 120rpx;
margin: 40rpx auto 35rpx;
font-size: 40rpx;
color: #BF3100;
font-weight: bold;
}
.tips{
padding: 30rpx 30rpx;
.til{
font-size: 28rpx;
color: #fff;
margin-bottom: 30rpx;
}
.text{
line-height: 1.6;
margin-bottom: 10rpx;
font-size: 26rpx;
color: #fff;
}
}
}
style>

- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
- 148
- 149
- 150
- 151
- 152
- 153
- 154
- 155
- 156
- 157
- 158
- 159
- 160
- 161
- 162
- 163
- 164
- 165
- 166
- 167
- 168
- 169
- 170
- 171
- 172
- 173
- 174
- 175
- 176
- 177
- 178
- 179
- 180
- 181
- 182
- 183
- 184
- 185
- 186
- 187
- 188
- 189
- 190
- 191
- 192
- 193
- 194
- 195
- 196
- 197
- 198
- 199
- 200
- 201
- 202
- 203
- 204
- 205
- 206
- 207
- 208
- 209
- 210
- 211
- 212
- 213
- 214
- 215
- 216
- 217
- 218
- 219
- 220
- 221
- 222
- 223
- 224
- 225
- 226
- 227
- 228
- 229
- 230
- 231
- 232
- 233
- 234
- 235
- 236
- 237
- 238
- 239
- 240
- 241
- 242
- 243
- 244
- 245
- 246
- 247
- 248
- 249
- 250