完善下单逻辑及其ui展示,修复支付倒计时显示错误bug
This commit is contained in:
@@ -174,40 +174,13 @@
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 推荐商品 -->
|
||||
<view v-if="currentCartType == 'goods' && recommendProducts.length > 0" class="recommend-section">
|
||||
<view class="section-header">
|
||||
<text class="section-title">猜你喜欢</text>
|
||||
</view>
|
||||
<view class="recommend-list">
|
||||
<view
|
||||
v-for="product in recommendProducts"
|
||||
:key="product.id"
|
||||
class="recommend-item"
|
||||
@click="navigateToProduct(product)"
|
||||
>
|
||||
<view class="recommend-image-wrapper">
|
||||
<image
|
||||
class="recommend-image"
|
||||
:src="product.image"
|
||||
mode="aspectFill"
|
||||
/>
|
||||
</view>
|
||||
<text class="recommend-name" :lines="2">{{ product.name }}</text>
|
||||
<view class="recommend-bottom">
|
||||
<text class="recommend-price">¥{{ product.price }}</text>
|
||||
<view class="recommend-add-btn" @click.stop="addToCart(product)">
|
||||
<text class="recommend-add-icon">+</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="recommend-load-more" @click="loadRecommendProducts(false)">
|
||||
<text v-if="recommendLoading" class="recommend-load-text">正在加载更多...</text>
|
||||
<text v-else-if="!recommendHasMore && recommendInitialized" class="recommend-load-text">没有更多了</text>
|
||||
<text v-else class="recommend-load-text">上拉加载更多</text>
|
||||
</view>
|
||||
</view>
|
||||
<GuessYouLike
|
||||
v-if="currentCartType == 'goods'"
|
||||
title="猜你喜欢"
|
||||
:pageSize="8"
|
||||
:loadMoreKey="guessLoadMoreKey"
|
||||
@productClick="handleGuessProductClick"
|
||||
/>
|
||||
<!-- 底部占位符:确保内容不被原生 TabBar 遮挡 -->
|
||||
<view class="tabbar-safe-area"></view>
|
||||
</scroll-view>
|
||||
@@ -280,6 +253,7 @@ import { ref, computed, onMounted } from 'vue'
|
||||
import { onShow } from '@dcloudio/uni-app'
|
||||
import { supabaseService, type CartItem as SupabaseCartItem, type Product } from '@/utils/supabaseService.uts'
|
||||
import { goToLogin } from '@/utils/utils.uts'
|
||||
import GuessYouLike from '@/components/mall/GuessYouLike/GuessYouLike.uvue'
|
||||
|
||||
type ModalSuccess = { confirm: boolean; cancel: boolean }
|
||||
|
||||
@@ -375,6 +349,7 @@ const recommendBottomLocked = ref<boolean>(false)
|
||||
const recommendViewportHeight = ref<number>(0)
|
||||
const pageWindowHeight = ref<number>(0)
|
||||
const isAndroidApp = ref<boolean>(false)
|
||||
const guessLoadMoreKey = ref<number>(0)
|
||||
const serviceMockItems = ref<ServiceCartItem[]>([
|
||||
{
|
||||
id: 'service-1',
|
||||
@@ -725,27 +700,6 @@ const mergeRecommendProducts = (oldList: RecommendProduct[], newList: RecommendP
|
||||
return result
|
||||
}
|
||||
|
||||
const mockRecommendProducts = (page: number, pageSize: number): RecommendProduct[] => {
|
||||
const list: RecommendProduct[] = []
|
||||
if (page >= 5) {
|
||||
return list
|
||||
}
|
||||
for (let i = 0; i < pageSize; i++) {
|
||||
const index = (page - 1) * pageSize + i + 1
|
||||
list.push({
|
||||
id: 'mock-recommend-' + index,
|
||||
shopId: 'mock-shop-' + index,
|
||||
shopName: '商城推荐',
|
||||
name: '猜你喜欢 推荐商品 ' + index,
|
||||
price: 9.9 + index,
|
||||
image: '/static/images/default.png',
|
||||
skuId: '',
|
||||
merchant_id: ''
|
||||
})
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
const fetchRecommendProducts = async (page: number, pageSize: number): Promise<RecommendProduct[]> => {
|
||||
console.log('[cart推荐] fetchRecommendProducts 请求 page=', page, 'pageSize=', pageSize)
|
||||
const hotResp = await supabaseService.searchProducts('', page, pageSize, 'sales')
|
||||
@@ -851,13 +805,7 @@ async function loadRecommendProducts(reset: boolean): Promise<void> {
|
||||
recommendInitialized.value = true
|
||||
} catch (error) {
|
||||
console.error('加载推荐商品失败:', error)
|
||||
if (reset && recommendProducts.value.length === 0) {
|
||||
const mockList = mockRecommendProducts(1, recommendPageSize.value)
|
||||
recommendProducts.value = mockList
|
||||
recommendPage.value = 2
|
||||
recommendHasMore.value = true
|
||||
recommendInitialized.value = true
|
||||
}
|
||||
recommendHasMore.value = false
|
||||
} finally {
|
||||
recommendLoading.value = false
|
||||
if (!reset && recommendPendingLoad.value && recommendHasMore.value) {
|
||||
@@ -869,59 +817,13 @@ async function loadRecommendProducts(reset: boolean): Promise<void> {
|
||||
}
|
||||
|
||||
function onRecommendScrollToLower(): void {
|
||||
console.log('[cart推荐] scrolltolower 触发 currentCartType=', currentCartType.value, 'initialized=', recommendInitialized.value)
|
||||
if (currentCartType.value != 'goods') {
|
||||
console.log('[cart推荐] 跳过:当前不是 goods')
|
||||
return
|
||||
if (currentCartType.value == 'goods') {
|
||||
guessLoadMoreKey.value = guessLoadMoreKey.value + 1
|
||||
}
|
||||
recommendBottomLocked.value = true
|
||||
loadRecommendProducts(false)
|
||||
}
|
||||
|
||||
function onRecommendScroll(event: any): void {
|
||||
if (currentCartType.value != 'goods' || recommendLoading.value || !recommendHasMore.value) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
const eventObj = toRecommendScrollJson(event)
|
||||
let detailObj: UTSJSONObject | null = null
|
||||
if (eventObj != null) {
|
||||
detailObj = toRecommendScrollJson(eventObj.get('detail'))
|
||||
}
|
||||
if (detailObj == null) {
|
||||
return
|
||||
}
|
||||
|
||||
const scrollTop = readRecommendScrollMetric(detailObj, 'scrollTop')
|
||||
const scrollHeight = readRecommendScrollMetric(detailObj, 'scrollHeight')
|
||||
let clientHeight = readRecommendScrollMetric(detailObj, 'clientHeight')
|
||||
|
||||
if (clientHeight <= 0) {
|
||||
clientHeight = recommendViewportHeight.value
|
||||
}
|
||||
|
||||
console.log('[cart推荐] scroll事件 scrollTop=', scrollTop, 'scrollHeight=', scrollHeight, 'clientHeight=', clientHeight)
|
||||
|
||||
if (scrollHeight <= 0 || clientHeight <= 0) {
|
||||
return
|
||||
}
|
||||
|
||||
const distanceToBottom = scrollHeight - scrollTop - clientHeight
|
||||
if (distanceToBottom > 260) {
|
||||
recommendBottomLocked.value = false
|
||||
}
|
||||
if (distanceToBottom <= 180) {
|
||||
console.log('[cart推荐] scroll 兜底触底 distanceToBottom=', distanceToBottom)
|
||||
if (recommendBottomLocked.value) {
|
||||
recommendPendingLoad.value = true
|
||||
return
|
||||
}
|
||||
recommendBottomLocked.value = true
|
||||
loadRecommendProducts(false)
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('[cart推荐] 处理推荐滚动失败:', e)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// 加载数据
|
||||
@@ -981,9 +883,6 @@ const loadCartData = async () => {
|
||||
console.log('Transformed items count:', transformedItems.length);
|
||||
cartItems.value = transformedItems
|
||||
|
||||
if (!recommendInitialized.value) {
|
||||
await loadRecommendProducts(true)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('加载购物车数据失败:', error)
|
||||
cartItems.value = []
|
||||
@@ -996,6 +895,10 @@ onShow(() => {
|
||||
loadCartData()
|
||||
})
|
||||
|
||||
const handleGuessProductClick = (productId: string) => {
|
||||
navigateToProduct({ id: productId, productId: productId, price: 0 })
|
||||
}
|
||||
|
||||
// 商品操作 - 更新选中状态到Supabase
|
||||
const toggleSelect = async (itemId: string) => {
|
||||
// 乐观更新
|
||||
@@ -2593,4 +2496,3 @@ const goToCheckout = () => {
|
||||
background-color: transparent;
|
||||
}
|
||||
</style>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user