完成consumer端同步

This commit is contained in:
2026-05-14 15:28:09 +08:00
parent 612fb3d360
commit 0ffbc53902
197 changed files with 92657 additions and 7564 deletions

View File

@@ -0,0 +1,279 @@
<template>
<scroll-view class="records-page" direction="vertical">
<view class="empty-state" v-if="!loading && records.length === 0">
<text class="empty-text">暂无兑换记录</text>
</view>
<view class="loading-state" v-if="loading">
<text class="loading-text">加载中...</text>
</view>
<view class="record-list" v-if="!loading && records.length > 0">
<view class="record-item" v-for="record in records" :key="record.id">
<view class="record-header">
<text class="record-product-name">{{ record.product_name }}</text>
<text class="record-status" :class="getStatusClass(record.status)">{{ getStatusText(record.status) }}</text>
</view>
<view class="record-info">
<view class="info-row">
<text class="info-label">消耗积分</text>
<text class="info-value">{{ record.points_used }}</text>
</view>
<view class="info-row">
<text class="info-label">兑换数量</text>
<text class="info-value">{{ record.quantity }}</text>
</view>
<view class="info-row">
<text class="info-label">兑换时间</text>
<text class="info-value">{{ formatTime(record.created_at) }}</text>
</view>
<view class="info-row" v-if="record.tracking_no">
<text class="info-label">物流单号</text>
<text class="info-value">{{ record.tracking_no }}</text>
</view>
</view>
</view>
</view>
</scroll-view>
</template>
<script setup lang="uts">
import { ref, onMounted } from 'vue'
import { supabaseService } from '@/utils/supabaseService.uts'
type ExchangeRecord = {
id: string
product_name: string
product_image: string | null
product_type: string
quantity: number
points_used: number
status: number
tracking_no: string | null
created_at: string
}
const records = ref<ExchangeRecord[]>([])
const loading = ref<boolean>(true)
const loadRecords = async (): Promise<void> => {
loading.value = true
try {
const result = await supabaseService.getExchangeRecords()
const parsed: ExchangeRecord[] = []
for (let i = 0; i < result.length; i++) {
const item = result[i]
const itemAny = item as any
// 处理数组返回
let recordData: any
if (Array.isArray(itemAny)) {
recordData = itemAny[0]
} else {
recordData = itemAny
}
let id = ''
let quantity = 1
let points_used = 0
let status = 0
let tracking_no: string | null = null
let created_at = ''
let product_name = ''
let product_image: string | null = null
let product_type = 'coupon'
// 转换为 UTSJSONObject
let recordObj: UTSJSONObject | null = null
if (recordData instanceof UTSJSONObject) {
recordObj = recordData
} else {
recordObj = JSON.parse(JSON.stringify(recordData)) as UTSJSONObject
}
id = recordObj.getString('id') ?? ''
quantity = recordObj.getNumber('quantity') ?? 1
points_used = recordObj.getNumber('points_used') ?? 0
status = recordObj.getNumber('status') ?? 0
tracking_no = recordObj.getString('tracking_no')
created_at = recordObj.getString('created_at') ?? ''
// 获取关联的商品信息
const product = recordObj.get('product')
if (product != null) {
let productObj: UTSJSONObject | null = null
if (product instanceof UTSJSONObject) {
productObj = product
} else {
productObj = JSON.parse(JSON.stringify(product)) as UTSJSONObject
}
product_name = productObj.getString('name') ?? ''
product_image = productObj.getString('image_url')
product_type = productObj.getString('product_type') ?? 'coupon'
}
parsed.push({
id,
product_name,
product_image,
product_type,
quantity,
points_used,
status,
tracking_no,
created_at
})
}
records.value = parsed
} catch (e) {
console.error('加载兑换记录失败:', e)
} finally {
loading.value = false
}
}
const getStatusText = (status: number): string => {
if (status === 0) return '待处理'
if (status === 1) return '已发货'
if (status === 2) return '已完成'
if (status === 3) return '已取消'
return '未知'
}
const getStatusClass = (status: number): string => {
if (status === 0) return 'status-pending'
if (status === 1) return 'status-shipped'
if (status === 2) return 'status-completed'
if (status === 3) return 'status-cancelled'
return ''
}
const formatTime = (timeStr: string): string => {
if (timeStr == '') return ''
const date = new Date(timeStr)
const y = date.getFullYear()
const m = (date.getMonth() + 1).toString().padStart(2, '0')
const d = date.getDate().toString().padStart(2, '0')
const hh = date.getHours().toString().padStart(2, '0')
const mm = date.getMinutes().toString().padStart(2, '0')
return `${y}-${m}-${d} ${hh}:${mm}`
}
onMounted(() => {
loadRecords()
})
</script>
<style>
.records-page {
flex: 1;
height: 100%;
background-color: #f5f5f5;
padding: 12px;
}
.empty-state {
padding: 60px 0;
display: flex;
align-items: center;
justify-content: center;
}
.empty-text {
font-size: 14px;
color: #999;
}
.loading-state {
padding: 60px 0;
display: flex;
align-items: center;
justify-content: center;
}
.loading-text {
font-size: 14px;
color: #999;
}
.record-list {
display: flex;
flex-direction: column;
}
.record-item {
background-color: white;
border-radius: 8px;
padding: 12px;
margin-bottom: 8px;
}
.record-header {
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
margin-bottom: 12px;
padding-bottom: 8px;
border-bottom: 1px solid #f0f0f0;
}
.record-product-name {
font-size: 16px;
font-weight: bold;
color: #333;
flex: 1;
}
.record-status {
font-size: 12px;
padding: 4px 8px;
border-radius: 4px;
}
.status-pending {
background-color: #fff7e6;
color: #d48806;
}
.status-shipped {
background-color: #e6f7ff;
color: #1890ff;
}
.status-completed {
background-color: #f6ffed;
color: #52c41a;
}
.status-cancelled {
background-color: #f5f5f5;
color: #999;
}
.record-info {
display: flex;
flex-direction: column;
}
.info-row {
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
padding: 6px 0;
}
.info-label {
font-size: 14px;
color: #999;
}
.info-value {
font-size: 14px;
color: #333;
}
</style>

