Feat:抽奖2.0(中奖名单缺中奖等级,优惠券领取接口异常)

This commit is contained in:
LinCyJang
2026-04-29 00:52:34 +08:00
parent a14d89efff
commit 092ef55293
8 changed files with 662 additions and 405 deletions
+191 -67
View File
@@ -75,11 +75,23 @@
<view class="empty-text">{{ loading ? '加载中...' : '暂无抽奖码记录' }}</view>
</view>
</scroll-view>
<view class="coupon-popup-mask" v-if="showCouponSuccessPopup" @click="closeCouponSuccessPopup">
<view class="coupon-popup" @click.stop>
<view class="popup-close" @click="closeCouponSuccessPopup">×</view>
<view class="popup-icon-wrap">
<text class="popup-icon">🎉</text>
</view>
<view class="popup-title">领取成功</view>
<view class="popup-desc">您的奖品已经领取成功,请前往“我的优惠券”查看详情</view>
<view class="popup-btn" @click="goMyCoupons">去查看我的优惠券</view>
</view>
</view>
</view>
</template>
<script>
// import { getDrawMyTickets } from '@/api/lottery'
import { claimCoupon, getDrawMyTickets } from '@/api/lottery'
export default {
name: 'CountyMyTicketsPage',
@@ -88,7 +100,7 @@ export default {
statusBarHeight: 20,
loading: false,
activeTab: 'all',
activityId: 1,
activityId: 0,
tabs: [
{ key: 'all', label: '全部' },
{ key: 'wait', label: '待开奖' },
@@ -96,7 +108,9 @@ export default {
{ key: 'invalid', label: '已失效' }
],
list: [],
openedList: []
openedList: [],
showCouponSuccessPopup: false,
claiming: false
}
},
computed: {
@@ -109,7 +123,7 @@ export default {
},
onLoad(options) {
if (options && options.activityId) {
this.activityId = Number(options.activityId) || 1
this.activityId = Number(options.activityId) || 0
}
},
onShow() {
@@ -124,6 +138,46 @@ export default {
}
return map[tab]
},
normalizeListData(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 []
},
normalizeTicketItem(item = {}) {
const statusNum = Number(item.status)
const claimStatusNum = Number(item.claimStatus)
return {
...item,
id: item.id || item.lotteryRecordId || item.ticketId || item.recordId || '',
ticketCode: item.ticketCode || item.code || '',
status: Number.isNaN(statusNum) ? -999 : statusNum,
claimStatus: Number.isNaN(claimStatusNum) ? 0 : claimStatusNum,
sourceOrderId: item.sourceOrderId || item.orderId || item.orderNo || '',
drawTime: item.drawTime || item.openTime || '',
prizeName: item.prizeName || item.awardName || '',
prizeType: item.prizeType || item.awardType || '',
prizeTypeName: item.prizeTypeName || item.awardTypeName || ''
}
},
filterByActivity(list = []) {
if (!this.activityId) return list
return list.filter(item => Number(item.activityId || item.drawActivityId || 0) === this.activityId)
},
filterByTab(list = []) {
if (this.activeTab === 'wait') {
return list.filter(item => item.status === 0)
}
if (this.activeTab === 'opened') {
return list.filter(item => item.status === 1 || item.status === 2)
}
if (this.activeTab === 'invalid') {
return list.filter(item => item.status === -1)
}
return list
},
onChangeTab(tab) {
if (this.activeTab === tab) return
this.activeTab = tab
@@ -134,69 +188,24 @@ export default {
url: `/pkg-video/views/county-winners?activityId=${this.activityId}`
})
},
fetchList() {
async fetchList() {
this.loading = true
// 使用模拟数据以匹配设计图所有状态
setTimeout(() => {
const mockData = [
{
id: 1,
ticketCode: 'A8F92E',
status: 0,
sourceOrderId: '12345678910',
drawTime: '2026-05-30 10:00:00',
},
{
id: 2,
ticketCode: 'A8F92E',
status: 1,
claimStatus: 0,
sourceOrderId: '12345678910',
drawTime: '2026-05-30 10:00:00',
prizeName: '一等奖ipone17 pro max手机'
},
{
id: 3,
ticketCode: 'A8F92E',
status: 1,
claimStatus: 1,
sourceOrderId: '12345678910',
drawTime: '2026-05-30 10:00:00',
prizeName: '一等奖ipone17 pro max手机'
},
{
id: 4,
ticketCode: 'A8F92E',
status: -1,
claimStatus: 0,
sourceOrderId: '12345678910',
drawTime: '2026-05-30 10:00:00',
},
{
id: 5,
ticketCode: 'A8F92E',
status: -1,
claimStatus: -1,
sourceOrderId: '12345678910',
drawTime: '2026-05-30 10:00:00',
prizeName: '一等奖ipone17 pro max手机'
}
];
let filteredData = mockData;
if (this.activeTab === 'wait') {
filteredData = mockData.filter(item => item.status === 0);
} else if (this.activeTab === 'opened') {
filteredData = mockData.filter(item => item.status === 1 || item.status === 2);
} else if (this.activeTab === 'invalid') {
filteredData = mockData.filter(item => item.status === -1);
}
this.list = filteredData;
this.openedList = mockData.filter(item => item.status === 1 || item.status === 2);
this.loading = false;
}, 300);
try {
const status = this.mapTabToStatus(this.activeTab)
const res = await getDrawMyTickets(status)
const allList = this.filterByActivity(this.normalizeListData(res).map(this.normalizeTicketItem))
this.openedList = allList.filter(item => item.status === 1 || item.status === 2)
this.list = this.filterByTab(allList)
} catch (e) {
this.list = []
this.openedList = []
uni.showToast({
title: '抽奖码加载失败',
icon: 'none'
})
} finally {
this.loading = false
}
},
getStatusText(item) {
const status = Number(item.status)
@@ -213,6 +222,13 @@ export default {
if (Number(item.claimStatus) === -1) return '奖品过期未领取'
return '订单取消'
},
isCouponPrize(item = {}) {
const prizeType = String(item.prizeType || '').toLowerCase()
const prizeTypeName = String(item.prizeTypeName || '')
const prizeName = String(item.prizeName || '')
if (prizeType === 'coupon' || prizeType === '3') return true
return /券/.test(prizeTypeName) || /券/.test(prizeName)
},
formatDrawTime(time) {
if (!time) return '--'
const date = new Date(String(time).replace(/-/g, '/'))
@@ -224,8 +240,27 @@ export default {
const mm = String(date.getMinutes()).padStart(2, '0')
return `${y}年${m}月${d}日 ${hh}:${mm}`
},
onClaim(item) {
async onClaim(item) {
if (!item.id) return
if (this.claiming) return
if (this.isCouponPrize(item)) {
this.claiming = true
uni.showLoading({ title: '领取中...' })
try {
await claimCoupon(Number(item.id))
this.showCouponSuccessPopup = true
this.fetchList()
} catch (e) {
uni.showToast({
title: (e && e.msg) || (e && e.message) || '领取失败',
icon: 'none'
})
} finally {
uni.hideLoading()
this.claiming = false
}
return
}
const query = [
`lotteryRecordId=${item.id}`,
`ticketCode=${encodeURIComponent(item.ticketCode || '')}`,
@@ -237,6 +272,15 @@ export default {
url: `/pkg-video/views/county-claim-address?${query}`
})
},
closeCouponSuccessPopup() {
this.showCouponSuccessPopup = false
},
goMyCoupons() {
this.showCouponSuccessPopup = false
uni.navigateTo({
url: '/pkg_user/views/myCoupons'
})
},
goOrder(item) {
if (!item.sourceOrderId) {
uni.showToast({
@@ -554,4 +598,84 @@ export default {
color: #999;
font-size: 28rpx;
}
.coupon-popup-mask {
position: fixed;
inset: 0;
z-index: 1000;
background: rgba(0, 0, 0, 0.55);
display: flex;
align-items: center;
justify-content: center;
padding: 24rpx;
}
.coupon-popup {
width: 100%;
max-width: 620rpx;
background: #fff;
border-radius: 32rpx;
padding: 26rpx 34rpx 42rpx;
position: relative;
}
.popup-close {
position: absolute;
right: 18rpx;
top: 18rpx;
width: 40rpx;
height: 40rpx;
border-radius: 50%;
border: 2rpx solid #333;
font-size: 40rpx;
font-weight: 700;
color: #333;
line-height: 40rpx;
text-align: center;
}
.popup-icon-wrap {
width: 112rpx;
height: 112rpx;
margin: 20rpx auto 8rpx;
border-radius: 8rpx;
display: flex;
align-items: center;
justify-content: center;
}
.popup-icon {
font-size: 70rpx;
}
.popup-title {
text-align: center;
font-size: 60rpx;
font-weight: 900;
color: #222;
margin-top: 12rpx;
}
.popup-desc {
margin: 38rpx auto 42rpx;
text-align: center;
font-size: 28rpx;
line-height: 1.6;
color: #9a9a9a;
width: 92%;
}
.popup-btn {
width: 86%;
height: 96rpx;
margin: 0 auto;
border-radius: 48rpx;
background: #c43124;
color: #fff;
font-size: 40rpx;
font-weight: 900;
text-align: center;
line-height: 96rpx;
letter-spacing: 2rpx;
}
</style>