consumer模块完成90%,前端完成supabase对接
This commit is contained in:
@@ -101,7 +101,7 @@
|
||||
|
||||
<script setup lang="uts">
|
||||
import { ref, onMounted, watch } from 'vue'
|
||||
import supa from '@/components/supadb/aksupainstance.uts'
|
||||
import { supabaseService } from '@/utils/supabaseService.uts'
|
||||
|
||||
type RefundType = {
|
||||
id: string
|
||||
@@ -187,40 +187,48 @@ const loadRefunds = async (loadMore: boolean = false) => {
|
||||
|
||||
const page = loadMore ? currentPage.value + 1 : 1
|
||||
|
||||
let query = supa
|
||||
.from('refunds')
|
||||
.select(`
|
||||
*,
|
||||
order:order_id(
|
||||
order_no,
|
||||
created_at,
|
||||
order_items(
|
||||
*,
|
||||
product:product_id(images)
|
||||
)
|
||||
)
|
||||
`)
|
||||
.eq('user_id', userId)
|
||||
.order('created_at', { ascending: false })
|
||||
|
||||
// 根据标签页过滤
|
||||
let statusList: number[] = []
|
||||
if (activeTab.value === 'processing') {
|
||||
query = query.in('status', [1, 2]) // 待处理和处理中
|
||||
statusList = [1, 2] // 待处理和处理中
|
||||
} else if (activeTab.value === 'completed') {
|
||||
query = query.in('status', [3, 4, 5]) // 已完成、已取消、已拒绝
|
||||
statusList = [3, 4, 5] // 已完成、已取消、已拒绝
|
||||
}
|
||||
|
||||
// 分页
|
||||
query = query.range((page - 1) * pageSize.value, page * pageSize.value - 1)
|
||||
|
||||
const { data, error } = await query
|
||||
|
||||
if (error !== null) {
|
||||
console.error('加载售后记录失败:', error)
|
||||
return
|
||||
}
|
||||
|
||||
const newRefunds = data || []
|
||||
|
||||
const rawData = await supabaseService.getRefunds(statusList, page, pageSize.value)
|
||||
|
||||
// Map data to UI structure (RefundType)
|
||||
const newRefunds = rawData.map((item: any): RefundType => {
|
||||
const orderObj = item.order || {}
|
||||
const dbItems = orderObj.ml_order_items || []
|
||||
const uiItems = dbItems.map((di: any) : any => ({
|
||||
id: di.id || '',
|
||||
product_name: di.product_name,
|
||||
sku_specifications: di.specifications,
|
||||
price: 0,
|
||||
quantity: di.quantity || 1,
|
||||
product: { images: [di.image_url || '/static/default-product.png'] }
|
||||
}))
|
||||
|
||||
return {
|
||||
id: item.id,
|
||||
user_id: item.user_id,
|
||||
order_id: item.order_id,
|
||||
refund_no: item.refund_no,
|
||||
refund_type: item.refund_type,
|
||||
refund_reason: item.refund_reason,
|
||||
refund_amount: Number(item.refund_amount),
|
||||
status: item.status,
|
||||
// Handle missing timeline by defaulting or leaving empty
|
||||
status_history: item.status_history || [],
|
||||
created_at: item.created_at,
|
||||
order: {
|
||||
id: item.order_id,
|
||||
order_no: orderObj.order_no,
|
||||
created_at: orderObj.created_at,
|
||||
order_items: uiItems
|
||||
}
|
||||
} as RefundType
|
||||
})
|
||||
|
||||
if (loadMore) {
|
||||
refunds.value.push(...newRefunds)
|
||||
|
||||
Reference in New Issue
Block a user