Feat:抽奖2.0(中奖名单缺中奖等级,优惠券领取接口异常)
This commit is contained in:
@@ -10,14 +10,14 @@
|
||||
</view>
|
||||
|
||||
<view class="content-wrap" v-if="loaded">
|
||||
<view class="draw-info-wrap" :style="{ backgroundImage: `url(${webUrl}/zhongjiang5.png)` }">
|
||||
<view v-if="!showHistory" class="draw-info-wrap" :style="{ backgroundImage: `url(${webUrl}/zhongjiang5.png)` }">
|
||||
<view class="period-side left">
|
||||
<text class="side-text">第</text>
|
||||
<text class="side-text">{{ periodLabel }}</text>
|
||||
<text class="side-text">期</text>
|
||||
<text class="side-text v12-font-36">第</text>
|
||||
<text class="side-text v12-font-36">{{ periodLabel }}</text>
|
||||
<text class="side-text v12-font-36">期</text>
|
||||
</view>
|
||||
<view class="period-side right">
|
||||
<view class="side-text side-text-count">
|
||||
<view class="side-text side-text-count v12-font-26" @click="handleShowHistory">
|
||||
<text>往</text>
|
||||
<text>期</text>
|
||||
<text>中</text>
|
||||
@@ -26,12 +26,33 @@
|
||||
<text>单</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="draw-main">
|
||||
<view class="draw-title">本期已开奖</view>
|
||||
<view class="draw-time">开奖时间:{{ drawTime }}</view>
|
||||
</view>
|
||||
</view>
|
||||
<view v-else class="draw-info-wrap" style="padding: 0" :style="{ backgroundImage: `url(${webUrl}/zhongjiang01.png)` }">
|
||||
<view
|
||||
class="history-nav-btn left"
|
||||
:class="{ disabled: !canSwitchPrev }"
|
||||
@click="handleSwitchHistory('prev')"
|
||||
>
|
||||
</view>
|
||||
<view
|
||||
class="history-nav-btn right"
|
||||
:class="{ disabled: !canSwitchNext }"
|
||||
@click="handleSwitchHistory('next')"
|
||||
>
|
||||
</view>
|
||||
<view class="top-wrap">
|
||||
<view class="v12-font-bold v12-font-40">
|
||||
第{{ periodLabel }}期
|
||||
</view>
|
||||
</view>
|
||||
<view class="draw-main" style="padding: 0" >
|
||||
<view class="draw-time" style="margin-top: 60rpx">开奖时间:{{ drawTime }}</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="win-banner" v-if="hasWon === 1 && userWinList.length > 0" :style="{ backgroundImage: `url(${webUrl}/zhongjiangn.png)` }">
|
||||
<view class="win-banner-subtitle">
|
||||
您的抽奖码 <text class="code">{{ userWinList[0].ticketCode }}</text> 获得了
|
||||
@@ -98,9 +119,21 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { getDrawActivityInfo, getActivityWinRecord, getDrawMyTickets } from '@/api/lottery'
|
||||
import { getDrawActivityInfo, getActivityWinRecord, getDrawMyTickets, getDrawHistoryActivities } from '@/api/lottery'
|
||||
|
||||
export default {
|
||||
computed: {
|
||||
currentHistoryIndex() {
|
||||
if (!this.historyList.length) return -1
|
||||
return this.historyList.findIndex(item => Number(item.id) === Number(this.activityId))
|
||||
},
|
||||
canSwitchPrev() {
|
||||
return this.currentHistoryIndex > -1 && this.currentHistoryIndex < this.historyList.length - 1
|
||||
},
|
||||
canSwitchNext() {
|
||||
return this.currentHistoryIndex > 0
|
||||
}
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
webUrl: this.$VUE_APP_RESOURCES_URL,
|
||||
@@ -111,8 +144,11 @@ export default {
|
||||
hasWon: 0,
|
||||
userWinList: [],
|
||||
activityWinnerList: [],
|
||||
historyActivities: [],
|
||||
loaded: false,
|
||||
showCouponSuccessPopup: false
|
||||
showCouponSuccessPopup: false,
|
||||
showHistory: false,
|
||||
historyList: []
|
||||
}
|
||||
},
|
||||
onLoad(options) {
|
||||
@@ -122,6 +158,48 @@ export default {
|
||||
this.fetchData()
|
||||
},
|
||||
methods: {
|
||||
async handleShowHistory() {
|
||||
uni.showLoading({
|
||||
mask: true
|
||||
})
|
||||
const historyRes = await getDrawHistoryActivities()
|
||||
const {data, success} = historyRes || {}
|
||||
uni.hideLoading()
|
||||
if(!success) return
|
||||
this.historyList = (data || [])
|
||||
.map(item => ({
|
||||
id: Number(item.id || item.activityId || item.drawActivityId || 0),
|
||||
periodNo: item.periodNo || '',
|
||||
drawTime: item.drawTime || ''
|
||||
}))
|
||||
.filter(item => item.id > 0)
|
||||
.sort((a, b) => this.getPeriodNoValue(b.periodNo) - this.getPeriodNoValue(a.periodNo))
|
||||
this.showHistory = true
|
||||
},
|
||||
async handleSwitchHistory(direction) {
|
||||
if (!this.historyList.length) {
|
||||
uni.showToast({
|
||||
title: "暂无可切换历史期",
|
||||
icon: "none"
|
||||
})
|
||||
return
|
||||
}
|
||||
const currentIndex = this.currentHistoryIndex
|
||||
if (currentIndex < 0) {
|
||||
uni.showToast({
|
||||
title: "当前期数不在历史列表中",
|
||||
icon: "none"
|
||||
})
|
||||
return
|
||||
}
|
||||
const targetIndex = direction === 'prev' ? currentIndex + 1 : currentIndex - 1
|
||||
if (targetIndex < 0 || targetIndex >= this.historyList.length) return
|
||||
const target = this.historyList[targetIndex]
|
||||
if (!target || Number(target.id) === Number(this.activityId)) return
|
||||
this.activityId = Number(target.id)
|
||||
this.loaded = false
|
||||
await this.fetchData()
|
||||
},
|
||||
goBack() {
|
||||
uni.navigateBack()
|
||||
},
|
||||
@@ -133,18 +211,17 @@ export default {
|
||||
handleClaimNow() {
|
||||
if (!this.userWinList.length) return
|
||||
|
||||
if (this.userWinList.length > 1) {
|
||||
this.navToMyTickets()
|
||||
return
|
||||
}
|
||||
|
||||
const allCouponPrize = this.userWinList.every((item) => this.isCouponPrize(item))
|
||||
if (allCouponPrize) {
|
||||
this.showCouponSuccessPopup = true
|
||||
return
|
||||
}
|
||||
|
||||
if (this.userWinList.length === 1) {
|
||||
this.navToReceiveInfo(this.userWinList[0])
|
||||
return
|
||||
}
|
||||
|
||||
this.navToMyTickets()
|
||||
this.navToReceiveInfo(this.userWinList[0])
|
||||
},
|
||||
isCouponPrize(prize = {}) {
|
||||
const prizeType = Number(prize.prizeType)
|
||||
@@ -174,6 +251,20 @@ export default {
|
||||
if (Array.isArray(res.list)) return res.list
|
||||
return []
|
||||
},
|
||||
normalizeHistoryListData(res) {
|
||||
if (!res) return []
|
||||
if (Array.isArray(res)) return res
|
||||
if (Array.isArray(res.data)) return res.data
|
||||
if (Array.isArray(res.data && res.data.list)) return res.data.list
|
||||
if (Array.isArray(res.list)) return res.list
|
||||
return []
|
||||
},
|
||||
getPeriodNoValue(periodNo) {
|
||||
const text = String(periodNo || '')
|
||||
const match = text.match(/\d+/g)
|
||||
if (!match || !match.length) return 0
|
||||
return Number(match.join('')) || 0
|
||||
},
|
||||
formatDrawTime(time) {
|
||||
if (!time) return "--"
|
||||
const date = new Date(String(time).replace(/-/g, "/"))
|
||||
@@ -183,18 +274,6 @@ export default {
|
||||
const d = String(date.getDate()).padStart(2, "0")
|
||||
return `${y}年${m}月${d}日`
|
||||
},
|
||||
parsePeriodLabel(info = {}, winners = []) {
|
||||
const periodText = String(info.periodNo || info.currentPeriodNo || info.periodLabel || "")
|
||||
if (periodText) {
|
||||
const match = periodText.match(/\d+/)
|
||||
if (match && match[0]) return match[0].padStart(2, "0")
|
||||
}
|
||||
const firstWinner = winners[0] || {}
|
||||
const winnerPeriod = String(firstWinner.periodNo || "")
|
||||
const winnerMatch = winnerPeriod.match(/\d+/)
|
||||
if (winnerMatch && winnerMatch[0]) return winnerMatch[0].padStart(2, "0")
|
||||
return "01"
|
||||
},
|
||||
mapUserWinList(ticketList = []) {
|
||||
return ticketList.map(item => ({
|
||||
levelName: item.levelName || item.prizeLevelName || "中奖奖品",
|
||||
@@ -213,7 +292,7 @@ export default {
|
||||
getDrawMyTickets(1)
|
||||
])
|
||||
const activityData = (activityRes && activityRes.data) || {}
|
||||
const winnerList = this.normalizeListData(winnerRes)
|
||||
const winnerList = winnerRes.data.activityWinnerList || []
|
||||
const myTicketList = this.normalizeListData(myTicketsRes)
|
||||
|
||||
const filteredMyTicketList = this.activityId
|
||||
@@ -224,7 +303,7 @@ export default {
|
||||
this.activityWinnerList = winnerList
|
||||
this.userWinList = this.mapUserWinList(filteredMyTicketList)
|
||||
this.hasWon = this.userWinList.length > 0 ? 1 : 0
|
||||
this.periodLabel = this.parsePeriodLabel(activityData, winnerList)
|
||||
this.periodLabel = winnerRes.data.periodNo || "01"
|
||||
} catch (e) {
|
||||
uni.showToast({
|
||||
title: "中奖数据加载失败",
|
||||
@@ -725,4 +804,38 @@ export default {
|
||||
line-height: 96rpx;
|
||||
letter-spacing: 2rpx;
|
||||
}
|
||||
.top-wrap{
|
||||
position: absolute;
|
||||
top: 6px;
|
||||
left: 0;
|
||||
right: 0;
|
||||
margin: auto;
|
||||
width: fit-content;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.history-nav-btn {
|
||||
width: 52rpx;
|
||||
height: 52rpx;
|
||||
position: absolute;
|
||||
top: 16rpx;
|
||||
border-radius: 50%;
|
||||
color: #333;
|
||||
font-size: 44rpx;
|
||||
line-height: 48rpx;
|
||||
text-align: center;
|
||||
font-weight: 700;
|
||||
|
||||
&.left {
|
||||
left: 240rpx;
|
||||
}
|
||||
|
||||
&.right {
|
||||
right: 240rpx;
|
||||
}
|
||||
|
||||
&.disabled {
|
||||
opacity: 0.4;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user