View File

@@ -0,0 +1,727 @@
<template>
<scroll-view class="exchange-page" direction="vertical">
<view class="header">
<view class="points-info">
<text class="points-label">可用积分</text>
<text class="points-value">{{ totalPoints }}</text>
</view>
<view class="header-actions">
<text class="records-link" @click="goToRecords">兑换记录</text>
</view>
</view>
<view class="tabs">
<view
class="tab-item"
:class="activeTab === 'all' ? 'active' : ''"
@click="switchTab('all')"
>
<text class="tab-text">全部</text>
</view>
<view
class="tab-item"
:class="activeTab === 'coupon' ? 'active' : ''"
@click="switchTab('coupon')"
>
<text class="tab-text">优惠券</text>
</view>
<view
class="tab-item"
:class="activeTab === 'physical' ? 'active' : ''"
@click="switchTab('physical')"
>
<text class="tab-text">实物</text>
</view>
<view
class="tab-item"
:class="activeTab === 'virtual' ? 'active' : ''"
@click="switchTab('virtual')"
>
<text class="tab-text">虚拟</text>
</view>
</view>
<view class="product-list" v-if="!loading">
<view
class="product-card"
v-for="product in filteredProducts"
:key="product.id"
@click="showExchangePopup(product)"
>
<image
class="product-image"
:src="product.image_url != null && product.image_url.length > 0 ? product.image_url : defaultImage"
mode="aspectFill"
/>
<view class="product-info">
<text class="product-name">{{ product.name }}</text>
<text class="product-desc" v-if="product.description">{{ product.description }}</text>
<view class="product-bottom">
<view class="product-points">
<text class="points-num">{{ product.points_required }}</text>
<text class="points-unit">积分</text>
</view>
<text class="product-stock">库存{{ product.stock }}件</text>
<text class="product-original" v-if="product.original_price">¥{{ product.original_price }}</text>
</view>
</view>
</view>
</view>
<view class="empty-state" v-if="!loading && filteredProducts.length === 0">
<text class="empty-text">暂无可兑换商品</text>
</view>
<view class="loading-state" v-if="loading">
<text class="loading-text">加载中...</text>
</view>
<view class="exchange-popup" v-if="showPopup" @click="closePopup">
<view class="popup-content" @click.stop>
<view class="popup-header">
<text class="popup-title">确认兑换</text>
<text class="popup-close" @click="closePopup">×</text>
</view>
<view class="popup-product" v-if="selectedProduct != null">
<image
class="popup-product-image"
:src="selectedProduct.image_url != null && selectedProduct.image_url.length > 0 ? selectedProduct.image_url : defaultImage"
mode="aspectFill"
/>
<view class="popup-product-info">
<text class="popup-product-name">{{ selectedProduct.name }}</text>
<view class="popup-product-points">
<text class="popup-points-num">{{ selectedProduct.points_required }}</text>
<text class="popup-points-unit">积分</text>
</view>
</view>
</view>
<view class="popup-quantity">
<text class="quantity-label">兑换数量</text>
<view class="quantity-control">
<text class="quantity-btn" @click="decreaseQuantity">-</text>
<text class="quantity-value">{{ exchangeQuantity }}</text>
<text class="quantity-btn" @click="increaseQuantity">+</text>
</view>
</view>
<view class="popup-summary">
<view class="summary-row">
<text class="summary-label">消耗积分</text>
<text class="summary-value">{{ totalPointsCost }}</text>
</view>
<view class="summary-row">
<text class="summary-label">当前积分</text>
<text class="summary-value">{{ totalPoints }}</text>
</view>
<view class="summary-row" v-if="totalPoints < totalPointsCost">
<text class="summary-label insufficient">积分不足</text>
<text class="summary-value insufficient">差{{ totalPointsCost - totalPoints }}</text>
</view>
</view>
<button
class="popup-btn"
:class="{ disabled: totalPoints < totalPointsCost }"
:disabled="totalPoints < totalPointsCost || exchanging"
@click="confirmExchange"
>
{{ exchanging ? '兑换中...' : '确认兑换' }}
</button>
</view>
</view>
<view class="success-popup" v-if="showSuccess" @click="closeSuccess">
<view class="success-content" @click.stop>
<view class="success-icon">✓</view>
<text class="success-title">兑换成功</text>
<text class="success-desc">消耗 {{ totalPointsCost }} 积分</text>
<button class="success-btn" @click="closeSuccess">确定</button>
</view>
</view>
</scroll-view>
</template>
<script setup lang="uts">
import { ref, computed, onMounted } from 'vue'
import { supabaseService } from '@/utils/supabaseService.uts'
type PointProduct = {
id: string
name: string
description: string | null
image_url: string | null
product_type: string
points_required: number
original_price: number | null
stock: number
status: number
}
const totalPoints = ref<number>(0)
const products = ref<PointProduct[]>([])
const loading = ref<boolean>(true)
const activeTab = ref<string>('all')
const showPopup = ref<boolean>(false)
const showSuccess = ref<boolean>(false)
const selectedProduct = ref<PointProduct | null>(null)
const exchangeQuantity = ref<number>(1)
const exchanging = ref<boolean>(false)
const defaultImage: string = '/static/images/default-product.png'
const filteredProducts = computed((): PointProduct[] => {
if (activeTab.value === 'all') {
return products.value
}
const filtered: PointProduct[] = []
for (let i = 0; i < products.value.length; i++) {
if (products.value[i].product_type === activeTab.value) {
filtered.push(products.value[i])
}
}
return filtered
})
const totalPointsCost = computed((): number => {
if (selectedProduct.value == null) return 0
return selectedProduct.value.points_required * exchangeQuantity.value
})
const loadProducts = async (): Promise<void> => {
loading.value = true
try {
const points = await supabaseService.getUserPoints()
totalPoints.value = points
const productList = await supabaseService.getPointProducts()
const parsed: PointProduct[] = []
for (let i = 0; i < productList.length; i++) {
const item = productList[i]
let id = ''
let name = ''
let description: string | null = null
let image_url: string | null = null
let product_type = 'coupon'
let points_required = 0
let original_price: number | null = null
let stock = 0
let status = 1
let itemObj: UTSJSONObject | null = null
if (item instanceof UTSJSONObject) {
itemObj = item
} else {
itemObj = JSON.parse(JSON.stringify(item)) as UTSJSONObject
}
id = itemObj.getString('id') ?? ''
name = itemObj.getString('name') ?? ''
description = itemObj.getString('description')
image_url = itemObj.getString('image_url')
product_type = itemObj.getString('product_type') ?? 'coupon'
points_required = itemObj.getNumber('points_required') ?? 0
original_price = itemObj.getNumber('original_price')
stock = itemObj.getNumber('stock') ?? 0
status = itemObj.getNumber('status') ?? 1
const product: PointProduct = {
id,
name,
description,
image_url,
product_type,
points_required,
original_price,
stock,
status
}
parsed.push(product)
}
products.value = parsed
} catch (e) {
console.error('加载商品失败:', e)
} finally {
loading.value = false
}
}
const switchTab = (tab: string): void => {
activeTab.value = tab
}
const showExchangePopup = (product: PointProduct): void => {
selectedProduct.value = product
exchangeQuantity.value = 1
showPopup.value = true
}
const closePopup = (): void => {
showPopup.value = false
selectedProduct.value = null
}
const increaseQuantity = (): void => {
if (selectedProduct.value != null && exchangeQuantity.value < selectedProduct.value.stock) {
exchangeQuantity.value++
}
}
const decreaseQuantity = (): void => {
if (exchangeQuantity.value > 1) {
exchangeQuantity.value--
}
}
const confirmExchange = async (): Promise<void> => {
if (selectedProduct.value == null) return
if (totalPoints.value < totalPointsCost.value) return
exchanging.value = true
try {
const result = await supabaseService.exchangeProduct(
selectedProduct.value.id,
exchangeQuantity.value,
null
)
if (result.getBoolean('success') === true) {
showPopup.value = false
totalPoints.value -= totalPointsCost.value
showSuccess.value = true
loadProducts()
} else {
const message = result.getString('message') ?? '兑换失败'
uni.showToast({ title: message, icon: 'none' })
}
} catch (e) {
console.error('兑换异常:', e)
uni.showToast({ title: '兑换异常', icon: 'none' })
} finally {
exchanging.value = false
}
}
const closeSuccess = (): void => {
showSuccess.value = false
}
const goToRecords = (): void => {
uni.navigateTo({
url: '/pages/mall/consumer/points/exchange-records'
})
}
onMounted(() => {
loadProducts()
})
</script>
<style>
.exchange-page {
flex: 1;
height: 100%;
background-color: #f5f5f5;
}
.header {
background: linear-gradient(135deg, #ff6b35 0%, #ff8c42 100%);
padding: 16px;
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
}
.points-info {
display: flex;
flex-direction: column;
}
.points-label {
font-size: 12px;
color: rgba(255, 255, 255, 0.8);
}
.points-value {
font-size: 28px;
font-weight: bold;
color: white;
}
.header-actions {
display: flex;
flex-direction: row;
}
.records-link {
font-size: 14px;
color: white;
padding: 6px 12px;
background-color: rgba(255, 255, 255, 0.2);
border-radius: 16px;
}
.tabs {
display: flex;
flex-direction: row;
background-color: white;
padding: 0 16px;
}
.tab-item {
flex: 1;
padding: 12px 0;
display: flex;
align-items: center;
justify-content: center;
border-bottom: 2px solid transparent;
}
.tab-item.active {
border-bottom-color: #ff6b35;
}
.tab-text {
font-size: 14px;
color: #666;
}
.tab-item.active .tab-text {
color: #ff6b35;
font-weight: bold;
}
.product-list {
display: flex;
flex-direction: row;
flex-wrap: wrap;
padding: 8px;
}
.product-card {
width: 48%;
margin: 4px;
background-color: white;
border-radius: 8px;
overflow: hidden;
}
.product-image {
width: 100%;
height: 150px;
}
.product-info {
padding: 8px;
}
.product-name {
font-size: 14px;
color: #333;
lines: 2;
text-overflow: ellipsis;
}
.product-desc {
font-size: 12px;
color: #999;
margin-top: 4px;
lines: 1;
text-overflow: ellipsis;
}
.product-bottom {
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
margin-top: 8px;
}
.product-points {
display: flex;
flex-direction: row;
align-items: center;
}
.points-num {
font-size: 18px;
font-weight: bold;
color: #ff6b35;
}
.points-unit {
font-size: 12px;
color: #ff6b35;
margin-left: 2px;
}
.product-stock {
font-size: 12px;
color: #ff6b35;
}
.product-original {
font-size: 12px;
color: #999;
}
.empty-state {
padding: 60px 0;
display: flex;
align-items: center;
justify-content: center;
}
.empty-text {
font-size: 14px;
color: #999;
}
.loading-state {
padding: 60px 0;
display: flex;
align-items: center;
justify-content: center;
}
.loading-text {
font-size: 14px;
color: #999;
}
.exchange-popup {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0, 0, 0, 0.5);
display: flex;
align-items: flex-end;
justify-content: center;
z-index: 1000;
}
.popup-content {
background-color: white;
border-radius: 16px 16px 0 0;
width: 100%;
padding: 16px;
}
.popup-header {
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
margin-bottom: 16px;
}
.popup-title {
font-size: 18px;
font-weight: bold;
color: #333;
}
.popup-close {
font-size: 24px;
color: #999;
}
.popup-product {
display: flex;
flex-direction: row;
padding: 12px;
background-color: #f9f9f9;
border-radius: 8px;
margin-bottom: 16px;
}
.popup-product-image {
width: 80px;
height: 80px;
border-radius: 4px;
}
.popup-product-info {
flex: 1;
margin-left: 12px;
display: flex;
flex-direction: column;
justify-content: center;
}
.popup-product-name {
font-size: 14px;
color: #333;
lines: 2;
}
.popup-product-points {
display: flex;
flex-direction: row;
align-items: center;
margin-top: 8px;
}
.popup-points-num {
font-size: 20px;
font-weight: bold;
color: #ff6b35;
}
.popup-points-unit {
font-size: 12px;
color: #ff6b35;
margin-left: 2px;
}
.popup-quantity {
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
padding: 12px 0;
border-bottom: 1px solid #f0f0f0;
}
.quantity-label {
font-size: 14px;
color: #333;
}
.quantity-control {
display: flex;
flex-direction: row;
align-items: center;
}
.quantity-btn {
width: 28px;
height: 28px;
background-color: #f5f5f5;
border-radius: 4px;
display: flex;
align-items: center;
justify-content: center;
font-size: 18px;
color: #666;
}
.quantity-value {
width: 40px;
text-align: center;
font-size: 16px;
color: #333;
}
.popup-summary {
padding: 12px 0;
}
.summary-row {
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
margin-bottom: 8px;
}
.summary-label {
font-size: 14px;
color: #666;
}
.summary-label.insufficient {
color: #ff6b35;
}
.summary-value {
font-size: 14px;
color: #333;
}
.summary-value.insufficient {
color: #ff6b35;
}
.popup-btn {
background: linear-gradient(135deg, #ff6b35 0%, #ff8c42 100%);
color: white;
font-size: 16px;
font-weight: bold;
border-radius: 24px;
height: 44px;
line-height: 44px;
margin-top: 16px;
}
.popup-btn.disabled {
background: #ccc;
}
.success-popup {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0, 0, 0, 0.5);
display: flex;
align-items: center;
justify-content: center;
z-index: 1001;
}
.success-content {
background-color: white;
border-radius: 16px;
padding: 32px;
width: 280px;
display: flex;
flex-direction: column;
align-items: center;
}
.success-icon {
width: 60px;
height: 60px;
background-color: #52c41a;
border-radius: 30px;
display: flex;
align-items: center;
justify-content: center;
font-size: 30px;
color: white;
margin-bottom: 16px;
}
.success-title {
font-size: 20px;
font-weight: bold;
color: #333;
margin-bottom: 8px;
}
.success-desc {
font-size: 14px;
color: #666;
margin-bottom: 24px;
}
.success-btn {
background-color: #ff6b35;
color: white;
font-size: 16px;
border-radius: 20px;
width: 100%;
height: 40px;
line-height: 40px;
}
</style>

