458 lines
16 KiB
Vue
458 lines
16 KiB
Vue
<template>
|
||
<!-- xuchao: 2026-10 首页按 UI 设计稿改版 —— 底部双 Tab 为自定义组件(切图含文字),页面留 tabbar 高度的底衬 -->
|
||
<view class="page">
|
||
<!-- 顶部头图(整张烘焙切图) -->
|
||
<image class="hero" src="/static/hhrs2_hero.png" mode="widthFix"></image>
|
||
|
||
<!-- 金刚区:图标文字已烘焙进切图,不再代码渲染文字 -->
|
||
<view class="kong">
|
||
<image class="kong-item" src="/static/hhrs2_kong_venue.png" mode="aspectFit" @click="goPage('/pages/venue/venue')"></image>
|
||
<image class="kong-item" src="/static/hhrs2_kong_shop.png" mode="aspectFit" @click="goPage('/pages/discount/discount')"></image>
|
||
<image class="kong-item" src="/static/hhrs2_kong_rights.png" mode="aspectFit" @click="goRights()"></image>
|
||
<image class="kong-item" src="/static/hhrs2_kong_winner.png" mode="aspectFit" @click="goPage('/pages/winners/winners')"></image>
|
||
</view>
|
||
|
||
<!-- 可领权益包 -->
|
||
<view class="card">
|
||
<view class="card-head">
|
||
<view class="head-left">
|
||
<view class="bar"></view>
|
||
<text class="head-title">可领权益包</text>
|
||
</view>
|
||
<text class="head-right">数量有限 先到先得</text>
|
||
</view>
|
||
<!-- xuchao: 数量取中奖名单实际总人数(各期 total 求和),接口失败/未出时兜底 10,000 -->
|
||
<text class="pack-sub">已产生 {{ winCountText }} 份千元权益包·实时公证开奖</text>
|
||
<!-- 查询按钮整图切图(含渐变底/礼盒图标/文案),点击打开中奖查询半屏弹层 -->
|
||
<image class="btn-query" src="/static/hhrs2_btn_query.png" mode="widthFix" @click="openQuery()"></image>
|
||
<!-- 指南轮播:两张图 3 秒自动轮播,图片下方指示点标当前张 -->
|
||
<swiper class="guides" :autoplay="true" :interval="3000" :duration="400" circular
|
||
indicator-dots indicator-color="rgba(232,84,47,0.25)" indicator-active-color="#E8542F">
|
||
<swiper-item @click="goPage('/pages/guide/join')">
|
||
<image class="guide-img" src="/static/hhrs2_guide_join.png" mode="aspectFill"></image>
|
||
</swiper-item>
|
||
<swiper-item @click="goPage('/pages/guide/use')">
|
||
<image class="guide-img" src="/static/hhrs2_guide_use.png" mode="aspectFill"></image>
|
||
</swiper-item>
|
||
</swiper>
|
||
</view>
|
||
|
||
<!-- 怀化社保卡折扣商户:按 2026-10-29 定稿的 16 个品牌展示(生活服务4/酒店餐饮8/零食便利4),logo 用品牌 brandLogo、缺失回退门店图 -->
|
||
<view class="card">
|
||
<view class="card-head">
|
||
<view class="head-left">
|
||
<view class="bar"></view>
|
||
<text class="head-title">怀化社保卡折扣商户</text>
|
||
</view>
|
||
<view class="head-link" @click="goPage('/pages/discount/discount')">
|
||
<text>查看全部商户</text>
|
||
<view class="chev"></view>
|
||
</view>
|
||
</view>
|
||
<view class="cat" v-for="grp in brandGroups" :key="grp.name">
|
||
<view class="cat-head">
|
||
<view class="bar bar-sm"></view>
|
||
<text class="cat-name">{{ grp.name }}</text>
|
||
</view>
|
||
<view class="mer-row">
|
||
<view class="mer-item" v-for="b in grp.brands" :key="b.brandId" @click="goStore(b)">
|
||
<image class="mer-logo" :src="b.logo" mode="aspectFill"></image>
|
||
<text class="mer-name">{{ b.display }}</text>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
|
||
<hhrs-tabbar current="home"></hhrs-tabbar>
|
||
|
||
<!-- xuchao: 「查询我的中奖结果」半屏弹层 -->
|
||
<hhrs-winner-sheet :visible="queryVisible" @close="queryVisible = false"></hhrs-winner-sheet>
|
||
</view>
|
||
</template>
|
||
|
||
<script>
|
||
import account from '@/common/account.js'
|
||
import HhrsTabbar from '@/components/hhrs-tabbar/hhrs-tabbar.vue'
|
||
import HhrsWinnerSheet from '@/components/hhrs-winner-sheet/hhrs-winner-sheet.vue'
|
||
|
||
// xuchao: 首页折扣商户板块定稿名单(2026-10-29 业务确认):brand 表 brandId 硬编码,顺序即展示顺序;
|
||
// 每行 4 个(生活服务 1 行 / 酒店餐饮 2 行 / 零食便利 1 行),brandId 在后台下架时该类自动跳过该项
|
||
const HOME_BRAND_GROUPS = [
|
||
{ name: '生活服务', brands: [
|
||
{ brandId: '202610260000011', display: '中国石化' },
|
||
{ brandId: '202610260000012', display: '中国石油' },
|
||
{ brandId: '202610260000077', display: '老百姓大药房' },
|
||
{ brandId: '202610260000110', display: '美年大健康' }
|
||
] },
|
||
{ name: '酒店餐饮', brands: [
|
||
{ brandId: '202610260000170', display: '温德姆酒店' },
|
||
{ brandId: '202610260000105', display: '皇冠假日酒店' },
|
||
{ brandId: '202610260000036', display: '凯里亚德酒店' },
|
||
{ brandId: '202610260000120', display: '维也纳酒店' },
|
||
{ brandId: '202610260000102', display: '煌族国际大酒店' },
|
||
{ brandId: '202610260000039', display: '华泰凤凰国际酒店' },
|
||
{ brandId: '202610260000151', display: '鸡棚子连锁餐饮' },
|
||
{ brandId: '202610260000108', display: '糖大丹' }
|
||
] },
|
||
{ name: '零食便利', brands: [
|
||
{ brandId: '202610260000032', display: '佳惠超市' },
|
||
{ brandId: '202610260000043', display: '富华超市' },
|
||
{ brandId: '202610260000162', display: '怀化三件宝' },
|
||
{ brandId: '202610260000072', display: '米小倩便利店' }
|
||
] }
|
||
]
|
||
|
||
export default {
|
||
components: { HhrsTabbar, HhrsWinnerSheet },
|
||
data() {
|
||
return {
|
||
brandGroups: [],
|
||
queryVisible: false,
|
||
// xuchao: 千元权益包发放数 = 中奖名单总数;加载前用 10000 兜底
|
||
winPackCount: 10000,
|
||
// xuchao: 云闪付免密登录是否仍在进行中 —— 返回前不放行任何依赖身份的跳转
|
||
tokenLoginPending: false,
|
||
tokenLoginTimer: null
|
||
}
|
||
},
|
||
computed: {
|
||
winCountText() {
|
||
return (this.winPackCount || 10000).toLocaleString()
|
||
}
|
||
},
|
||
onLoad(options) {
|
||
// xuchao: 云闪付入口带 token 进来 —— 直接免密换取会话,不经过手机号验证码
|
||
if (options.token) {
|
||
this.handleTokenLogin(options.token)
|
||
}
|
||
// xuchao: 登录页 redirect=query 回跳时自动弹出中奖查询层
|
||
if (options.openQuery) {
|
||
this.queryVisible = true
|
||
}
|
||
this.getLocation()
|
||
this.loadBrands()
|
||
this.loadWinCount()
|
||
},
|
||
// xuchao: 离开首页时收尾,避免看门狗与遮罩残留
|
||
onUnload() {
|
||
this.finishTokenLogin()
|
||
},
|
||
methods: {
|
||
// xuchao: 首页"会产生 N 份"= 各期开奖名单 total 求和(与中奖公示页"已产生"同口径);
|
||
// pageSize=1 只取计数不拉名单,失败静默保持 10,000 兜底
|
||
loadWinCount() {
|
||
this.$u.api.getWinnerDates().then(res => {
|
||
if (res.errcode !== 0 || !Array.isArray(res.data) || !res.data.length) return
|
||
Promise.all(res.data.map(d => this.$u.api.getWinnerList({ pageNo: 1, pageSize: 1, drawDate: d })))
|
||
.then(list => {
|
||
const sum = list.reduce((acc, r) => acc + ((r && r.errcode === 0 && r.data && r.data.total) || 0), 0)
|
||
if (sum > 0) this.winPackCount = sum
|
||
}).catch(() => {})
|
||
}).catch(() => {})
|
||
},
|
||
// xuchao: 折扣商户板块改为品牌宫格:拉商户折扣全量门店,按定稿 brandId 名单组装;
|
||
// 同一 brandId 取首家门店作跳转锚点,logo 品牌图缺失回退门店图,品牌下架则该位自动缺行
|
||
loadBrands() {
|
||
this.$u.api.getStoreList({ pageNo: 1, pageSize: 300, typeId: 2 }).then(res => {
|
||
if (res.errcode !== 0 || !res.data) return
|
||
const byBrand = {}
|
||
;(res.data.list || []).forEach(s => {
|
||
const id = String(s.brandId || '')
|
||
if (id && !byBrand[id]) byBrand[id] = s
|
||
})
|
||
this.brandGroups = HOME_BRAND_GROUPS.map(g => ({
|
||
name: g.name,
|
||
brands: g.brands
|
||
.filter(b => byBrand[b.brandId])
|
||
.map(b => {
|
||
const s = byBrand[b.brandId]
|
||
return { brandId: b.brandId, display: b.display, logo: s.brandLogo || s.image, shopId: s.shopId }
|
||
})
|
||
})).filter(g => g.brands.length)
|
||
})
|
||
},
|
||
// xuchao: 云闪付入口 token 自动登录(免密换人)
|
||
handleTokenLogin(token) {
|
||
// xuchao: 云闪付入口是"免密换人",本机上一个账号的会话与权益缓存必须先丢弃:
|
||
// 一是请求不能再带旧 accessToken(后端"会话优先"会把旧账号数据返给新用户),
|
||
// 二是权益页只在 onLoad 取一次账号快照、不会自我纠正,所以清缓存必须赶在
|
||
// 发请求之前 —— 解码返回前的窗口期里最多读到"未登录",绝不会读到别人的数据
|
||
account.clearAccountCache()
|
||
this.tokenLoginPending = true
|
||
uni.showLoading({ title: '登录中', mask: true })
|
||
// xuchao: 兜底看门狗,网络异常时不让遮罩卡死(只收遮罩,不改变登录结果)
|
||
this.tokenLoginTimer = setTimeout(() => {
|
||
this.finishTokenLogin()
|
||
}, 10000)
|
||
this.$u.api.tokenDecode({ token }).then(res => {
|
||
this.finishTokenLogin()
|
||
if (res.errcode === 0 && res.data && res.data.mobile) {
|
||
uni.setStorageSync('phone', res.data.mobile)
|
||
// xuchao: 后端已为云闪付入口签发会员会话,存下 accessToken,后续接口才认得这个用户。
|
||
// 只认"非空字符串":后端字段缺失/为 null 时会被序列化成 {},直接存进缓存
|
||
// 就会变成 Bearer [object Object],把所有鉴权接口全打挂
|
||
const issued = typeof res.data.accessToken === 'string' ? res.data.accessToken : ''
|
||
if (issued) uni.setStorageSync('token', issued)
|
||
// xuchao: 标记本次会话为云闪付免密登录——商户详情付款码按此放行
|
||
uni.setStorageSync('loginWay', 'ysf')
|
||
this.$u.api.getEligibility({ phone: res.data.mobile, identityNo: res.data.idNo || '', name: res.data.name || '' }).then(eRes => {
|
||
if (eRes.errcode === 0) {
|
||
uni.setStorageSync('isAuth', eRes.data.isAuth)
|
||
uni.setStorageSync('hasWin', eRes.data.hasWin)
|
||
uni.setStorageSync('cardNumber', eRes.data.cardNumber)
|
||
uni.setStorageSync('expiresTime', eRes.data.expiresTime)
|
||
}
|
||
})
|
||
// xuchao: 清除地址栏 token,防止分享泄露
|
||
this.clearUrlToken()
|
||
} else {
|
||
this.degradeToPhoneLogin()
|
||
}
|
||
}).catch(() => {
|
||
this.finishTokenLogin()
|
||
this.degradeToPhoneLogin()
|
||
})
|
||
},
|
||
// xuchao: 免密登录收尾(收起遮罩、撤看门狗),成功/失败/超时/离开页面都会走到
|
||
finishTokenLogin() {
|
||
if (!this.tokenLoginPending) return
|
||
this.tokenLoginPending = false
|
||
clearTimeout(this.tokenLoginTimer)
|
||
this.tokenLoginTimer = null
|
||
uni.hideLoading()
|
||
},
|
||
// xuchao: 解码失败兜底,提示并跳手机号登录
|
||
degradeToPhoneLogin() {
|
||
uni.showToast({ title: '登录凭证已失效,请使用手机号登录', icon: 'none' })
|
||
setTimeout(() => {
|
||
uni.navigateTo({ url: '/pages/index/login' })
|
||
}, 800)
|
||
},
|
||
// xuchao: 从 URL hash 中移除 token 参数
|
||
clearUrlToken() {
|
||
try {
|
||
const hash = window.location.hash || ''
|
||
const qIndex = hash.indexOf('?')
|
||
if (qIndex === -1) return
|
||
const params = new URLSearchParams(hash.substring(qIndex + 1))
|
||
if (!params.has('token')) return
|
||
params.delete('token')
|
||
const rest = params.toString()
|
||
const base = hash.substring(0, qIndex)
|
||
window.history.replaceState(null, '', rest ? `${base}?${rest}` : base)
|
||
} catch (e) {}
|
||
},
|
||
getLocation() {
|
||
import('@/common/location.js').then(module => {
|
||
module.default.getLocation().then(({ lng, lat }) => {
|
||
console.log('定位成功:', lng, lat)
|
||
}).catch(err => {
|
||
console.log('定位失败:', err)
|
||
})
|
||
})
|
||
},
|
||
goPage(url) {
|
||
uni.navigateTo({ url })
|
||
},
|
||
// xuchao: 「查询我的中奖结果」入口:免密登录中不放行,未登录先去登录并回跳,否则开弹层
|
||
openQuery() {
|
||
if (this.tokenLoginPending) {
|
||
uni.showToast({ title: '正在登录,请稍候', icon: 'none' })
|
||
return
|
||
}
|
||
const phone = uni.getStorageSync('phone')
|
||
if (!phone) {
|
||
uni.navigateTo({ url: '/pages/index/login?redirect=query' })
|
||
return
|
||
}
|
||
this.queryVisible = true
|
||
},
|
||
goStore(s) {
|
||
// xuchao: 与商户折扣页同款跳转——品牌详情页
|
||
uni.navigateTo({ url: '/pages/shop/detail?id=' + s.shopId })
|
||
},
|
||
goRights() {
|
||
// xuchao: 免密登录还没返回时不放行,避免带着空/旧身份进权益页
|
||
if (this.tokenLoginPending) {
|
||
uni.showToast({ title: '正在登录,请稍候', icon: 'none' })
|
||
return
|
||
}
|
||
const phone = uni.getStorageSync('phone')
|
||
if (!phone) {
|
||
uni.navigateTo({ url: '/pages/index/login?redirect=rights' })
|
||
return
|
||
}
|
||
const isAuth = uni.getStorageSync('isAuth')
|
||
const hasWin = uni.getStorageSync('hasWin')
|
||
// xuchao: 最近发起过认证流程(含取消)时忽略旧认证缓存,一律回认证页
|
||
const authFlowStarted = uni.getStorageSync('authFlowStarted')
|
||
let status = 'auth'
|
||
if (isAuth && !authFlowStarted) {
|
||
status = hasWin ? 'info' : 'noWin'
|
||
}
|
||
uni.navigateTo({ url: `/pages/rights/rights?status=${status}` })
|
||
}
|
||
}
|
||
}
|
||
</script>
|
||
|
||
<style>
|
||
/* xuchao: 改版后首页底色取设计稿暖米色;底部为自定义 tabbar(128rpx+安全区)留底衬 */
|
||
.page {
|
||
min-height: 100vh;
|
||
background-color: #FDECE2;
|
||
padding-bottom: calc(156rpx + env(safe-area-inset-bottom));
|
||
}
|
||
|
||
.hero {
|
||
width: 100%;
|
||
display: block;
|
||
}
|
||
|
||
/* 金刚区(整图切图 110rpx,含文字);与卡1间距由 80 减半为 40(16+卡 margin-top 24) */
|
||
.kong {
|
||
display: flex;
|
||
justify-content: space-around;
|
||
align-items: center;
|
||
padding: 10rpx 0 16rpx;
|
||
}
|
||
.kong-item {
|
||
width: 110rpx;
|
||
height: 110rpx;
|
||
}
|
||
|
||
/* 白卡通用(设计稿实测:外边距 29、左右内边距 17,内容宽 658 与切图基准一致) */
|
||
.card {
|
||
background: #FFFFFF;
|
||
border-radius: 28rpx;
|
||
margin: 24rpx 29rpx 0;
|
||
padding: 24rpx 17rpx;
|
||
}
|
||
.card-head {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
}
|
||
.head-left {
|
||
display: flex;
|
||
align-items: center;
|
||
}
|
||
.bar {
|
||
width: 8rpx;
|
||
height: 34rpx;
|
||
border-radius: 4rpx;
|
||
background: linear-gradient(180deg, #F6613C, #E01818);
|
||
margin-right: 14rpx;
|
||
}
|
||
.head-title {
|
||
font-size: 34rpx;
|
||
font-weight: bold;
|
||
color: #333333;
|
||
}
|
||
.head-right {
|
||
font-size: 24rpx;
|
||
color: #BCAB9A;
|
||
}
|
||
.head-link {
|
||
display: flex;
|
||
align-items: center;
|
||
font-size: 26rpx;
|
||
font-weight: 600;
|
||
color: #E0342B;
|
||
}
|
||
.chev {
|
||
width: 12rpx;
|
||
height: 12rpx;
|
||
border-top: 3rpx solid #E0342B;
|
||
border-right: 3rpx solid #E0342B;
|
||
transform: rotate(45deg);
|
||
margin-left: 8rpx;
|
||
}
|
||
|
||
/* 可领权益包(切图 @1500 基准,显示 px÷2:按钮 658×102、指南卡 571×141) */
|
||
.pack-sub {
|
||
display: block;
|
||
margin-top: 22rpx;
|
||
font-size: 26rpx;
|
||
color: #E05A38;
|
||
}
|
||
.btn-query {
|
||
display: block;
|
||
width: 100%;
|
||
margin-top: 26rpx;
|
||
}
|
||
/* xuchao: 指南轮播 swiper —— 图 648x200(切图 1297x400÷2),指示点浮于图片内侧 */
|
||
.guides {
|
||
margin-top: 26rpx;
|
||
height: 200rpx;
|
||
}
|
||
/* xuchao: uni-app H5 把页面样式编成 scoped,swiper 内部元素无 data-v 属性,必须 /deep/ 穿透;
|
||
容器高=图高时 bottom 即点距图底距离,3px ≈ 原默认位置(压出图外3px)上移 6px 且完全在图内 */
|
||
.guides /deep/ .uni-swiper-dots-horizontal {
|
||
bottom: 3px !important;
|
||
}
|
||
.guide-img {
|
||
display: block;
|
||
width: 648rpx;
|
||
height: 200rpx;
|
||
border-radius: 24rpx;
|
||
margin: 0 auto;
|
||
}
|
||
|
||
/* 折扣商户 */
|
||
.cat {
|
||
margin-top: 28rpx;
|
||
}
|
||
.cat-head {
|
||
display: flex;
|
||
align-items: center;
|
||
}
|
||
.bar-sm {
|
||
width: 6rpx;
|
||
height: 26rpx;
|
||
border-radius: 3rpx;
|
||
margin-right: 12rpx;
|
||
/* xuchao: 折扣商户二级标题标记色,按 UI 要求统一琥珀金 */
|
||
background: #E79A30;
|
||
}
|
||
.cat-name {
|
||
font-size: 30rpx;
|
||
font-weight: bold;
|
||
color: #333333;
|
||
}
|
||
.mer-row {
|
||
display: flex;
|
||
flex-wrap: wrap;
|
||
margin-top: 24rpx;
|
||
}
|
||
.mer-item {
|
||
width: 25%;
|
||
box-sizing: border-box;
|
||
padding: 0 8rpx;
|
||
display: flex;
|
||
flex-direction: column;
|
||
align-items: center;
|
||
margin-bottom: 30rpx;
|
||
}
|
||
.mer-logo {
|
||
width: 96rpx;
|
||
height: 96rpx;
|
||
border-radius: 16rpx;
|
||
background: #F5F5F5;
|
||
}
|
||
.mer-name {
|
||
width: 100%;
|
||
text-align: center;
|
||
font-size: 22rpx;
|
||
color: #4A3A2E;
|
||
margin-top: 12rpx;
|
||
line-height: 30rpx;
|
||
height: 60rpx;
|
||
/* xuchao: 设计稿店名可折两行,固定两行高度保证宫格对齐 */
|
||
display: -webkit-box;
|
||
-webkit-box-orient: vertical;
|
||
-webkit-line-clamp: 2;
|
||
overflow: hidden;
|
||
}
|
||
</style>
|