完成consumer端同步
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
<!-- 结算页面 -->
|
||||
<!-- 结算页面 -->
|
||||
<template>
|
||||
<view class="checkout-page">
|
||||
<scroll-view class="checkout-content" direction="vertical">
|
||||
@@ -307,6 +307,7 @@
|
||||
import { ref, onMounted, computed, watch, onUnmounted, getCurrentInstance } from 'vue'
|
||||
import { onLoad } from '@dcloudio/uni-app'
|
||||
import { supabaseService, type UserAddress as SupabaseUserAddress } from '@/utils/supabaseService.uts'
|
||||
import { goToLogin as redirectToLogin } from '@/utils/utils.uts'
|
||||
|
||||
type CheckoutItemType = {
|
||||
id: string
|
||||
@@ -397,7 +398,7 @@ type MockAddress = {
|
||||
function getObjectKeys(obj: object): string[] {
|
||||
const keys: string[] = []
|
||||
// UTS 兼容的对象属性获取方式
|
||||
const tempObj = obj as Record<string, any>
|
||||
const tempObj = obj as UTSJSONObject
|
||||
|
||||
// 使用 try-catch 安全获取对象属性
|
||||
try {
|
||||
@@ -482,7 +483,7 @@ const getGroupTotal = (group: ShopGroupType): string => {
|
||||
price = item.member_price
|
||||
}
|
||||
const quantity = item.quantity
|
||||
if (isNaN(price) == false && isNaN(quantity) == false) {
|
||||
if (Number.isNaN(price) == false && Number.isNaN(quantity) == false) {
|
||||
sum += (price * quantity)
|
||||
}
|
||||
})
|
||||
@@ -509,7 +510,7 @@ const totalAmount = computed(() => {
|
||||
const quantity = item.quantity
|
||||
|
||||
// 验证转换后的数字是否有效
|
||||
if (isNaN(price) || isNaN(quantity) || price <= 0 || quantity <= 0) {
|
||||
if (Number.isNaN(price) || Number.isNaN(quantity) || price <= 0 || quantity <= 0) {
|
||||
console.warn('商品价格或数量无效:', item, 'price:', price, 'quantity:', quantity)
|
||||
return sum
|
||||
}
|
||||
@@ -593,14 +594,14 @@ const processCheckoutItems = async (items: any[]) => {
|
||||
const priceAny = obj.get('price')
|
||||
if (priceAny != null) {
|
||||
const parsed = parseFloat(priceAny.toString())
|
||||
if (isNaN(parsed) == false) price = parsed
|
||||
if (Number.isNaN(parsed) == false) price = parsed
|
||||
}
|
||||
|
||||
let quantity = 1
|
||||
const quantityAny = obj.get('quantity')
|
||||
if (quantityAny != null) {
|
||||
const parsedQ = parseInt(quantityAny.toString())
|
||||
if (isNaN(parsedQ) == false && parsedQ >= 1) quantity = parsedQ
|
||||
if (Number.isNaN(parsedQ) == false && parsedQ >= 1) quantity = parsedQ
|
||||
}
|
||||
|
||||
const shopId = obj.getString('shop_id') ?? obj.getString('shopId') ?? 'unknown'
|
||||
@@ -719,19 +720,19 @@ async function loadDefaultAddress(): Promise<void> {
|
||||
}
|
||||
|
||||
// 同时更新本地存储缓存
|
||||
const localAddresses: any[] = []
|
||||
const localAddresses: UTSJSONObject[] = []
|
||||
for (let i = 0; i < supabaseAddresses.length; i++) {
|
||||
const addr = supabaseAddresses[i]
|
||||
localAddresses.push({
|
||||
id: addr.id,
|
||||
name: addr.recipient_name,
|
||||
phone: addr.phone,
|
||||
province: addr.province,
|
||||
city: addr.city,
|
||||
district: addr.district,
|
||||
detail: addr.detail_address,
|
||||
isDefault: addr.is_default
|
||||
})
|
||||
const localItem = new UTSJSONObject()
|
||||
localItem.set('id', addr.id)
|
||||
localItem.set('name', addr.recipient_name)
|
||||
localItem.set('phone', addr.phone)
|
||||
localItem.set('province', addr.province)
|
||||
localItem.set('city', addr.city)
|
||||
localItem.set('district', addr.district)
|
||||
localItem.set('detail', addr.detail_address)
|
||||
localItem.set('isDefault', addr.is_default)
|
||||
localAddresses.push(localItem)
|
||||
}
|
||||
uni.setStorageSync('addresses', JSON.stringify(localAddresses))
|
||||
}
|
||||
@@ -847,7 +848,7 @@ async function loadAddressList(): Promise<void> {
|
||||
|
||||
if (supabaseAddresses != null && supabaseAddresses.length > 0) {
|
||||
const list: AddressItem[] = []
|
||||
const localAddresses: any[] = []
|
||||
const localAddresses: UTSJSONObject[] = []
|
||||
for (let i = 0; i < supabaseAddresses.length; i++) {
|
||||
const addr = supabaseAddresses[i]
|
||||
console.log('[loadAddressList] 地址', i, ':', addr.recipient_name, addr.phone, addr.detail_address)
|
||||
@@ -861,16 +862,16 @@ async function loadAddressList(): Promise<void> {
|
||||
detail: addr.detail_address,
|
||||
is_default: addr.is_default
|
||||
})
|
||||
localAddresses.push({
|
||||
id: addr.id,
|
||||
name: addr.recipient_name,
|
||||
phone: addr.phone,
|
||||
province: addr.province,
|
||||
city: addr.city,
|
||||
district: addr.district,
|
||||
detail: addr.detail_address,
|
||||
isDefault: addr.is_default
|
||||
})
|
||||
const localItem = new UTSJSONObject()
|
||||
localItem.set('id', addr.id)
|
||||
localItem.set('name', addr.recipient_name)
|
||||
localItem.set('phone', addr.phone)
|
||||
localItem.set('province', addr.province)
|
||||
localItem.set('city', addr.city)
|
||||
localItem.set('district', addr.district)
|
||||
localItem.set('detail', addr.detail_address)
|
||||
localItem.set('isDefault', addr.is_default)
|
||||
localAddresses.push(localItem)
|
||||
}
|
||||
addressList.value = list
|
||||
console.log('[loadAddressList] addressList.value 设置完成, 数量:', addressList.value.length)
|
||||
@@ -1265,8 +1266,8 @@ function formatSpecs(specs: any): string {
|
||||
const specsStr = JSON.stringify(specs)
|
||||
if (specsStr == '{}' || specsStr == '[]' || specsStr == '""' || specsStr == '') return ''
|
||||
|
||||
// 使用 Record 类型替代 UTSJSONObject 的迭代器方法
|
||||
const specsObj = JSON.parse(specsStr) as Record<string, any>
|
||||
// 使用 UTSJSONObject 替代 Record 类型
|
||||
const specsObj = JSON.parse(specsStr) as UTSJSONObject
|
||||
|
||||
const parts: string[] = []
|
||||
// 遍历已知可能的规格键名
|
||||
@@ -1347,14 +1348,14 @@ const submitOrder = async () => {
|
||||
const userId = supabaseService.getCurrentUserId()
|
||||
if (userId == null || userId == '') {
|
||||
uni.hideLoading()
|
||||
uni.showToast({ title: '请先登录', icon: 'none' })
|
||||
redirectToLogin('/pages/mall/consumer/checkout')
|
||||
return
|
||||
}
|
||||
|
||||
console.log('[submitOrder] 开始创建订单, userId:', userId)
|
||||
console.log('[submitOrder] shopGroups数量:', shopGroups.value.length)
|
||||
|
||||
const groups: any[] = []
|
||||
const groups: UTSJSONObject[] = []
|
||||
for (let i = 0; i < shopGroups.value.length; i++) {
|
||||
const group = shopGroups.value[i]
|
||||
console.log(`[submitOrder] 处理店铺组 ${i}:`, {
|
||||
@@ -1363,29 +1364,29 @@ const submitOrder = async () => {
|
||||
merchant_id: group.merchant_id,
|
||||
itemsCount: group.items.length
|
||||
})
|
||||
const items: any[] = []
|
||||
const items: UTSJSONObject[] = []
|
||||
for (let j = 0; j < group.items.length; j++) {
|
||||
const item = group.items[j]
|
||||
items.push({
|
||||
id: item.id,
|
||||
product_id: item.product_id,
|
||||
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
|
||||
})
|
||||
const itemObj = new UTSJSONObject()
|
||||
itemObj.set('id', item.id)
|
||||
itemObj.set('product_id', item.product_id)
|
||||
itemObj.set('sku_id', item.sku_id)
|
||||
itemObj.set('quantity', item.quantity)
|
||||
itemObj.set('price', item.price)
|
||||
itemObj.set('member_price', item.member_price)
|
||||
itemObj.set('product_name', item.product_name)
|
||||
itemObj.set('product_image', item.product_image)
|
||||
itemObj.set('specifications', item.sku_specifications)
|
||||
items.push(itemObj)
|
||||
}
|
||||
const finalMerchantId = (group.merchant_id != null && group.merchant_id != '') ? group.merchant_id : group.shopId
|
||||
console.log(`[submitOrder] 店铺组 ${i} 最终使用的 merchant_id:`, finalMerchantId)
|
||||
groups.push({
|
||||
merchant_id: finalMerchantId,
|
||||
shopId: group.shopId,
|
||||
shopName: group.shopName,
|
||||
items: items
|
||||
})
|
||||
const groupObj = new UTSJSONObject()
|
||||
groupObj.set('merchant_id', finalMerchantId)
|
||||
groupObj.set('shopId', group.shopId)
|
||||
groupObj.set('shopName', group.shopName)
|
||||
groupObj.set('items', items)
|
||||
groups.push(groupObj)
|
||||
}
|
||||
|
||||
console.log('[submitOrder] 准备传递的 groups 数量:', groups.length)
|
||||
@@ -1452,9 +1453,7 @@ const selectAddress = () => {
|
||||
|
||||
// 添加登录跳转方法
|
||||
const goToLogin = () => {
|
||||
uni.navigateTo({
|
||||
url: '/pages/login/login' // 根据实际登录页面路径调整
|
||||
})
|
||||
redirectToLogin('/pages/mall/consumer/checkout')
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user