View File

@@ -0,0 +1,654 @@
<template>
<scroll-view class="points-page" direction="vertical">
<view class="points-header">
<view class="points-info">
<text class="points-label">当前积分</text>
<text class="points-value">{{ totalPoints }}</text>
</view>
<view class="points-actions">
<button class="exchange-btn" @click="handleExchange">积分兑换</button>
</view>
</view>
<view class="quick-actions">
<view class="action-item" @click="goToSignin">
<view class="action-icon signin-icon">📅</view>
<text class="action-text">每日签到</text>
<view class="action-badge" v-if="!signedToday">
<text class="badge-text">+5</text>
</view>
<view class="signed-badge" v-else>
<text class="signed-text">已签</text>
</view>
</view>
<view class="action-item" @click="handleExchange">
<view class="action-icon exchange-icon">🎁</view>
<text class="action-text">积分兑换</text>
</view>
<view class="action-item" @click="goToMyReviews">
<view class="action-icon review-icon">⭐</view>
<text class="action-text">我的评价</text>
</view>
</view>
<view class="signin-card" v-if="!signedToday">
<view class="signin-info">
<text class="signin-title">今日未签到</text>
<text class="signin-desc">连续签到可获得额外奖励</text>
</view>
<button class="signin-btn" @click="goToSignin">去签到</button>
</view>
<view class="signin-card signed" v-else>
<view class="signin-info">
<text class="signin-title">今日已签到</text>
<text class="signin-desc">已连续签到 {{ continuousDays }} 天</text>
</view>
<text class="signed-icon">✓</text>
</view>
<view class="expiring-card" v-if="expiringPoints > 0" @click="showExpiringDetails">
<view class="expiring-icon">⚠️</view>
<view class="expiring-info">
<text class="expiring-title">{{ expiringPoints }} 积分即将过期</text>
<text class="expiring-date">过期日期:{{ expiringDate }}</text>
</view>
<text class="expiring-arrow"></text>
</view>
<view class="records-section">
<text class="section-title">积分明细</text>
<view v-if="loading" class="loading-state">
<text>加载中...</text>
</view>
<view v-else-if="records.length === 0" class="empty-state">
<text class="empty-text">暂无积分记录</text>
</view>
<view v-else class="record-list">
<view v-for="item in records" :key="item.id" class="record-item">
<view class="record-left">
<text class="record-title">{{ item.description ?? getTypeText(item.type) }}</text>
<text class="record-time">{{ formatTime(item.created_at) }}</text>
</view>
<view class="record-right">
<text class="record-amount" :class="{ positive: item.points > 0, negative: item.points < 0 }">
{{ item.points > 0 ? '+' : '' }}{{ item.points }}
</text>
</view>
</view>
</view>
</view>
<view class="expiring-popup" v-if="showExpiringPopup" @click="closeExpiringPopup">
<view class="popup-content" @click.stop>
<view class="popup-header">
<text class="popup-title">即将过期积分</text>
<text class="popup-close" @click="closeExpiringPopup">×</text>
</view>
<view class="popup-list">
<view class="popup-item" v-for="(detail, index) in expiringDetails" :key="index">
<view class="popup-item-info">
<text class="popup-item-points">+{{ detail.points }} 积分</text>
<text class="popup-item-desc">{{ detail.description ?? '积分获取' }}</text>
</view>
<view class="popup-item-expire">
<text class="popup-item-date">{{ formatDate(detail.expires_at) }}</text>
<text class="popup-item-label">过期</text>
</view>
</view>
</view>
<view class="popup-tip">
<text class="tip-text">积分有效期为获取后365天请及时使用避免过期</text>
</view>
</view>
</view>
</scroll-view>
</template>
<script setup lang="uts">
import { ref, onMounted } from 'vue'
import { supabaseService } from '@/utils/supabaseService.uts'
type PointRecord = {
id: string
user_id: string
points: number
type: string
description: string
created_at: string
}
type ExpiringDetail = {
points: number
description: string | null
expires_at: string
created_at: string
}
const totalPoints = ref<number>(0)
const records = ref<PointRecord[]>([])
const loading = ref<boolean>(true)
const signedToday = ref<boolean>(false)
const continuousDays = ref<number>(0)
const expiringPoints = ref<number>(0)
const expiringDate = ref<string>('')
const expiringDetails = ref<ExpiringDetail[]>([])
const showExpiringPopup = ref<boolean>(false)
const loadPoints = async (): Promise<void> => {
try {
const points = await supabaseService.getUserPoints()
totalPoints.value = points
} catch (e) {
console.error('获取积分失败', e)
}
}
const loadRecords = async (): Promise<void> => {
try {
const list = await supabaseService.getPointRecords()
records.value = list as PointRecord[]
} catch (e) {
console.error('获取积分记录失败', e)
}
}
const loadSigninStatus = async (): Promise<void> => {
try {
const status = await supabaseService.getTodaySigninStatus()
signedToday.value = status.getBoolean('signed') ?? false
continuousDays.value = status.getNumber('continuous_days') ?? 0
} catch (e) {
console.error('获取签到状态失败', e)
}
}
const loadExpiringPoints = async (): Promise<void> => {
try {
const result = await supabaseService.getExpiringPoints()
expiringPoints.value = result.getNumber('expiring_points') ?? 0
expiringDate.value = result.getString('expiring_date') ?? ''
const detailsRaw = result.get('details')
if (detailsRaw != null && Array.isArray(detailsRaw)) {
const details: ExpiringDetail[] = []
const arr = detailsRaw as any[]
for (let i = 0; i < arr.length; i++) {
const item = arr[i]
let itemObj: UTSJSONObject
if (item instanceof UTSJSONObject) {
itemObj = item
} else {
itemObj = JSON.parse(JSON.stringify(item)) as UTSJSONObject
}
details.push({
points: itemObj.getNumber('points') ?? 0,
description: itemObj.getString('description'),
expires_at: itemObj.getString('expires_at') ?? '',
created_at: itemObj.getString('created_at') ?? ''
})
}
expiringDetails.value = details
}
} catch (e) {
console.error('获取即将过期积分失败', e)
}
}
const loadData = async (): Promise<void> => {
loading.value = true
await Promise.all([
loadPoints(),
loadRecords(),
loadSigninStatus(),
loadExpiringPoints()
])
loading.value = false
}
onMounted(() => {
loadData()
})
const handleExchange = (): void => {
uni.navigateTo({
url: '/pages/mall/consumer/points/exchange'
})
}
const goToSignin = (): void => {
uni.navigateTo({
url: '/pages/mall/consumer/points/signin'
})
}
const goToMyReviews = (): void => {
uni.navigateTo({
url: '/pages/mall/consumer/my-reviews'
})
}
const showExpiringDetails = (): void => {
showExpiringPopup.value = true
}
const closeExpiringPopup = (): void => {
showExpiringPopup.value = false
}
const getTypeText = (type: string): string => {
if (type == 'signin') {
return '每日签到'
} else if (type == 'shopping') {
return '购物奖励'
} else if (type == 'redeem') {
return '积分兑换'
} else if (type == 'admin') {
return '系统调整'
} else if (type == 'register') {
return '注册赠送'
} else if (type == 'expire') {
return '积分过期'
} else {
return '积分变动'
}
}
const formatTime = (timeStr: string): string => {
if (timeStr == '') return ''
const date = new Date(timeStr)
const y = date.getFullYear()
const m = (date.getMonth() + 1).toString().padStart(2, '0')
const d = date.getDate().toString().padStart(2, '0')
const hh = date.getHours().toString().padStart(2, '0')
const mm = date.getMinutes().toString().padStart(2, '0')
return `${y}-${m}-${d} ${hh}:${mm}`
}
const formatDate = (dateStr: string): string => {
if (dateStr == '') return ''
const date = new Date(dateStr)
const y = date.getFullYear()
const m = (date.getMonth() + 1).toString().padStart(2, '0')
const d = date.getDate().toString().padStart(2, '0')
return `${y}-${m}-${d}`
}
</script>
<style>
.points-page {
flex: 1;
height: 100%;
background-color: #f5f5f5;
}
.points-header {
background: linear-gradient(135deg, #ff6b35 0%, #ff8c42 100%);
padding: 30px 20px;
color: white;
display: flex;
justify-content: space-between;
align-items: center;
}
.points-info {
display: flex;
flex-direction: column;
}
.points-label {
font-size: 14px;
opacity: 0.9;
margin-bottom: 8px;
}
.points-value {
font-size: 36px;
font-weight: bold;
}
.exchange-btn {
background-color: rgba(255,255,255,0.2);
color: white;
border: 1px solid rgba(255,255,255,0.4);
font-size: 14px;
border-radius: 20px;
padding: 0 15px;
height: 32px;
line-height: 32px;
}
.quick-actions {
display: flex;
flex-direction: row;
background-color: white;
padding: 16px 0;
margin-bottom: 8px;
}
.action-item {
flex: 1;
display: flex;
flex-direction: column;
align-items: center;
position: relative;
}
.action-icon {
width: 44px;
height: 44px;
border-radius: 22px;
display: flex;
align-items: center;
justify-content: center;
font-size: 20px;
margin-bottom: 6px;
}
.signin-icon {
background-color: #fff5f0;
}
.exchange-icon {
background-color: #f0f5ff;
}
.review-icon {
background-color: #fff5f0;
}
.action-text {
font-size: 12px;
color: #666;
}
.action-badge {
position: absolute;
top: 0;
right: 20px;
background-color: #ff6b35;
border-radius: 8px;
padding: 2px 6px;
}
.badge-text {
font-size: 10px;
color: white;
}
.signed-badge {
position: absolute;
top: 0;
right: 20px;
background-color: #52c41a;
border-radius: 8px;
padding: 2px 6px;
}
.signed-text {
font-size: 10px;
color: white;
}
.signin-card {
background-color: white;
margin: 0 12px 8px;
border-radius: 12px;
padding: 16px;
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
}
.signin-card.signed {
background: linear-gradient(135deg, #f6ffed 0%, #e6fffb 100%);
}
.signin-info {
display: flex;
flex-direction: column;
}
.signin-title {
font-size: 16px;
font-weight: bold;
color: #333;
}
.signin-desc {
font-size: 12px;
color: #999;
margin-top: 4px;
}
.signin-btn {
background-color: #ff6b35;
color: white;
font-size: 14px;
border-radius: 16px;
padding: 0 20px;
height: 32px;
line-height: 32px;
}
.signed-icon {
width: 32px;
height: 32px;
background-color: #52c41a;
border-radius: 16px;
display: flex;
align-items: center;
justify-content: center;
font-size: 16px;
color: white;
}
.expiring-card {
background: linear-gradient(135deg, #fff7e6 0%, #ffe7ba 100%);
margin: 0 12px 8px;
border-radius: 12px;
padding: 14px 16px;
display: flex;
flex-direction: row;
align-items: center;
}
.expiring-icon {
font-size: 24px;
margin-right: 12px;
}
.expiring-info {
flex: 1;
display: flex;
flex-direction: column;
}
.expiring-title {
font-size: 14px;
font-weight: bold;
color: #d48806;
}
.expiring-date {
font-size: 12px;
color: #ad8b00;
margin-top: 2px;
}
.expiring-arrow {
font-size: 20px;
color: #d48806;
}
.records-section {
background-color: white;
padding: 0 16px;
min-height: 300px;
}
.section-title {
font-size: 16px;
font-weight: bold;
padding: 16px 0;
border-bottom: 1px solid #f0f0f0;
display: flex;
}
.record-item {
display: flex;
justify-content: space-between;
align-items: center;
padding: 16px 0;
border-bottom: 1px solid #f9f9f9;
}
.record-left {
display: flex;
flex-direction: column;
}
.record-title {
margin-bottom: 4px;
font-size: 15px;
color: #333;
}
.record-time {
font-size: 12px;
color: #999;
}
.record-amount {
font-size: 16px;
font-weight: bold;
color: #333;
}
.record-amount.positive {
color: #ff6b35;
}
.record-amount.negative {
color: #333;
}
.empty-state {
padding: 40px 0;
display: flex;
justify-content: center;
}
.empty-text {
color: #999;
font-size: 14px;
}
.loading-state {
padding: 40px 0;
display: flex;
justify-content: center;
}
.expiring-popup {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0, 0, 0, 0.5);
display: flex;
align-items: flex-end;
justify-content: center;
z-index: 1000;
}
.popup-content {
background-color: white;
border-radius: 16px 16px 0 0;
width: 100%;
max-height: 400px;
padding: 16px;
}
.popup-header {
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
margin-bottom: 16px;
}
.popup-title {
font-size: 18px;
font-weight: bold;
color: #333;
}
.popup-close {
font-size: 24px;
color: #999;
}
.popup-list {
max-height: 300px;
}
.popup-item {
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
padding: 12px 0;
border-bottom: 1px solid #f0f0f0;
}
.popup-item-info {
display: flex;
flex-direction: column;
}
.popup-item-points {
font-size: 14px;
font-weight: bold;
color: #ff6b35;
}
.popup-item-desc {
font-size: 12px;
color: #999;
margin-top: 2px;
}
.popup-item-expire {
display: flex;
flex-direction: column;
align-items: flex-end;
}
.popup-item-date {
font-size: 12px;
color: #d48806;
}
.popup-item-label {
font-size: 10px;
color: #999;
}
.popup-tip {
margin-top: 16px;
padding: 12px;
background-color: #f9f9f9;
border-radius: 8px;
}
.tip-text {
font-size: 12px;
color: #666;
}
</style>

View File

@@ -0,0 +1,562 @@
<template>
<view class="signin-page">
<view class="header">
<view class="header-content">
<text class="title">每日签到</text>
<text class="subtitle">连续签到可获得额外奖励</text>
</view>
<view class="points-display">
<text class="points-label">当前积分</text>
<text class="points-value">{{ totalPoints }}</text>
</view>
</view>
<view class="calendar-section">
<view class="calendar-header">
<view class="month-nav">
<text class="nav-btn" @click="prevMonth">&lt;</text>
<text class="current-month">{{ currentYear }}年{{ currentMonth }}月</text>
<text class="nav-btn" @click="nextMonth">&gt;</text>
</view>
<view class="continuous-info">
<text class="continuous-label">已连续签到</text>
<text class="continuous-value">{{ continuousDays }}天</text>
</view>
</view>
<view class="calendar-weekdays">
<text class="weekday" v-for="day in weekdays" :key="day">{{ day }}</text>
</view>
<view class="calendar-days">
<view
v-for="(day, index) in calendarDays"
:key="index"
class="day-cell"
:class="{
'empty': day.day === 0,
'signed': day.signed,
'today': day.isToday
}"
>
<text v-if="day.day > 0" class="day-number">{{ day.day }}</text>
<view v-if="day.signed" class="signed-mark">
<text class="check-icon">✓</text>
</view>
</view>
</view>
</view>
<view class="signin-btn-section">
<button
class="signin-btn"
:class="{ 'signed-today': signedToday }"
:disabled="signedToday"
@click="doSignin"
>
{{ signedToday ? '今日已签到' : '立即签到' }}
</button>
</view>
<view class="rules-section">
<text class="section-title">签到规则</text>
<view class="rule-list">
<view class="rule-item">
<text class="rule-icon">📅</text>
<text class="rule-text">每日签到可获得5积分</text>
</view>
<view class="rule-item">
<text class="rule-icon">🔥</text>
<text class="rule-text">连续签到7天额外奖励20积分</text>
</view>
<view class="rule-item">
<text class="rule-icon">🏆</text>
<text class="rule-text">连续签到30天额外奖励100积分</text>
</view>
<view class="rule-item">
<text class="rule-icon">⚠️</text>
<text class="rule-text">中断签到后连续天数将重置</text>
</view>
</view>
</view>
<view class="signin-popup" v-if="showPopup" @click="closePopup">
<view class="popup-content" @click.stop>
<view class="popup-icon">🎉</view>
<text class="popup-title">签到成功</text>
<view class="popup-points">
<text class="popup-points-label">获得积分</text>
<text class="popup-points-value">+{{ popupPoints }}</text>
</view>
<view class="popup-bonus" v-if="popupBonus > 0">
<text class="popup-bonus-label">连续签到奖励</text>
<text class="popup-bonus-value">+{{ popupBonus }}</text>
</view>
<view class="popup-continuous">
<text>已连续签到 {{ popupContinuousDays }} 天</text>
</view>
<button class="popup-btn" @click="closePopup">确定</button>
</view>
</view>
</view>
</template>
<script setup lang="uts">
import { ref, onMounted, computed } from 'vue'
import { supabaseService } from '@/utils/supabaseService.uts'
type CalendarDay = {
day: number
signed: boolean
isToday: boolean
}
const totalPoints = ref<number>(0)
const continuousDays = ref<number>(0)
const signedToday = ref<boolean>(false)
const currentYear = ref<number>(new Date().getFullYear())
const currentMonth = ref<number>(new Date().getMonth() + 1)
const signinRecords = ref<string[]>([])
const showPopup = ref<boolean>(false)
const popupPoints = ref<number>(0)
const popupBonus = ref<number>(0)
const popupContinuousDays = ref<number>(0)
const weekdays: string[] = ['日', '一', '二', '三', '四', '五', '六']
const calendarDays = computed((): CalendarDay[] => {
const days: CalendarDay[] = []
const year = currentYear.value
const month = currentMonth.value
const firstDay = new Date(year, month - 1, 1).getDay()
const daysInMonth = new Date(year, month, 0).getDate()
const today = new Date()
const todayStr = today.toISOString().split('T')[0]
for (let i = 0; i < firstDay; i++) {
days.push({ day: 0, signed: false, isToday: false })
}
for (let i = 1; i <= daysInMonth; i++) {
const dateStr = `${year}-${month.toString().padStart(2, '0')}-${i.toString().padStart(2, '0')}`
const isToday = dateStr === todayStr
const signed = signinRecords.value.includes(dateStr)
days.push({ day: i, signed, isToday })
}
return days
})
const loadSigninData = async (): Promise<void> => {
uni.showLoading({ title: '加载中...' })
try {
const points = await supabaseService.getUserPoints()
totalPoints.value = points
const status = await supabaseService.getTodaySigninStatus()
signedToday.value = status.getBoolean('signed') ?? false
continuousDays.value = status.getNumber('continuous_days') ?? 0
const records = await supabaseService.getSigninRecords(currentYear.value, currentMonth.value)
const dates: string[] = []
for (let i = 0; i < records.length; i++) {
const record = records[i]
let dateStr = ''
if (record instanceof UTSJSONObject) {
dateStr = record.getString('signin_date') ?? ''
} else {
const rObj = JSON.parse(JSON.stringify(record)) as UTSJSONObject
dateStr = rObj.getString('signin_date') ?? ''
}
if (dateStr !== '') {
dates.push(dateStr)
}
}
signinRecords.value = dates
} catch (e) {
console.error('加载签到数据失败:', e)
} finally {
uni.hideLoading()
}
}
const doSignin = async (): Promise<void> => {
if (signedToday.value) return
uni.showLoading({ title: '签到中...' })
try {
const result = await supabaseService.signin()
if (result.getBoolean('success') === true) {
popupPoints.value = result.getNumber('points') ?? 0
popupBonus.value = result.getNumber('bonus_points') ?? 0
popupContinuousDays.value = result.getNumber('continuous_days') ?? 0
totalPoints.value = result.getNumber('total_points') ?? 0
continuousDays.value = popupContinuousDays.value
signedToday.value = true
const today = new Date().toISOString().split('T')[0]
signinRecords.value.push(today)
showPopup.value = true
} else {
const message = result.getString('message') ?? '签到失败'
uni.showToast({ title: message, icon: 'none' })
}
} catch (e) {
console.error('签到异常:', e)
uni.showToast({ title: '签到异常', icon: 'none' })
} finally {
uni.hideLoading()
}
}
const closePopup = (): void => {
showPopup.value = false
}
const prevMonth = (): void => {
if (currentMonth.value === 1) {
currentYear.value--
currentMonth.value = 12
} else {
currentMonth.value--
}
loadSigninData()
}
const nextMonth = (): void => {
if (currentMonth.value === 12) {
currentYear.value++
currentMonth.value = 1
} else {
currentMonth.value++
}
loadSigninData()
}
onMounted(() => {
loadSigninData()
})
</script>
<style>
.signin-page {
flex: 1;
background-color: #f5f5f5;
}
.header {
background: linear-gradient(135deg, #ff6b35 0%, #ff8c42 100%);
padding: 20px 16px;
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
}
.header-content {
display: flex;
flex-direction: column;
}
.title {
font-size: 24px;
font-weight: bold;
color: white;
}
.subtitle {
font-size: 12px;
color: rgba(255, 255, 255, 0.8);
margin-top: 4px;
}
.points-display {
background-color: rgba(255, 255, 255, 0.2);
border-radius: 12px;
padding: 10px 16px;
display: flex;
flex-direction: column;
align-items: center;
}
.points-label {
font-size: 12px;
color: rgba(255, 255, 255, 0.8);
}
.points-value {
font-size: 24px;
font-weight: bold;
color: white;
}
.calendar-section {
background-color: white;
margin: 12px;
border-radius: 12px;
padding: 16px;
}
.calendar-header {
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
margin-bottom: 16px;
}
.month-nav {
display: flex;
flex-direction: row;
align-items: center;
}
.nav-btn {
font-size: 18px;
color: #666;
padding: 4px 12px;
}
.current-month {
font-size: 16px;
font-weight: bold;
color: #333;
margin: 0 8px;
}
.continuous-info {
display: flex;
flex-direction: row;
align-items: center;
background-color: #fff5f0;
padding: 4px 12px;
border-radius: 16px;
}
.continuous-label {
font-size: 12px;
color: #ff6b35;
}
.continuous-value {
font-size: 14px;
font-weight: bold;
color: #ff6b35;
margin-left: 4px;
}
.calendar-weekdays {
display: flex;
flex-direction: row;
margin-bottom: 8px;
}
.weekday {
flex: 1;
text-align: center;
font-size: 12px;
color: #999;
padding: 8px 0;
}
.calendar-days {
display: flex;
flex-direction: row;
flex-wrap: wrap;
}
.day-cell {
width: 14.28%;
height: 45px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
position: relative;
}
.day-cell.empty {
background-color: transparent;
}
.day-number {
font-size: 14px;
color: #333;
}
.day-cell.today .day-number {
color: #ff6b35;
font-weight: bold;
}
.day-cell.signed {
background-color: #fff5f0;
border-radius: 8px;
}
.signed-mark {
position: absolute;
bottom: 2px;
width: 16px;
height: 16px;
background-color: #ff6b35;
border-radius: 8px;
display: flex;
align-items: center;
justify-content: center;
}
.check-icon {
font-size: 10px;
color: white;
}
.signin-btn-section {
padding: 16px;
}
.signin-btn {
background: linear-gradient(135deg, #ff6b35 0%, #ff8c42 100%);
color: white;
font-size: 18px;
font-weight: bold;
border-radius: 24px;
height: 48px;
line-height: 48px;
}
.signin-btn.signed-today {
background: #ccc;
}
.rules-section {
background-color: white;
margin: 12px;
border-radius: 12px;
padding: 16px;
}
.section-title {
font-size: 16px;
font-weight: bold;
color: #333;
margin-bottom: 12px;
}
.rule-list {
display: flex;
flex-direction: column;
}
.rule-item {
display: flex;
flex-direction: row;
align-items: center;
padding: 8px 0;
}
.rule-icon {
font-size: 16px;
margin-right: 8px;
}
.rule-text {
font-size: 14px;
color: #666;
}
.signin-popup {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0, 0, 0, 0.5);
display: flex;
align-items: center;
justify-content: center;
z-index: 1000;
}
.popup-content {
background-color: white;
border-radius: 16px;
padding: 24px;
width: 280px;
display: flex;
flex-direction: column;
align-items: center;
}
.popup-icon {
font-size: 48px;
margin-bottom: 12px;
}
.popup-title {
font-size: 20px;
font-weight: bold;
color: #333;
margin-bottom: 16px;
}
.popup-points {
display: flex;
flex-direction: row;
align-items: center;
margin-bottom: 8px;
}
.popup-points-label {
font-size: 14px;
color: #666;
}
.popup-points-value {
font-size: 24px;
font-weight: bold;
color: #ff6b35;
margin-left: 8px;
}
.popup-bonus {
display: flex;
flex-direction: row;
align-items: center;
margin-bottom: 8px;
}
.popup-bonus-label {
font-size: 14px;
color: #666;
}
.popup-bonus-value {
font-size: 20px;
font-weight: bold;
color: #ff6b35;
margin-left: 8px;
}
.popup-continuous {
font-size: 14px;
color: #999;
margin-bottom: 16px;
}
.popup-btn {
background-color: #ff6b35;
color: white;
font-size: 16px;
border-radius: 20px;
width: 100%;
height: 40px;
line-height: 40px;
}
</style>