Files
frontend-app/pages/other_package/turntable/turntable.vue
T
2026-09-15 14:14:09 +08:00

345 lines
8.8 KiB
Vue

<template>
<view class="turntable_warp">
<view class="turntable_header_warp">
<view class="header_title_warp">
<view style="width:100rpx;height:100rpx;display: flex;align-items: center;" @click="jumpMine">
<up-image src="/static/common/left_b.png" width="22" height="22" bgColor="#f1f6ff00"></up-image>
</view>
<view class="title_">{{ prizesObj.title || '幸运转盘百亿补贴' }}</view>
<qiaobao-assistant page-key="pages/other_package/turntable/turntable" title="抽奖活动" />
</view>
<view class="turntable_content_warp">
<view class="frequency_warp">
<!-- 抽奖转盘 -->
<view class="content">
<view class="lottery">
<dengbo-lotteryWheel :prizes="prizes" :size="626" :duration="5000" @run="startClick(1)"
@done="Done" ref="luckyWheel" :lightImgs="lightImages" customStyle="borderRadius: 50%;"
:styleOpt="styleOpt">
<template v-slot:bg>
<image src="https://static.tbmall.xin/static/turntable.png"
style="width: 100%; height: 100%;" />
</template>
<template v-slot:pointer>
<image src="https://static.tbmall.xin/static/zz.png"
style="width: 50px; height: 50px;" mode="widthFix" @click="startClick(1)" />
</template>
</dengbo-lotteryWheel>
</view>
<view class="draws_number">
还剩 {{ prizesObj.times || 0 }} 次抽奖
</view>
</view>
<!-- 抽奖次数 -->
<view class="draws_warp">
<view :class="prizesObj.times < 1 ? 'draws_item_warp draws_item_warp_no' : 'draws_item_warp'"
@click="startClick(1)">
抽1次
</view>
<view :class="prizesObj.times < 10 ? 'draws_item_warp draws_item_warp_no' : 'draws_item_warp'"
@click="startClick(10)">
抽10次</view>
<view :class="prizesObj.times < 20 ? 'draws_item_warp draws_item_warp_no' : 'draws_item_warp'"
@click="startClick(20)">
抽20次</view>
<view :class="prizesObj.times < 50 ? 'draws_item_warp draws_item_warp_no' : 'draws_item_warp'"
@click="startClick(50)">
抽50次</view>
</view>
</view>
</view>
<!-- 活动规则 -->
<view class="rule">
<view class="rule_title">
<view class="title">活动规则</view>
</view>
<view class="rule_content" v-html="prizesObj.ruleDescr"></view>
</view>
</view>
<!-- 中奖记录 -->
<view class="winning_record" @click="jumpWinningRecord">
<view style="margin-top: 10rpx;">
<up-image src="/pages/other_package/static/turntable/record.png" width="14" height="14"
bgColor="#f1f6ff00"></up-image>
</view>
<view style="margin-left: 10rpx;">中奖记录</view>
</view>
</view>
</template>
<script>
import { getActivityList, raffleExecute } from '@/api/raffle.js';
import dengboLotteryWheel from "@/pages/other_package/components/dengbo-lotteryWheel/components/dengbo-lotteryWheel/dengbo-lotteryWheel.vue";
export default {
components: {
dengboLotteryWheel,
},
data() {
return {
lightImages: ['https://static.tbmall.xin/static/bg_bs.png', 'https://static.tbmall.xin/static/bg_hs.png'],
prizesObj: {},
prizes: [],
lotteryList: [],// 中奖的列表ID
styleOpt: {
prizeBgColors: ['#fff0a3', '#fffce6', '#fdba64'],
},
isRun: false,// 是否正在抽奖
backPath: null,
}
},
onLoad(option) {
const backPath = option.backPath;
console.log("option backPath", backPath);
if (backPath && backPath !== 'null') {
this.backPath = backPath;
}
},
mounted() {
this.getActivityList();
},
methods: {
jumpMine() {
const backPath = this.backPath;
console.log("backPath", backPath);
if (backPath) {
uni.switchTab({
url: '/pages/home/home',
})
} else {
uni.switchTab({
url: '/pages/mine/mine',
})
}
},
// 查询活动详情
async getActivityList() {
const resp = await getActivityList();
if (resp && resp.bizcode === 100) {
this.prizesObj = resp.data;
this.prizes = resp.data.prizes || [];
if (this.prizes.length % 2 === 0) {
this.styleOpt.prizeBgColors = ['#fff0a3', '#fdba64'];
}
}
},
/**
* 跳转到中奖记录
*/
jumpWinningRecord() {
uni.navigateTo({
url: '/pages/mine_package/mine_winning_record/mine_winning_record',
})
},
// 用户点击开始,需要请求后台,去算出抽奖的选中的哪个
async startClick(num) {
if (this.isRun) {
return;
}
const count = this.prizesObj.times;// 当前拥有的抽奖次数
if (!count || count === 0) {
uni.showToast({
title: `您当前未获取到抽奖次数,快去获取吧~`,
icon: 'none'
});
return;
}
if (count < num) {
return;
}
this.isRun = true;
const params = {
id: this.prizesObj.id,
times: num,
}
const result = await raffleExecute(params);
let runCount = null;
if (result && result.bizcode === 100) {
const total = this.prizesObj.times;
const data = result.data;
this.lotteryList = data;// 中奖列表
this.prizesObj.times = total - num;// 减去次数
const prizes = this.prizes;
const lastData = data[data.length - 1];
for (let i = 0; i < prizes.length; i++) {
if (prizes[i].id === lastData.prizeId) {
runCount = i;
break;
}
}
}
if (!runCount && runCount !== 0) {
uni.showToast({
title: `系统异常【抱歉,抽奖失败】~`,
icon: 'none'
});
return;
}
this.$refs.luckyWheel.run(runCount);
},
//prize
Done() {
const lotteryList = this.lotteryList;
if (lotteryList && lotteryList.length !== 0) {
const data = lotteryList.map(item => item.prizeName);
uni.showToast({
title: `恭喜你获得【${data.join(',')}】`,
icon: 'none',
duration: lotteryList.length > 1 ? 4000 : 2000, // 持续时长,单位ms
});
} else {
uni.showToast({
title: `抱歉,抽奖失败`,
icon: 'none'
});
}
this.isRun = false;
},
}
}
</script>
<style lang="scss">
.turntable_warp {
height: 100vh;
}
.turntable_header_warp {
height: 1230rpx;
background-image: url("https://static.tbmall.xin/static/turntable_opt_1.png");
background-size: 100% 100%;
background-position: center;
/* 将图片居中显示 */
padding: 88rpx 0rpx 0;
.header_title_warp {
display: flex;
align-items: center;
padding: 0 30rpx;
.title_ {
font-weight: 800;
font-size: 67rpx;
color: #FBFAFA;
line-height: 120rpx;
text-shadow: 0rpx 10rpx 1rpx rgba(190, 10, 1, 0.45);
background: linear-gradient(0deg, #FBFAFA 0%, #FFE5D4 100%);
-webkit-background-clip: text;
letter-spacing: 2px;
width: calc(100% - 80rpx);
text-align: center;
}
}
.turntable_content_warp {
.frequency_warp {
margin-top: 224rpx;
background-image: url("https://static.tbmall.xin/static/turntable_opt_2.png");
background-size: 100% 100%;
background-position: center;
/* 将图片居中显示 */
width: 100%;
height: 844rpx;
position: relative;
}
.draws_warp {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
padding: 0 84rpx;
position: absolute;
top: 624rpx;
width: calc(100% - 168rpx);
.draws_item_warp {
width: 40%;
text-align: center;
background: #FE2F32;
border-radius: 16rpx;
border: 2px solid #FFC8C8;
margin-bottom: 20rpx;
color: #ffffff;
padding: 20rpx 0rpx;
}
.draws_item_warp_no {
color: #ff5464;
background: #ff7d7d;
border: 0px solid #FFC8C8;
}
}
}
.rule {
background: #FFFFFF;
border-radius: 50rpx 50rpx 0rpx 0rpx;
min-height: 500rpx;
padding: 30rpx;
.rule_title {
display: flex;
justify-content: center;
margin-bottom: 30rpx;
.title {
background: #FF2524;
border-radius: 30rpx 0rpx 40rpx 0rpx;
color: #FFFFFF;
padding: 10rpx 0;
width: 280rpx;
text-align: center;
font-size: 40rpx;
}
}
.rule_content {
font-weight: 400;
font-size: 28rpx;
color: #999999;
line-height: 38rpx;
}
}
}
.winning_record {
position: fixed;
right: 0rpx;
top: 224rpx;
background: rgba(92, 0, 1, 0.5);
border-radius: 30rpx 0rpx 0rpx 30rpx;
display: flex;
align-items: center;
color: #FFFFFF;
padding: 10rpx 20rpx;
font-weight: 500;
font-size: 25rpx;
color: #FBFAFA;
}
.content {
display: flex;
flex-direction: column;
align-items: center;
top: -292rpx;
position: relative;
}
.lottery {
position: relative;
display: inline-block;
width: 626rpx;
height: 626rpx;
margin-top: 100rpx;
}
.draws_number {
color: #FFFFFF;
margin-top: 136rpx;
}
</style>