consumer模块完成95%,在和商家端对接聊天购物闭环

This commit is contained in:
2026-02-06 17:10:31 +08:00
parent 06b7369494
commit e2f1dfb097
1454 changed files with 5425 additions and 210555 deletions

View File

@@ -20,9 +20,9 @@
<text class="nav-stat-value">{{ userStats.points }}</text>
</view>
<view class="nav-stat-item" @click="goToWallet">
<view class="nav-stat-item">
<text class="nav-stat-label">余额</text>
<text class="nav-stat-value">¥{{ userStats.balance }}</text>
<text class="nav-stat-value" @click="goToWallet">¥{{ userStats.balance }}</text>
</view>
<view class="nav-stat-item" @click="goToCoupons">
@@ -74,9 +74,9 @@
<text class="service-icon">📝</text>
<text class="service-text">评价</text>
</view>
<view class="service-item" @click="goToMySubscriptions">
<text class="service-icon">🧩</text>
<text class="service-text">我的订阅</text>
<view class="service-item" @click="goToFollowedShops">
<text class="service-icon"></text>
<text class="service-text">关注店铺</text>
</view>
<view class="service-item" @click="goToSubscriptions">
<text class="service-icon">📱</text>
@@ -249,7 +249,6 @@
<script>
import { UserType, OrderType } from '@/types/mall-types.uts'
import supabaseService from '@/utils/supabaseService.uts'
import { getCurrentUser } from '@/utils/store.uts'
type UserStatsType = {
points: number
@@ -423,45 +422,86 @@ export default {
const systemInfo = uni.getSystemInfoSync()
this.statusBarHeight = systemInfo.statusBarHeight || 0
},
loadUserProfile() {
// 模拟加载用户信息
this.userInfo = {
id: 'user_001',
phone: '13800138000',
email: 'user@example.com',
nickname: '张三',
avatar_url: '/static/avatar1.jpg',
gender: 1,
user_type: 1,
status: 1,
created_at: '2023-06-15T10:30:00'
async loadUserProfile() {
try {
// 获取用户资料
const profile = await supabaseService.getUserProfile()
if (profile != null) {
// 映射字段
let uId = ''
let uPhone = ''
let uEmail = ''
let uNickname = ''
let uAvatar = ''
let uGender = 0
if (profile instanceof UTSJSONObject) {
uId = profile.getString('user_id') || ''
uPhone = profile.getString('phone') || ''
uEmail = profile.getString('email') || ''
uNickname = profile.getString('nickname') || ''
uAvatar = profile.getString('avatar_url') || ''
uGender = profile.getNumber('gender') || 0
} else {
uId = (profile['user_id'] as string) || ''
uPhone = (profile['phone'] as string) || ''
uEmail = (profile['email'] as string) || ''
uNickname = (profile['nickname'] as string) || ''
uAvatar = (profile['avatar_url'] as string) || ''
uGender = (profile['gender'] as number) || 0
}
// 如果昵称为空,使用手机号脱敏显示
if (!uNickname && uPhone) {
uNickname = uPhone.substring(0, 3) + '****' + uPhone.substring(7)
}
this.userInfo = {
id: uId,
phone: uPhone,
email: uEmail,
nickname: uNickname || '微信用户',
avatar_url: uAvatar || '/static/default-avatar.png',
gender: uGender,
user_type: 1,
status: 1,
created_at: new Date().toISOString()
} as UserType
} else {
// 如果获取失败未登录或无档案尝试获取当前登录ID
const userId = supabaseService.getCurrentUserId()
if (userId != null) {
this.userInfo.id = userId
this.userInfo.nickname = '用户' + userId.substring(0, 4)
} else {
this.userInfo.nickname = '未登录'
}
}
// 获取积分和余额(并行获取)
const [balance, points] = await Promise.all([
supabaseService.getUserBalance(),
supabaseService.getUserPoints()
])
this.userStats = {
points: points,
balance: balance,
level: this.calculateLevel(points) // 根据积分计算等级
} as UserStatsType
} catch (e) {
console.error('加载用户信息失败', e)
// 保持默认或显示错误
}
this.userStats = {
points: 1580,
balance: 268.50,
level: 3
}
// orderCounts 将通过 loadOrders 从真实数据获取
// init with zeros
this.orderCounts = {
total: 0,
pending: 0,
toship: 0,
shipped: 0,
review: 0
}
this.serviceCounts = {
coupons: 5,
favorites: 12
}
// recentOrders 将通过 loadOrders 从真实数据获取
this.recentOrders = []
this.loadConsumptionStats()
},
calculateLevel(points: number): number {
if (points < 1000) return 0
if (points < 5000) return 1
if (points < 20000) return 2
if (points < 50000) return 3
return 4
},
loadConsumptionStats() {
@@ -503,11 +543,15 @@ export default {
this.updateCouponCount() // 更新优惠券数量
},
updateCouponCount() {
// 从本地存储读取领取的优惠券数量并叠加到基础数量上
const baseCoupons = 5
const claimedCoupons = uni.getStorageSync('claimedCoupons') || 0
this.serviceCounts.coupons = baseCoupons + (claimedCoupons as number)
async updateCouponCount() {
// 从 Supabase 获取真实的优惠券数量
try {
const count = await supabaseService.getUserCouponCount()
this.serviceCounts.coupons = count
} catch (e) {
console.error('获取优惠券数量失败', e)
this.serviceCounts.coupons = 0
}
},
getUserLevel(): string {
@@ -585,39 +629,10 @@ export default {
// 跳转钱包
goToWallet() {
const user = getCurrentUser()
if (!user) {
uni.showToast({
title: '请先登录',
icon: 'none'
})
uni.navigateTo({
url: '/pages/user/login'
})
return
}
uni.navigateTo({
url: '/pages/mall/consumer/wallet'
})
},
// 跳转积分
goToPoints() {
const user = getCurrentUser()
if (!user) {
uni.showToast({
title: '请先登录',
icon: 'none'
})
uni.navigateTo({
url: '/pages/user/login'
})
return
}
uni.navigateTo({
url: '/pages/mall/consumer/points'
})
},
goToOrders(type: string) {
uni.navigateTo({
@@ -670,6 +685,12 @@ export default {
url: '/pages/mall/consumer/coupons'
})
},
goToPoints() {
uni.navigateTo({
url: '/pages/mall/consumer/points/index'
})
},
goToAddress() {
// 暂时跳转到设置页的地址管理
@@ -711,6 +732,11 @@ export default {
url: '/pages/mall/consumer/subscription/my-subscriptions'
})
},
goToFollowedShops() {
uni.navigateTo({
url: '/pages/mall/consumer/subscription/followed-shops'
})
},
goToSubscriptions() {
uni.navigateTo({
url: '/pages/mall/consumer/subscription/plan-list'