consumer模块完成度95%,安卓端大部分页面能正常获取数据,页面样式显示基本正常,逐渐完善;消费者端的积分、余额、评价、优惠券等小模块正在完善

This commit is contained in:
cyh666666
2026-03-03 17:02:53 +08:00
parent 7e74b88e1e
commit cceb556c62
15 changed files with 4975 additions and 612 deletions

View File

@@ -204,11 +204,16 @@ const updateOrderInStorage = (targetOrderId: string, status: number) => {
// 尝试从 'orders' 读取 (checkout页面写入的key)
const ordersStr = uni.getStorageSync('orders')
let orders: Record<string, any>[] = []
if (ordersStr != null) {
if (ordersStr != null && ordersStr !== '') {
const parsed = JSON.parse(ordersStr as string)
if (Array.isArray(parsed)) {
for (let i = 0; i < parsed.length; i++) {
orders.push(parsed[i] as Record<string, any>)
// 使用 JSON 序列化转换
const itemStr = JSON.stringify(parsed[i])
const itemParsed = JSON.parse(itemStr)
if (itemParsed != null) {
orders.push(itemParsed as Record<string, any>)
}
}
}
}
@@ -230,7 +235,8 @@ const updateOrderInStorage = (targetOrderId: string, status: number) => {
uni.setStorageSync('orders', JSON.stringify(orders))
console.log('订单状态已更新到Storage (orders):', targetOrderId, status)
} else {
console.warn('在Storage (orders)中未找到订单:', targetOrderId)
// 本地缓存中没有订单数据是正常的,数据在数据库中
console.log('本地缓存中无订单数据,已忽略:', targetOrderId)
}
} catch (e) {
console.error('更新订单状态失败', e)
@@ -291,16 +297,26 @@ const loadOrderInfo = async () => {
const order = await supabaseService.getOrderDetail(orderId.value)
if (order != null) {
const orderObj = order as Record<string, any>
orderNo.value = orderObj['order_no'] as string
// Only update amount if not passed via options (options is priority for UI flow usually, but DB is source of truth)
// But checking consistency is good
const totalAmount = orderObj['total_amount']
const dbAmount = totalAmount != null ? parseFloat(totalAmount.toString()) : 0
// 使用 JSON 序列化转换对象
const orderStr = JSON.stringify(order)
const orderParsed = JSON.parse(orderStr)
if (orderParsed == null) {
console.error('订单数据解析失败')
return
}
const orderObj = orderParsed as UTSJSONObject
const orderNoVal = orderObj.getString('order_no')
if (orderNoVal != null) {
orderNo.value = orderNoVal
}
const totalAmount = orderObj.getNumber('total_amount')
const dbAmount = totalAmount ?? 0
if (dbAmount > 0) {
amount.value = dbAmount
}
const items = orderObj['items']
const items = orderObj.get('items')
if (items != null && Array.isArray(items) && items.length > 0) {
// Could update product name etc if displayed
}
@@ -315,43 +331,45 @@ const loadOrderInfo = async () => {
}
// 生命周期
onLoad((options) => {
if (options != null) {
const orderIdValue = options['orderId']
if (orderIdValue != null) {
orderId.value = orderIdValue as string
loadOrderInfo()
}
const amountValue = options['amount']
if (amountValue != null) {
amount.value = parseFloat(amountValue.toString())
}
// 获取传递的价格详情
const productAmountValue = options['productAmount']
if (productAmountValue != null) {
productAmount.value = parseFloat(productAmountValue.toString())
}
const deliveryFeeValue = options['deliveryFee']
if (deliveryFeeValue != null) {
deliveryFee.value = parseFloat(deliveryFeeValue.toString())
}
const discountAmountValue = options['discountAmount']
if (discountAmountValue != null) {
discountAmount.value = parseFloat(discountAmountValue.toString())
}
// 如果没有传详情,尝试根据总价估算(兼容旧逻辑,但优先使用传参)
if (productAmountValue == null && amount.value > 0) {
calculatePriceDetails(amount.value)
}
loadPaymentMethods()
loadUserBalance()
}
})
onMounted(() => {
const pages = getCurrentPages()
const currentPage = pages[pages.length - 1]
const options = currentPage.options as Record<string, any>
const orderIdValue = options['orderId']
if (orderIdValue != null) {
orderId.value = orderIdValue as string
loadOrderInfo()
}
const amountValue = options['amount']
if (amountValue != null) {
amount.value = parseFloat(amountValue.toString())
}
// 获取传递的价格详情
const productAmountValue = options['productAmount']
if (productAmountValue != null) {
productAmount.value = parseFloat(productAmountValue.toString())
}
const deliveryFeeValue = options['deliveryFee']
if (deliveryFeeValue != null) {
deliveryFee.value = parseFloat(deliveryFeeValue.toString())
}
const discountAmountValue = options['discountAmount']
if (discountAmountValue != null) {
discountAmount.value = parseFloat(discountAmountValue.toString())
}
// 如果没有传详情,尝试根据总价估算(兼容旧逻辑,但优先使用传参)
if (productAmountValue == null && amount.value > 0) {
calculatePriceDetails(amount.value)
}
loadPaymentMethods()
loadUserBalance()
// onMounted 中的逻辑已移到 onLoad 中
})
// 监听返回操作(包含系统返回键和导航栏返回按钮)
@@ -370,11 +388,16 @@ onBackPress((options) => {
const getCurrentUserId = (): string => {
const userStore = uni.getStorageSync('userInfo')
if (userStore != null) {
const userObj = userStore as Record<string, any>
const id = userObj['id']
if (id != null) {
return id as string
}
// 使用 JSON 序列化转换
const userStr = JSON.stringify(userStore)
const userParsed = JSON.parse(userStr)
if (userParsed != null) {
const userObj = userParsed as UTSJSONObject
const id = userObj.getString('id')
if (id != null) {
return id
}
}
}
return ''
}