20260227-1

This commit is contained in:
cyh666666
2026-02-27 16:51:56 +08:00
1526 changed files with 2457 additions and 38509 deletions

View File

@@ -200,6 +200,7 @@ type RecommendProduct = {
price: number
image: string
skuId: string
merchant_id: string
}
// 响应式数据
@@ -326,9 +327,10 @@ const loadCartData = async () => {
shopId: p.merchant_id ?? 'unknown',
shopName: p.shop_name ?? '商城推荐',
name: p.name,
price: p.base_price ?? p.price ?? 0,
image: p.main_image_url ?? '/static/images/default-product.png',
skuId: ''
price: p.base_price ?? p.market_price ?? 0,
image: p.main_image_url ?? p.image_url ?? '/static/images/default-product.png',
skuId: '',
merchant_id: p.merchant_id ?? ''
}
})
} else {
@@ -558,31 +560,52 @@ const deleteSelectedItems = async () => {
})
}
const addToCart = async (product: any) => {
const addToCart = async (product: RecommendProduct) => {
uni.showLoading({ title: '检查商品...' })
try {
// 调用SupabaseService添加商品到购物车
// 显式访问属性避免any类型导致的编译错误
const target = product as UTSJSONObject
const productId = target.getString('id') ?? ''
const skuId = target.getString('skuId') ?? ''
const success = await supabaseService.addToCart(productId, 1, skuId)
if (success) {
const productId = product.id
const skuId = product.skuId
const merchantId = product.merchant_id
// 检查商品是否有SKU
const skus = await supabaseService.getProductSkus(productId)
uni.hideLoading()
if (skus.length > 0) {
// 有规格,提示并跳转到商品详情页选择规格
uni.showToast({
title: '已添加到购物车',
icon: 'success'
})
// 重新加载购物车数据
loadCartData()
} else {
console.error('添加商品到购物车失败')
uni.showToast({
title: '添加失败',
title: '请选择规格',
icon: 'none'
})
setTimeout(() => {
uni.navigateTo({
url: '/pages/mall/consumer/product-detail?id=' + productId
})
}, 500)
} else {
// 无规格,直接加入购物车
uni.showLoading({ title: '添加中...' })
const success = await supabaseService.addToCart(productId, 1, skuId, merchantId)
uni.hideLoading()
if (success) {
uni.showToast({
title: '已添加到购物车',
icon: 'success'
})
// 重新加载购物车数据
loadCartData()
} else {
console.error('添加商品到购物车失败')
uni.showToast({
title: '添加失败',
icon: 'none'
})
}
}
} catch (error) {
console.error('添加商品到购物车异常:', error)
uni.hideLoading()
uni.showToast({
title: '添加失败',
icon: 'none'