consumer模块完成度95%,优化安卓端界面和小程序测试2
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
<!-- 结算页面 -->
|
||||
<!-- 结算页面 -->
|
||||
<template>
|
||||
<view class="checkout-page">
|
||||
<scroll-view class="checkout-content" direction="vertical">
|
||||
@@ -316,6 +316,8 @@ type CheckoutItemType = {
|
||||
product_image: string
|
||||
sku_specifications: any
|
||||
price: number
|
||||
original_price: number // 原价
|
||||
member_price: number // 会员价
|
||||
quantity: number
|
||||
shop_id?: string
|
||||
shop_name?: string
|
||||
@@ -474,7 +476,11 @@ const shopGroups = computed((): Array<ShopGroupType> => {
|
||||
const getGroupTotal = (group: ShopGroupType): string => {
|
||||
let sum = 0
|
||||
group.items.forEach((item) => {
|
||||
const price = item.price
|
||||
// 优先使用会员价,如果没有会员价则使用原价
|
||||
let price = item.price
|
||||
if (item.member_price != null && item.member_price > 0 && item.member_price < item.price) {
|
||||
price = item.member_price
|
||||
}
|
||||
const quantity = item.quantity
|
||||
if (isNaN(price) == false && isNaN(quantity) == false) {
|
||||
sum += (price * quantity)
|
||||
@@ -495,7 +501,11 @@ const totalAmount = computed(() => {
|
||||
// 确保item存在且包含必要的属性
|
||||
if (item == null) return sum
|
||||
|
||||
const price = item.price
|
||||
// 优先使用会员价,如果没有会员价则使用原价
|
||||
let price = item.price
|
||||
if (item.member_price != null && item.member_price > 0 && item.member_price < item.price) {
|
||||
price = item.member_price
|
||||
}
|
||||
const quantity = item.quantity
|
||||
|
||||
// 验证转换后的数字是否有效
|
||||
@@ -546,8 +556,20 @@ watch(checkoutItems, (newItems: Array<CheckoutItemType>) => {
|
||||
}, { deep: true })
|
||||
|
||||
// 处理商品数据清洗
|
||||
const processCheckoutItems = (items: any[]) => {
|
||||
// 数据清洗:确保价格和数量是数字类型
|
||||
const processCheckoutItems = async (items: any[]) => {
|
||||
// 获取会员折扣信息
|
||||
let memberDiscount = 1.0
|
||||
try {
|
||||
const memberInfo = await supabaseService.getUserMemberInfo()
|
||||
const discountRaw = memberInfo.get('discount')
|
||||
if (discountRaw != null) {
|
||||
memberDiscount = discountRaw as number
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('获取会员信息失败,使用默认折扣:', e)
|
||||
}
|
||||
|
||||
// 数据清洗:确保价格和数量是数字类型
|
||||
const converted: Array<CheckoutItemType> = []
|
||||
if (items != null && items.length > 0) {
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
@@ -584,6 +606,12 @@ const processCheckoutItems = (items: any[]) => {
|
||||
const shopId = obj.getString('shop_id') ?? obj.getString('shopId') ?? 'unknown'
|
||||
const shopName = obj.getString('shop_name') ?? obj.getString('shopName') ?? ''
|
||||
const merchantId = obj.getString('merchant_id') ?? obj.getString('merchantId') ?? ''
|
||||
|
||||
// 计算会员价
|
||||
let memberPrice = 0
|
||||
if (memberDiscount > 0 && memberDiscount < 1 && price > 0) {
|
||||
memberPrice = Math.round(price * memberDiscount * 100) / 100
|
||||
}
|
||||
|
||||
converted.push({
|
||||
id: id,
|
||||
@@ -593,6 +621,8 @@ const processCheckoutItems = (items: any[]) => {
|
||||
product_image: productImage,
|
||||
sku_specifications: specs,
|
||||
price: parseFloat(price.toFixed(2)),
|
||||
original_price: parseFloat(price.toFixed(2)),
|
||||
member_price: memberPrice,
|
||||
quantity: quantity,
|
||||
shop_id: shopId,
|
||||
shop_name: shopName,
|
||||
@@ -605,7 +635,7 @@ const processCheckoutItems = (items: any[]) => {
|
||||
if (checkoutItems.value.length > 0) {
|
||||
console.log('清洗后商品价格明细:')
|
||||
checkoutItems.value.forEach((item: CheckoutItemType, index: number) => {
|
||||
console.log(`商品${index}:`, item.product_name, '价格:', item.price, 'shop:', item.shop_id)
|
||||
console.log(`商品${index}:`, item.product_name, '原价:', item.price, '会员价:', item.member_price, 'shop:', item.shop_id)
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -929,7 +959,7 @@ async function loadAddressList(): Promise<void> {
|
||||
}
|
||||
|
||||
// 从本地存储加载结算数据(例如从购物车进入)
|
||||
function loadFromLocalStorage(): void {
|
||||
async function loadFromLocalStorage(): Promise<void> {
|
||||
const cartData = uni.getStorageSync('cart')
|
||||
const cartDataStr = cartData != null ? cartData.toString() : ''
|
||||
if (cartDataStr != '') {
|
||||
@@ -942,7 +972,7 @@ function loadFromLocalStorage(): void {
|
||||
if (selected) selectedCartItems.push(obj)
|
||||
}
|
||||
if (selectedCartItems.length > 0) {
|
||||
processCheckoutItems(selectedCartItems)
|
||||
await processCheckoutItems(selectedCartItems)
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('解析购物车数据失败:', e)
|
||||
@@ -956,7 +986,8 @@ function loadCheckoutData(): void {
|
||||
loadFromLocalStorage()
|
||||
}
|
||||
|
||||
onLoad((options: any) => {
|
||||
// 初始化加载数据
|
||||
async function initCheckoutData(): Promise<void> {
|
||||
let dataLoaded = false
|
||||
const checkoutTypeAny = uni.getStorageSync('checkout_type')
|
||||
const checkoutType = checkoutTypeAny != null ? checkoutTypeAny.toString() : ''
|
||||
@@ -969,7 +1000,7 @@ onLoad((options: any) => {
|
||||
const items = JSON.parse(itemsStr as string)
|
||||
console.log('从Storage加载的商品数据:', items)
|
||||
if (items != null && Array.isArray(items) && items.length > 0) {
|
||||
processCheckoutItems(items)
|
||||
await processCheckoutItems(items)
|
||||
dataLoaded = true
|
||||
}
|
||||
} catch (e) {
|
||||
@@ -980,11 +1011,15 @@ onLoad((options: any) => {
|
||||
|
||||
if (dataLoaded == false) {
|
||||
console.log('未找到预结算数据,尝试从购物车本地存储加载')
|
||||
loadFromLocalStorage()
|
||||
await loadFromLocalStorage()
|
||||
}
|
||||
|
||||
loadDefaultAddress()
|
||||
loadAddressList()
|
||||
}
|
||||
|
||||
onLoad((options: any) => {
|
||||
initCheckoutData()
|
||||
})
|
||||
|
||||
// 页面显示时触发
|
||||
@@ -1337,6 +1372,7 @@ const submitOrder = async () => {
|
||||
sku_id: item.sku_id,
|
||||
quantity: item.quantity,
|
||||
price: item.price,
|
||||
member_price: item.member_price,
|
||||
product_name: item.product_name,
|
||||
product_image: item.product_image,
|
||||
specifications: item.sku_specifications
|
||||
|
||||
Reference in New Issue
Block a user