继续完善购物逻辑闭环,consumer模块完成度75%

This commit is contained in:
2026-01-26 17:15:51 +08:00
parent be90f1213b
commit f2f208f258
21 changed files with 2516 additions and 217 deletions

View File

@@ -147,6 +147,8 @@
<script setup lang="uts">
import { ref, reactive, onMounted, computed } from 'vue'
import { onShow, onLoad } from '@dcloudio/uni-app'
// // import supa from '@/components/supadb/aksupainstance.uts'
// 响应式数据
const orders = ref<any[]>([])
@@ -317,19 +319,96 @@ const filteredOrders = computed(() => {
})
// 生命周期
onMounted(() => {
onLoad((options) => {
if (options['status']) {
const status = options['status'] as string
if (['all', 'pending', 'shipping', 'delivering', 'completed', 'cancelled'].includes(status)) {
activeTab.value = status
}
}
if (options['type']) {
const type = options['type'] as string
if (type === 'pending') activeTab.value = 'pending'
else if (type === 'shipped') activeTab.value = 'delivering' // 映射到待收货
else if (type === 'review') activeTab.value = 'completed' // 映射到已完成
}
})
onShow(() => {
loadOrders()
})
// 加载订单数据
const loadOrders = () => {
const loadOrders = async () => {
loading.value = true
const userStore = uni.getStorageSync('userInfo')
const userId = userStore?.id
// 模拟API请求延迟
setTimeout(() => {
orders.value = [...mockOrders]
if (!userId) {
loading.value = false
}, 800)
return
}
try {
// Mock Data Loading
await new Promise(resolve => setTimeout(resolve, 500)) // Simulate network delay
// Use filtered mock orders based on user ID logic if needed, but for now just return all mock orders
// In a real app we'd filter by userId
/* const { data, error } = await supa
.from('orders')
.select('*, order_items(*)')
.eq('user_id', userId)
.order('created_at', { ascending: false })
if (error != null) {
console.error('加载订单失败:', error)
return
}
if (data != null) {
orders.value = data.map((order: any) => ({
id: order.id,
order_no: order.order_no,
status: order.status,
create_time: formatDate(order.created_at),
product_amount: order.total_amount,
shipping_fee: order.delivery_fee,
total_amount: order.actual_amount,
products: (order.order_items as any[]).map((item: any) => ({
id: item.product_id,
name: item.product_name,
price: item.price,
image: '/static/products/1.jpg', // 默认图片
spec: formatSpec(item.sku_specifications),
quantity: item.quantity
}))
}))
} */
// Using Mock Data
orders.value = mockOrders
} catch (err) {
console.error('加载订单异常:', err)
} finally {
loading.value = false
}
}
const formatDate = (isoString: string): string => {
if (!isoString) return ''
const date = new Date(isoString)
return `${date.getFullYear()}-${(date.getMonth()+1).toString().padStart(2, '0')}-${date.getDate().toString().padStart(2, '0')} ${date.getHours().toString().padStart(2, '0')}:${date.getMinutes().toString().padStart(2, '0')}`
}
const formatSpec = (specs: any): string => {
if (!specs) return ''
if (typeof specs === 'object') {
return Object.keys(specs).map(key => `${key}:${specs[key]}`).join(' ')
}
return String(specs)
}
// 切换标签
@@ -381,21 +460,8 @@ const onRefresh = () => {
const loadMore = () => {
if (loadingMore.value || !hasMore.value) return
loadingMore.value = true
// 模拟加载更多数据
setTimeout(() => {
const newOrders = [...mockOrders].map((order, index) => ({
...order,
id: `${order.id}_${page.value}${index}`,
order_no: `${order.order_no}_${page.value}${index}`
}))
orders.value = [...orders.value, ...newOrders]
loadingMore.value = false
page.value++
hasMore.value = orders.value.length < 20
}, 1200)
// 暂未实现分页,直接返回
hasMore.value = false
}
// 订单操作函数