consumerm模块完成度90%,完善消费者和商家端数据库表,商品、聊天、订单数据对接好了supabase,和商家端对接了聊天功能,安卓端编译通过了css样式,剩余几个页面在处理函数规范问题
This commit is contained in:
@@ -22,61 +22,71 @@
|
||||
|
||||
<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 orderNo = ref('')
|
||||
const amount = ref(0)
|
||||
|
||||
// 定义 loadOrderInfo 函数(必须在 onMounted 之前)
|
||||
const loadOrderInfo = async () => {
|
||||
try {
|
||||
const response = await supabaseService.getOrderById(orderId.value)
|
||||
console.log('[payment-success] getOrderById response:', JSON.stringify(response))
|
||||
|
||||
if (response != null) {
|
||||
const orderData = response as UTSJSONObject
|
||||
const totalAmount = orderData.getNumber('total_amount')
|
||||
const paidAmount = orderData.getNumber('paid_amount')
|
||||
console.log('[payment-success] total_amount:', totalAmount, 'paid_amount:', paidAmount)
|
||||
|
||||
if (paidAmount != null && paidAmount > 0) {
|
||||
amount.value = paidAmount
|
||||
} else if (totalAmount != null && totalAmount > 0) {
|
||||
amount.value = totalAmount
|
||||
}
|
||||
|
||||
const orderNoVal = orderData.getString('order_no')
|
||||
if (orderNoVal != null && orderNoVal != '') {
|
||||
orderNo.value = orderNoVal
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('[payment-success] 加载订单信息失败:', err)
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
const pages = getCurrentPages()
|
||||
const currentPage = pages[pages.length - 1]
|
||||
const options = currentPage.options as any
|
||||
const options = currentPage.options as Record<string, any>
|
||||
|
||||
if (options.orderId) {
|
||||
orderId.value = options.orderId
|
||||
orderNo.value = options.orderId // 使用订单ID作为订单号
|
||||
console.log('[payment-success] options:', JSON.stringify(options))
|
||||
|
||||
const orderIdValue = options['orderId']
|
||||
if (orderIdValue != null) {
|
||||
orderId.value = orderIdValue as string
|
||||
orderNo.value = orderIdValue as string
|
||||
|
||||
// 优先使用传递的 amount
|
||||
if (options.amount) {
|
||||
amount.value = parseFloat(options.amount)
|
||||
} else {
|
||||
// 如果没有传 amount,尝试从本地存储查找订单
|
||||
try {
|
||||
const ordersStr = uni.getStorageSync('orders')
|
||||
if (ordersStr) {
|
||||
const orders = JSON.parse(ordersStr as string) as any[]
|
||||
const order = orders.find((o: any) => o.id === orderId.value)
|
||||
if (order) {
|
||||
amount.value = order.actual_amount || order.total_amount || 0
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('读取本地订单失败', e)
|
||||
const amountValue = options['amount']
|
||||
if (amountValue != null) {
|
||||
const amountStr = amountValue.toString()
|
||||
console.log('[payment-success] amountStr:', amountStr)
|
||||
const parsed = parseFloat(amountStr)
|
||||
console.log('[payment-success] parsed:', parsed)
|
||||
if (isNaN(parsed) == false) {
|
||||
amount.value = parsed
|
||||
}
|
||||
}
|
||||
|
||||
// loadOrderInfo() // 暂时注释掉数据库查询
|
||||
if (amount.value == 0) {
|
||||
console.log('[payment-success] amount为0,尝试从数据库查询')
|
||||
}
|
||||
|
||||
loadOrderInfo()
|
||||
}
|
||||
})
|
||||
|
||||
// const loadOrderInfo = async () => {
|
||||
// try {
|
||||
// const { data, error } = await supa
|
||||
// .from('orders')
|
||||
// .select('order_no, actual_amount')
|
||||
// .eq('id', orderId.value)
|
||||
// .single()
|
||||
//
|
||||
// if (error == null && data != null) {
|
||||
// orderNo.value = data['order_no'] as string
|
||||
// amount.value = data['actual_amount'] as number
|
||||
// }
|
||||
// } catch (err) {
|
||||
// console.error('加载订单信息失败', err)
|
||||
// }
|
||||
// }
|
||||
|
||||
const viewOrder = () => {
|
||||
uni.navigateTo({
|
||||
url: '/pages/mall/consumer/orders'
|
||||
@@ -96,7 +106,8 @@ const goHome = () => {
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
height: 100vh;
|
||||
/* height: 100vh; */
|
||||
flex: 1;
|
||||
background-color: #ffffff;
|
||||
padding: 0 30px;
|
||||
}
|
||||
@@ -162,7 +173,7 @@ const goHome = () => {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 15px;
|
||||
/* gap: 15px; */
|
||||
}
|
||||
|
||||
.btn {
|
||||
@@ -174,6 +185,7 @@ const goHome = () => {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.primary-btn {
|
||||
|
||||
Reference in New Issue
Block a user