480 lines
12 KiB
Vue
480 lines
12 KiB
Vue
<template>
|
||
<view class="page">
|
||
<!-- 顶部公告区 -->
|
||
<view class="banner-area">
|
||
<!-- 返回按钮 -->
|
||
<view class="back-btn" @click="goBack">
|
||
<u-icon name="arrow-left" color="#333333" size="40"></u-icon>
|
||
<text class="back-text">返回</text>
|
||
</view>
|
||
<view class="banner-header">
|
||
<image class="banner-icon" src="https://aliyunoss.hn12301.net/hhrs/hhrs_zjgs.png" mode="aspectFit"></image>
|
||
<text class="banner-title">中奖名单公示</text>
|
||
</view>
|
||
<text class="banner-subtitle">总计 10,000份权益包,全程公证抽取</text>
|
||
<view class="stats-card">
|
||
<image class="stats-gift" src="https://aliyunoss.hn12301.net/hhrs/hhrs_xyckr.png" mode="aspectFit"></image>
|
||
<text class="stats-label">已产生</text>
|
||
<text class="stats-number">{{ totalWinners.toLocaleString() }}</text>
|
||
<text class="stats-label">名幸运持卡人</text>
|
||
</view>
|
||
</view>
|
||
|
||
<!-- 各期 Tab -->
|
||
<view class="tab-bar">
|
||
<view
|
||
class="tab-item"
|
||
:class="{ active: currentTab === index }"
|
||
v-for="(tab, index) in tabs"
|
||
:key="index"
|
||
@click="switchTab(index)"
|
||
>
|
||
<text class="tab-label">{{ tab.name }}</text>
|
||
<text class="tab-date">{{ tab.date }}</text>
|
||
<view class="tab-indicator" v-if="currentTab === index"></view>
|
||
</view>
|
||
</view>
|
||
|
||
<!-- 搜索栏 -->
|
||
<view class="search-area">
|
||
<view class="search-bar">
|
||
<u-icon name="search" color="#8e8e93" size="36"></u-icon>
|
||
<input class="search-input" v-model="keyword" placeholder="搜索姓名/身份证号" confirm-type="search" @confirm="onSearch" />
|
||
<view class="search-btn" @click="onSearch">搜索</view>
|
||
</view>
|
||
</view>
|
||
|
||
<!-- 中奖者表格 -->
|
||
<view class="table-area">
|
||
<template v-if="currentList.length > 0">
|
||
<view class="table-header">
|
||
<text class="table-col col-name">姓名</text>
|
||
<text class="table-col col-idcard">身份证</text>
|
||
</view>
|
||
<view class="table-row" v-for="(item, index) in currentList" :key="index">
|
||
<text class="table-col col-name">{{ item.memberName }}</text>
|
||
<text class="table-col col-idcard">{{ item.memberIdentityNo }}</text>
|
||
</view>
|
||
<!-- xuchao: 名单不足一页时隐藏加载更多 -->
|
||
<view class="loadmore-area" v-if="(totals[currentTab] || 0) > pageSize">
|
||
<u-loadmore :status="loadStatus" :loading-text="'加载中...'" :loadmore-text="'上拉加载更多'" :nomore-text="'没有更多了'" />
|
||
</view>
|
||
</template>
|
||
<!-- xuchao: 无名单时展示空态;全量拉取/首屏预取进行中显示查询态,避免"暂无数据"闪现 -->
|
||
<view class="loadmore-area" v-else-if="!datesLoaded || loadStatus === 'loading'">
|
||
<u-loadmore status="loading" loading-text="查询中..." />
|
||
</view>
|
||
<view class="empty-area" v-else>
|
||
<u-icon name="empty" size="60" color="#c8c8c8"></u-icon>
|
||
<text class="empty-text">暂无数据</text>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
</template>
|
||
|
||
<script>
|
||
export default {
|
||
data() {
|
||
return {
|
||
currentTab: 0,
|
||
tabs: [],
|
||
winnerData: {},
|
||
// xuchao: 页码改为按期维护(原单一 pageNo 在切期后会被沿用,导致同一页重复追加/跳页)
|
||
pageNos: {},
|
||
pageSize: 10,
|
||
totals: {},
|
||
// xuchao: 各期全量人数(无关键字),仅用于顶部"已产生"总数;搜索态不影响该统计
|
||
periodTotals: {},
|
||
// xuchao: 各期当前生效的查询关键字(loadMore 续拉用它,而非输入框实时值)
|
||
queryKeywords: {},
|
||
// xuchao: 各期请求序号,丢弃乱序返回的旧响应
|
||
reqSeqs: {},
|
||
totalWinners: 0,
|
||
inFlight: 0,
|
||
loadStatusMap: {},
|
||
// xuchao: 期次日期接口是否已回,首屏未回前显示查询态而非空态
|
||
datesLoaded: false,
|
||
keyword: ''
|
||
}
|
||
},
|
||
computed: {
|
||
// xuchao: 服务端已按关键字模糊过滤,前端直接渲染当期列表
|
||
currentList() {
|
||
return this.winnerData[this.currentTab] || []
|
||
},
|
||
// xuchao: 各期独立的加载状态,避免并行请求互相覆盖
|
||
loadStatus() {
|
||
return this.loadStatusMap[this.currentTab] || 'nomore'
|
||
}
|
||
},
|
||
watch: {
|
||
// xuchao: 关键字防抖 400ms 后走服务端模糊搜索(姓名/身份证任意片段)
|
||
keyword() {
|
||
clearTimeout(this._kwTimer)
|
||
this._kwTimer = setTimeout(() => this.search(), 400)
|
||
}
|
||
},
|
||
onLoad() {
|
||
this.loadDates()
|
||
},
|
||
onReachBottom() {
|
||
this.loadMore()
|
||
},
|
||
methods: {
|
||
loadDates() {
|
||
this.$u.api.getWinnerDates().then(res => {
|
||
this.datesLoaded = true
|
||
if (res.errcode === 0 && res.data) {
|
||
// xuchao: 后端按日期倒序返回,期次须按开奖日期正序(最早=第一期),否则二期会被标成"第1期"
|
||
const dates = res.data.slice().sort()
|
||
this.tabs = dates.map((date, index) => ({
|
||
name: `第${index + 1}期`,
|
||
date: date
|
||
}))
|
||
const data = {}
|
||
dates.forEach((date, index) => {
|
||
data[index] = []
|
||
})
|
||
this.winnerData = data
|
||
// xuchao: 预置各期 key,保证响应式
|
||
this.totals = {}
|
||
this.pageNos = {}
|
||
this.loadStatusMap = {}
|
||
this.periodTotals = {}
|
||
this.queryKeywords = {}
|
||
this.reqSeqs = {}
|
||
dates.forEach((date, index) => {
|
||
this.$set(this.totals, index, 0)
|
||
this.$set(this.pageNos, index, 1)
|
||
this.$set(this.loadStatusMap, index, 'loading')
|
||
this.$set(this.periodTotals, index, 0)
|
||
this.$set(this.queryKeywords, index, '')
|
||
this.$set(this.reqSeqs, index, 0)
|
||
})
|
||
// xuchao: 预取各期第一页(无关键字),汇总已产生总人数
|
||
this.tabs.forEach((tab, index) => {
|
||
this.loadTab(index, 1, '')
|
||
})
|
||
}
|
||
}).catch(() => { this.datesLoaded = true })
|
||
},
|
||
// xuchao: 拉取某期某页;keyword 走服务端 LIKE(姓名/身份证任意片段),空串=不过滤
|
||
loadTab(tabIndex, pageNo, keyword) {
|
||
if (!this.tabs[tabIndex]) return
|
||
const kw = keyword || ''
|
||
// xuchao: 递增序号,返回时仅最新请求生效,丢弃连续输入产生的乱序旧响应
|
||
const seq = (this.reqSeqs[tabIndex] || 0) + 1
|
||
this.$set(this.reqSeqs, tabIndex, seq)
|
||
this.inFlight++
|
||
this.$set(this.loadStatusMap, tabIndex, 'loading')
|
||
this.$u.api.getWinnerList({
|
||
pageNo: pageNo,
|
||
pageSize: this.pageSize,
|
||
drawDate: this.tabs[tabIndex].date,
|
||
keyword: kw
|
||
}).then(res => {
|
||
if (seq !== this.reqSeqs[tabIndex]) return
|
||
if (res.errcode === 0 && res.data) {
|
||
const list = res.data.list || []
|
||
const prev = pageNo > 1 ? (this.winnerData[tabIndex] || []) : []
|
||
this.$set(this.winnerData, tabIndex, prev.concat(list))
|
||
this.$set(this.pageNos, tabIndex, pageNo)
|
||
this.$set(this.queryKeywords, tabIndex, kw)
|
||
this.$set(this.totals, tabIndex, res.data.total || 0)
|
||
// xuchao: 顶部总数只累计"无关键字"的全量人数,搜索态不会让它缩水
|
||
if (!kw) {
|
||
this.$set(this.periodTotals, tabIndex, res.data.total || 0)
|
||
this.totalWinners = Object.values(this.periodTotals).reduce((s, n) => s + n, 0)
|
||
}
|
||
}
|
||
}).finally(() => {
|
||
this.inFlight--
|
||
if (seq !== this.reqSeqs[tabIndex]) return
|
||
const len = (this.winnerData[tabIndex] || []).length
|
||
const total = this.totals[tabIndex] || 0
|
||
this.$set(this.loadStatusMap, tabIndex, len === 0 || len >= total ? 'nomore' : 'loadmore')
|
||
})
|
||
},
|
||
// xuchao: 执行一次关键字搜索(当期回到第1页);输入防抖与点搜索按钮都走这里
|
||
search() {
|
||
this.loadTab(this.currentTab, 1, (this.keyword || '').trim())
|
||
},
|
||
loadMore() {
|
||
const tab = this.currentTab
|
||
const total = this.totals[tab] || 0
|
||
const len = (this.winnerData[tab] || []).length
|
||
if (len < total && this.inFlight === 0) {
|
||
this.loadTab(tab, (this.pageNos[tab] || 1) + 1, this.queryKeywords[tab] || '')
|
||
}
|
||
},
|
||
switchTab(index) {
|
||
this.currentTab = index
|
||
// xuchao: 关键字作用于"正在看的这期"——若输入关键字与该期已生效查询不同则重查,否则复用已加载结果
|
||
const kw = (this.keyword || '').trim()
|
||
if (kw !== (this.queryKeywords[index] || '')) {
|
||
this.loadTab(index, 1, kw)
|
||
} else {
|
||
const total = this.totals[index] || 0
|
||
const len = (this.winnerData[index] || []).length
|
||
this.$set(this.loadStatusMap, index, len === 0 || len >= total ? 'nomore' : 'loadmore')
|
||
}
|
||
},
|
||
goBack() {
|
||
// xuchao: 直接通过链接进入(无历史栈)时回到首页
|
||
const pages = getCurrentPages()
|
||
if (pages.length > 1) {
|
||
uni.navigateBack()
|
||
} else {
|
||
uni.reLaunch({ url: '/pages/index/index' })
|
||
}
|
||
},
|
||
onSearch() {
|
||
// xuchao: 点搜索/键盘确认 → 立即搜索,取消待执行的防抖
|
||
clearTimeout(this._kwTimer)
|
||
this.search()
|
||
}
|
||
}
|
||
}
|
||
</script>
|
||
<style>
|
||
page {
|
||
background-color: #f2f2f7;
|
||
}
|
||
</style>
|
||
<style scoped lang="less">
|
||
/* 返回按钮 */
|
||
.back-btn {
|
||
align-self: flex-start;
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 2px;
|
||
margin-top: 48px;
|
||
}
|
||
|
||
.back-text {
|
||
font-size: 14px;
|
||
color: #333333;
|
||
}
|
||
|
||
/* 顶部公告区 */
|
||
.banner-area {
|
||
background-color: #ffffff;
|
||
padding: 0 24px 24px;
|
||
margin-top: -24px;
|
||
display: flex;
|
||
flex-direction: column;
|
||
align-items: center;
|
||
gap: 17px;
|
||
}
|
||
|
||
.banner-header {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 4px;
|
||
margin-top: -12px;
|
||
}
|
||
|
||
.banner-icon {
|
||
width: 50px;
|
||
height: 50px;
|
||
}
|
||
|
||
.banner-title {
|
||
color: #C0301B;
|
||
font-weight: 700;
|
||
font-size: 32px;
|
||
line-height: normal;
|
||
letter-spacing: 0px;
|
||
text-align: left;
|
||
}
|
||
|
||
.banner-subtitle {
|
||
color: #8E8E93;
|
||
font-weight: 600;
|
||
font-size: 14px;
|
||
line-height: normal;
|
||
letter-spacing: 0px;
|
||
text-align: center;
|
||
}
|
||
|
||
.stats-card {
|
||
width: 100%;
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 12px;
|
||
padding: 12px;
|
||
border-radius: 10px;
|
||
background: linear-gradient(-135deg, #E8542F 0%, #C0301B 100%);
|
||
}
|
||
|
||
.stats-gift {
|
||
width: 36px;
|
||
height: 36px;
|
||
}
|
||
|
||
.stats-label {
|
||
color: #FFFFFF;
|
||
font-size: 14px;
|
||
line-height: normal;
|
||
letter-spacing: 0px;
|
||
text-align: left;
|
||
}
|
||
|
||
.stats-number {
|
||
flex: 1;
|
||
font-weight: 700;
|
||
font-size: 36px;
|
||
line-height: normal;
|
||
letter-spacing: 0px;
|
||
text-align: center;
|
||
color: #fce7b0;
|
||
}
|
||
|
||
/* 三期 Tab */
|
||
.tab-bar {
|
||
display: flex;
|
||
background-color: #ffffff;
|
||
padding-top: 12px;
|
||
justify-content: space-around;
|
||
position: sticky;
|
||
top: 0;
|
||
z-index: 5;
|
||
border-bottom: 1px solid #f2f2f7;
|
||
}
|
||
|
||
.tab-item {
|
||
display: flex;
|
||
flex-direction: column;
|
||
align-items: center;
|
||
width: 88px;
|
||
position: relative;
|
||
padding-bottom: 12px;
|
||
}
|
||
|
||
.tab-label {
|
||
color: #B1B1B1;
|
||
font-weight: 600;
|
||
font-size: 16px;
|
||
line-height: 22px;
|
||
letter-spacing: 0px;
|
||
text-align: center;
|
||
}
|
||
|
||
.tab-date {
|
||
font-size: 14px;
|
||
font-weight: 600;
|
||
color: #B1B1B1;
|
||
line-height: 22px;
|
||
}
|
||
|
||
.tab-item.active .tab-label,
|
||
.tab-item.active .tab-date {
|
||
color: #E0342B;
|
||
}
|
||
|
||
.tab-indicator {
|
||
position: absolute;
|
||
bottom: 0;
|
||
width: 24px;
|
||
height: 4px;
|
||
background-color: #E0342B;
|
||
border-radius: 100px;
|
||
}
|
||
|
||
/* 搜索栏 */
|
||
.search-area {
|
||
background-color: #ffffff;
|
||
padding: 10px 12px 12px;
|
||
}
|
||
|
||
.search-bar {
|
||
display: flex;
|
||
align-items: center;
|
||
height: 44px;
|
||
background-color: #ffffff;
|
||
border: 1px solid #f2f2f7;
|
||
border-radius: 100px;
|
||
padding: 4px 8px;
|
||
gap: 12px;
|
||
}
|
||
|
||
.search-input {
|
||
flex: 1;
|
||
font-size: 16px;
|
||
color: #333;
|
||
}
|
||
|
||
.search-btn {
|
||
background-color: #E8542F;
|
||
color: #ffffff;
|
||
font-size: 14px;
|
||
padding: 4px 10px;
|
||
border-radius: 50px;
|
||
white-space: nowrap;
|
||
}
|
||
|
||
/* 中奖者表格 */
|
||
.table-area {
|
||
background-color: #ffffff;
|
||
width: 100%;
|
||
margin: 12px 0;
|
||
padding: 0 12px;
|
||
box-sizing: border-box;
|
||
}
|
||
|
||
.table-header,
|
||
.table-row {
|
||
display: flex;
|
||
align-items: center;
|
||
padding: 12px 0;
|
||
border-bottom: 1px solid #f2f2f7;
|
||
}
|
||
|
||
.table-header {
|
||
color: #8e8e93;
|
||
font-size: 14px;
|
||
}
|
||
|
||
.table-row {
|
||
color: #000000;
|
||
font-size: 14px;
|
||
height: 64px;
|
||
}
|
||
|
||
.table-col {
|
||
flex: 1;
|
||
text-align: center;
|
||
}
|
||
|
||
.col-name {
|
||
width: 80px;
|
||
flex: none;
|
||
text-align: center;
|
||
}
|
||
|
||
.col-idcard {
|
||
flex: 1;
|
||
text-align: center;
|
||
}
|
||
|
||
/* 加载更多 */
|
||
.loadmore-area {
|
||
padding: 24px 0;
|
||
color: #999999;
|
||
}
|
||
|
||
/* 空态 */
|
||
.empty-area {
|
||
display: flex;
|
||
flex-direction: column;
|
||
align-items: center;
|
||
padding: 80px 0;
|
||
color: #999999;
|
||
}
|
||
|
||
.empty-text {
|
||
margin-top: 12px;
|
||
font-size: 14px;
|
||
}
|
||
</style>
|