继续完善购物逻辑闭环,consumer模块完成度75%
This commit is contained in:
@@ -248,6 +248,7 @@
|
||||
|
||||
<script>
|
||||
import { UserType, OrderType } from '@/types/mall-types.uts'
|
||||
// import { supabase as supa } from '@/components/supadb/aksupainstance.uts'
|
||||
|
||||
type UserStatsType = {
|
||||
points: number
|
||||
@@ -330,7 +331,10 @@ export default {
|
||||
onLoad() {
|
||||
this.initPage()
|
||||
this.loadUserProfile()
|
||||
this.loadMockOrders() // 加载Mock订单数据
|
||||
this.loadOrders()
|
||||
},
|
||||
onShow() {
|
||||
this.refreshData()
|
||||
},
|
||||
computed: {
|
||||
// 根据当前Tab筛选订单
|
||||
@@ -348,100 +352,47 @@ export default {
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
// 加载Mock订单数据
|
||||
loadMockOrders() {
|
||||
// 创建Mock数据
|
||||
const mockData: Array<OrderType> = [
|
||||
// 待支付订单
|
||||
{
|
||||
id: 'order_001',
|
||||
order_no: 'ORD202401250001',
|
||||
user_id: 'user_001',
|
||||
merchant_id: 'merchant_001',
|
||||
status: 1, // 待支付
|
||||
total_amount: 299.00,
|
||||
discount_amount: 30.00,
|
||||
delivery_fee: 0.00,
|
||||
actual_amount: 269.00,
|
||||
payment_method: 1,
|
||||
payment_status: 0,
|
||||
delivery_address: {},
|
||||
created_at: '2024-01-25T14:30:00'
|
||||
},
|
||||
// 待发货
|
||||
{
|
||||
id: 'order_002',
|
||||
order_no: 'ORD202401240002',
|
||||
user_id: 'user_001',
|
||||
merchant_id: 'merchant_002',
|
||||
status: 2, // 待发货
|
||||
total_amount: 158.00,
|
||||
discount_amount: 0,
|
||||
delivery_fee: 6.00,
|
||||
actual_amount: 164.00,
|
||||
payment_method: 1,
|
||||
payment_status: 1,
|
||||
delivery_address: {},
|
||||
created_at: '2024-01-24T09:20:00'
|
||||
},
|
||||
// 待收货
|
||||
{
|
||||
id: 'order_003',
|
||||
order_no: 'ORD202401230003',
|
||||
user_id: 'user_001',
|
||||
merchant_id: 'merchant_001',
|
||||
status: 3, // 待收货
|
||||
total_amount: 89.90,
|
||||
discount_amount: 10.00,
|
||||
delivery_fee: 0.00,
|
||||
actual_amount: 79.90,
|
||||
payment_method: 1,
|
||||
payment_status: 1,
|
||||
delivery_address: {},
|
||||
created_at: '2024-01-23T18:15:00'
|
||||
},
|
||||
// 待评价 (已完成)
|
||||
{
|
||||
id: 'order_004',
|
||||
order_no: 'ORD202401200004',
|
||||
user_id: 'user_001',
|
||||
merchant_id: 'merchant_003',
|
||||
status: 4, // 待评价
|
||||
total_amount: 399.00,
|
||||
discount_amount: 50.00,
|
||||
delivery_fee: 0.00,
|
||||
actual_amount: 349.00,
|
||||
payment_method: 1,
|
||||
payment_status: 1,
|
||||
delivery_address: {},
|
||||
created_at: '2024-01-20T11:30:00'
|
||||
},
|
||||
// 已完成 (已评价)
|
||||
{
|
||||
id: 'order_005',
|
||||
order_no: 'ORD202401180005',
|
||||
user_id: 'user_001',
|
||||
merchant_id: 'merchant_001',
|
||||
status: 5, // 已完成
|
||||
total_amount: 128.00,
|
||||
discount_amount: 0,
|
||||
delivery_fee: 0.00,
|
||||
actual_amount: 128.00,
|
||||
payment_method: 1,
|
||||
payment_status: 1,
|
||||
delivery_address: {},
|
||||
created_at: '2024-01-18T16:45:00'
|
||||
// 加载订单数据
|
||||
async loadOrders() {
|
||||
const userStore = uni.getStorageSync('userInfo')
|
||||
const userId = userStore?.id
|
||||
if (!userId) return
|
||||
|
||||
try {
|
||||
/* const { data, error } = await supa
|
||||
.from('orders')
|
||||
.select('*')
|
||||
.eq('user_id', userId)
|
||||
.order('created_at', { ascending: false })
|
||||
|
||||
if (error != null) {
|
||||
console.error('加载订单失败', error)
|
||||
return
|
||||
}
|
||||
]
|
||||
this.allOrders = mockData
|
||||
this.recentOrders = mockData // 初始显示全部
|
||||
|
||||
// 更新角标统计
|
||||
this.orderCounts = {
|
||||
total: mockData.length,
|
||||
pending: mockData.filter((o: OrderType): boolean => o.status === 1).length,
|
||||
shipped: mockData.filter((o: OrderType): boolean => o.status === 2 || o.status === 3).length,
|
||||
review: mockData.filter((o: OrderType): boolean => o.status === 4).length
|
||||
|
||||
if (data != null) {
|
||||
this.allOrders = data as any[]
|
||||
this.recentOrders = this.allOrders
|
||||
|
||||
// 更新角标统计
|
||||
this.orderCounts = {
|
||||
total: this.allOrders.length,
|
||||
pending: this.allOrders.filter((o: any) => o.status === 1).length,
|
||||
shipped: this.allOrders.filter((o: any) => o.status === 2 || o.status === 3).length,
|
||||
review: this.allOrders.filter((o: any) => o.status === 4).length
|
||||
}
|
||||
} */
|
||||
|
||||
// MOCK ORDERS
|
||||
this.allOrders = this.recentOrders
|
||||
this.orderCounts = {
|
||||
total: this.allOrders.length,
|
||||
pending: this.allOrders.filter((o: any) => o.status === 1).length,
|
||||
shipped: this.allOrders.filter((o: any) => o.status === 2 || o.status === 3).length,
|
||||
review: this.allOrders.filter((o: any) => o.status === 4).length
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('加载订单异常', e)
|
||||
}
|
||||
},
|
||||
|
||||
@@ -568,7 +519,7 @@ export default {
|
||||
refreshData() {
|
||||
// 刷新页面数据
|
||||
this.loadUserProfile()
|
||||
this.loadMockOrders() // 加载Mock订单数据
|
||||
this.loadOrders()
|
||||
this.updateCouponCount() // 更新优惠券数量
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user