consumer模块完成90%,前端完成supabase对接

This commit is contained in:
2026-02-03 17:11:50 +08:00
parent b6200cda28
commit 8a535e3f38
69 changed files with 5020 additions and 33273 deletions

View File

@@ -57,7 +57,7 @@
<script setup lang="uts">
import { ref, onMounted } from 'vue'
// import supa from '@/components/supadb/aksupainstance.uts'
import { supabaseService } from '@/utils/supabaseService.uts'
const orderId = ref('')
const orderItemId = ref('') // Optional, if refunding specific item
@@ -92,19 +92,22 @@ onMounted(() => {
const loadOrderInfo = async () => {
try {
const { data, error } = await supa
.from('orders')
.select('actual_amount, delivery_fee')
.eq('id', orderId.value)
.single()
const orderData = await supabaseService.getOrderDetail(orderId.value)
if (error == null && data != null) {
maxAmount.value = data['actual_amount'] as number
deliveryFee.value = data['delivery_fee'] as number
if (orderData != null) {
const total = Number(orderData['total_amount'] ?? 0)
const shipping = Number(orderData['shipping_fee'] ?? 0)
maxAmount.value = total
deliveryFee.value = shipping
refundAmount.value = maxAmount.value.toString()
}
} catch (err) {
console.error('加载订单信息失败', err)
uni.showToast({
title: '加载订单失败',
icon: 'none'
})
}
}
@@ -132,53 +135,29 @@ const submitRefund = async () => {
submitting.value = true
try {
const userStore = uni.getStorageSync('userInfo')
const userId = userStore?.id
// 1. Create Refund Record
/* const { data, error } = await supa
.from('refunds')
.insert({
user_id: userId,
order_id: orderId.value,
refund_no: 'REF' + Date.now(),
refund_type: refundType.value,
refund_reason: refundReason.value,
refund_amount: amount,
description: description.value,
status: 1, // 待处理
status_history: [{
status: 1,
remark: '用户提交申请',
created_at: new Date().toISOString()
}]
})
if (error != null) throw error */
// MOCK SUBMIT
await new Promise(resolve => setTimeout(resolve, 1000))
// 2. Update Order Status (Optional, e.g. to "After-sales")
// Assuming status 6 is "After-sales/Refund"
/*
await supa
.from('orders')
.update({ status: 6 })
.eq('id', orderId.value)
*/
uni.showToast({ title: '提交成功', icon: 'success' })
setTimeout(() => {
uni.redirectTo({
url: '/pages/mall/consumer/refund'
})
}, 1500)
const result = await supabaseService.createRefund({
order_id: orderId.value,
refund_type: refundType.value,
refund_reason: refundReason.value,
refund_amount: amount,
description: description.value
})
if (result.success) {
uni.showToast({ title: '提交成功', icon: 'success' })
setTimeout(() => {
// Go back to orders listing focused on refund type?
// or stay here? User probably wants to see list.
// Since profile redirects "Refunds" to orders list, let's go there.
uni.navigateBack()
}, 1500)
} else {
uni.showToast({ title: result.message, icon: 'none' })
}
} catch (err) {
console.error('提交退款失败', err)
uni.showToast({ title: '提交失败,请重试', icon: 'none' })
uni.showToast({ title: '提交异常', icon: 'none' })
} finally {
submitting.value = false
}