抽奖增加领取

This commit is contained in:
2024-12-05 17:22:05 +08:00
parent 9156891770
commit bf17bb3a5d
3 changed files with 111 additions and 79 deletions

46
App.vue
View File

@@ -274,30 +274,32 @@
setInterval(d => { //定时器,定时去调取聊天未读消息
let userId = uni.getStorageSync('userId')
if (userId) {
this.$Request.getT('/app/message/selectMessageCount').then(res => {
if (res.code === 0) {
let num = res.data
uni.setStorageSync('numCount', num)
if (num == 0) {
uni.removeTabBarBadge({
index: 3
})
} else {
uni.setTabBarBadge({
index: 3,
text: num + ''
})
}
}
});
}
}, 3000);
// setInterval(d => { //定时器,定时去调取聊天未读消息
// let userId = uni.getStorageSync('userId')
// if (userId) {
// this.$Request.getT('/app/message/selectMessageCount').then(res => {
// if (res.code === 0) {
// let num = res.data
// uni.setStorageSync('numCount', num)
// if (num == 0) {
// uni.removeTabBarBadge({
// index: 3
// })
// } else {
// uni.setTabBarBadge({
// index: 3,
// text: num + ''
// })
// }
// }
// });
// }
// }, 3000);
//#ifdef H5
this.$u.get('/app/common/type/108').then(res => { //// 是否开启公众号自动登陆 108

View File

@@ -2,16 +2,10 @@
<view class="almost-lottery">
<!-- head -->
<view class="almost-lottery__head">
<!-- <view :class="['action', isApple && 'action-shadow']">
<text class="gold"></text>
<text class="content">红包余额<text class="num">{{ goldCoin }}</text></text>
</view> -->
<view class="btn-group u-flex u-row-between">
<view :class="['action', isApple && 'action-shadow']">
<text class="pack"></text>
<text class="content">红包余额<text class="num">{{ goldCoin }}</text></text>
<text class="content">红包<text class="num">{{ totalMoney }}</text></text>
</view>
<view :class="['action', isApple && 'action-shadow']" @click="toGift">
<text class="gift"></text>
@@ -96,9 +90,13 @@
},
data() {
return {
//红包余额
totalMoney:0,
//抽奖结果
result:'',
// 开启调试模式
isDev: true,
option:{},
option: {},
// 以下是转盘配置相关数据
lotteryConfig: {
// 抽奖转盘的整体尺寸单位rpx
@@ -221,6 +219,7 @@
ok: true,
data: res.data.records.map(v => {
return {
...v,
prizeId: v.id,
prizeName: v.name,
prizeStock: 10,
@@ -300,7 +299,7 @@
},
// 抽奖开始之前
async handleDrawBefore(callback) {
console.log('抽奖开始之前')
let flag = false
@@ -312,7 +311,7 @@
flag = false
uni.showModal({
title: '抽奖次数不足',
icon:'none'
icon: 'none'
})
}
@@ -411,62 +410,74 @@
// 远程请求接口获取中奖下标
// 大哥,这里只是模拟,别告诉我你不会对接自己的接口
async remoteGetPrizeIndex() {
this.result=''
console.warn('###当前处于模拟的请求接口,并返回了中奖信息###')
const res = await this.$Request.getT('app/discSpinning/draw', {
orderId: this.option.orderId
})
if (res.code == 0) {}
return
// 模拟请求接口获取中奖信息
let stoTimer = setTimeout(() => {
stoTimer = null
console.log(res);
if (res.code != 0) {
return uni.showToast({
title: res.msg
})
}
this.result=res.data
let list = [...this.prizeList]
let list = [...this.prizeList]
// 这里随机产生的 prizeId 是模拟后端返回的 prizeId
const arr=list.filter(v=>v.type==res.data.type)
let prizeId = arr[0].prizeId
// 这里随机产生的 prizeId 是模拟后端返回的 prizeId
let prizeId = Math.floor(Math.random() * list.length + 1)
// 拿到后端返回的 prizeId 后,开始循环比对得出那个中奖的数据
for (let i = 0; i < list.length; i++) {
let item = list[i]
if (item.prizeId === prizeId) {
// 中奖下标
this.prizeIndex = i
break
}
// 拿到后端返回的 prizeId 后,开始循环比对得出那个中奖的数据
for (let i = 0; i < list.length; i++) {
let item = list[i]
if (item.prizeId === prizeId) {
// 中奖下标
this.prizeIndex = i
break
}
console.log('本次抽中奖品 =>', this.prizeList[this.prizeIndex].prizeName)
// 如果奖品设有库存
if (this.onStock) {
console.log('本次奖品库存 =>', this.prizeList[this.prizeIndex].prizeStock)
}
}, 200)
}
console.log('本次抽中奖品 =>', this.prizeList[this.prizeIndex].prizeName)
},
// 本次抽奖结束
handleDrawEnd() {
console.log('旋转结束,执行拿到结果后到逻辑')
// 旋转结束后,开始处理拿到结果后的逻辑
let prizeName = this.prizeList[this.prizeIndex].prizeName
// const prize = this.prizeList[this.prizeIndex]
const prize = this.result
let {name} = prize
let tipContent = ''
if (prizeName === '谢谢参与') {
if (name.type ==1) {
tipContent = '很遗憾,没有中奖,请再接再厉!'
} else {
// 如果奖品设有库存
if (this.onStock) {
let prizeStock = this.prizeList[this.prizeIndex].prizeStock
tipContent = prizeStock ? `恭喜您,获得 ${prizeName}` : `很抱歉,您来晚了,当前奖品 ${prizeName} 已无库存`
} else {
tipContent = `恭喜您,获得 ${prizeName} `
}
tipContent = `恭喜您,获得 ${name}${this.result.type==2?(this.result.number+'元'):''} `
}
const _this=this;
uni.showModal({
content: tipContent,
showCancel: false,
success() {
const {
orderId,id
}=_this.result
_this.$Request.postJson('app/discSpinning/receive',_this.result).then(res=>{
_this.result=''
console.log(res)
if(res.code==0){
uni.showToast({
title: '领取成功',
icon:'none'
})
_this.getRedPack()
}else{
uni.showToast({
title: '领取失败',
icon:'none'
})
}
})
},
complete: () => {
this.prizeing = false
}
@@ -487,17 +498,24 @@
stoTimer = null
uni.hideLoading()
uni.showToast({
title: res.msg,
mask: true,
icon: 'none'
})
// uni.showToast({
// title: res.msg,
// mask: true,
// icon: 'none'
// })
}, 50)
},
async getRedPack(){
const res=await this.$Request.getT('app/moneyDetails/selectUserMoney')
if(res.code==0){
this.totalMoney=res.data.amount
}
}
},
onLoad(opt) {
this.option=opt
this.option = opt
this.prizeList = []
this.getRedPack()
this.getPrizeList()
},
onUnload() {

View File

@@ -4,7 +4,7 @@
<view class="gift-bg">
</view>
<view class="list">
<view class="item" v-for="(item,index) in 10" :key="index">
<view class="item" v-for="(item,index) in list" :key="index">
<view class="color-666 u-font-24">中奖时间 2024-09-11 10:20:11</view>
<view class="u-m-t-24 u-flex u-row-between">
<view class="u-flex-1 u-flex u-col-top">
@@ -20,10 +20,13 @@
</view>
</view>
</view>
<view class="u-p-t-30 u-p-b-30" v-if="hasAjax&&!list.length">
<u-empty text="暂无奖品"></u-empty>
</view>
</view>
<view class="u-p-30">
<u-loadmore :font-size="24" color="#999" :status="status" />
</view>
<!-- <view class="u-p-30">
<u-loadmore font-size="24" color="#999" :status="status" />
</view> -->
</view>
</template>
@@ -34,7 +37,9 @@
background: {
backgroundColor: 'transparent'
},
status: 'nomore'
status: 'nomore',
hasAjax:true,
list:[]
}
},
methods: {
@@ -42,7 +47,14 @@
uni.navigateTo({
url:'/me/gift/duihuan'
})
},
init(){
this.$Request.getT('app/discSpinningRecord/selectDiscSpinningRecord')
}
},
onShow() {
console.log('onShow');
this.init()
}
}
</script>