- 添加了 itemDetail 组件,用于展示商品详细信息 - 在 home 页面中集成了瀑布流列表组件 - 实现了商品列表的加载更多和下拉刷新功能 - 添加了商品详情弹窗组件
236 lines
7.1 KiB
Vue
236 lines
7.1 KiB
Vue
<script setup>
|
||
import xPopup from '@/components/x-popup/index.vue'
|
||
import {goodStore} from "@/stores/goods/index.js";
|
||
import xImage from '@/components/x-image/index.vue'
|
||
import DetailPopup from '@/pages/home/components/DetailPopup/index.vue'
|
||
import {liveStore} from "~/stores/live/index.js";
|
||
import {ref} from "vue";
|
||
const {pageRef,itemList,getArtworkList, loading: storeLoading,} = goodStore();
|
||
const {auctionData} = liveStore()
|
||
const showDetail=ref(false)
|
||
const localState = ref({
|
||
finished: false,
|
||
refreshing: false,
|
||
showDetail: false,
|
||
showHeight: '',
|
||
isSearchingCurrentItem: false
|
||
})
|
||
const onRefresh = async () => {
|
||
try {
|
||
localState.value.refreshing = true
|
||
localState.value.finished = false
|
||
const { finished } = await getArtworkList(true)
|
||
localState.value.finished = finished
|
||
} finally {
|
||
localState.value.refreshing = false
|
||
}
|
||
}
|
||
const props = defineProps({
|
||
show: Boolean,
|
||
title: {
|
||
type: String,
|
||
default: ''
|
||
}
|
||
})
|
||
const scrollToCurrentItem = async () => {
|
||
if (!auctionData.value?.artwork?.index) return
|
||
|
||
const targetIndex = auctionData.value.artwork.index
|
||
let currentIndex = itemList.value.findIndex(item => targetIndex === item?.index)
|
||
|
||
if (currentIndex === -1) {
|
||
try {
|
||
localState.value.isSearchingCurrentItem = true
|
||
|
||
await searchSpecificItem(targetIndex)
|
||
|
||
currentIndex = itemList.value.findIndex(item => targetIndex === item?.index)
|
||
|
||
if (currentIndex > -1) {
|
||
await nextTick()
|
||
scrollToElement(currentIndex)
|
||
}
|
||
} finally {
|
||
localState.value.isSearchingCurrentItem = false
|
||
}
|
||
} else {
|
||
await nextTick()
|
||
scrollToElement(currentIndex)
|
||
}
|
||
}
|
||
const searchSpecificItem = async (targetIndex) => {
|
||
try {
|
||
const originalPage = pageRef.value.page
|
||
const originalPageSize = pageRef.value.pageSize
|
||
|
||
const estimatedPage = Math.ceil(targetIndex / 20)
|
||
|
||
pageRef.value.pageSize = 50
|
||
|
||
pageRef.value.page = estimatedPage > 0 ? estimatedPage : 1
|
||
await getArtworkList(true)
|
||
|
||
let found = itemList.value.some(item => targetIndex === item?.index)
|
||
|
||
if (!found) {
|
||
pageRef.value.page = 1
|
||
pageRef.value.pageSize = 100
|
||
await getArtworkList(true)
|
||
}
|
||
|
||
pageRef.value.page = originalPage
|
||
pageRef.value.pageSize = originalPageSize
|
||
} catch (error) {
|
||
console.error('搜索特定拍品时出错:', error)
|
||
}
|
||
}
|
||
const scrollToElement = (index) => {
|
||
const container = document.querySelector('.list-container')
|
||
const allItems = document.querySelectorAll('.item-wrapper')
|
||
|
||
if (!container || !allItems.length || index >= allItems.length) {
|
||
console.warn('无法滚动:容器或目标元素不存在')
|
||
return
|
||
}
|
||
|
||
const targetElement = allItems[index]
|
||
|
||
if (targetElement) {
|
||
const containerRect = container.getBoundingClientRect()
|
||
const elementRect = targetElement.getBoundingClientRect()
|
||
|
||
const scrollTop = elementRect.top - containerRect.top + container.scrollTop
|
||
|
||
container.scrollTo({
|
||
top: Math.max(0, scrollTop - 20),
|
||
behavior: 'smooth'
|
||
})
|
||
|
||
targetElement.classList.add('highlight-item')
|
||
setTimeout(() => {
|
||
targetElement.classList.remove('highlight-item')
|
||
}, 2000)
|
||
}
|
||
}
|
||
const emit = defineEmits(['update:show'])
|
||
const showDetailInfo=ref(null)
|
||
const close = () => emit('update:show', false);
|
||
const openShow=(item)=>{
|
||
showDetailInfo.value=item
|
||
showDetail.value=true
|
||
|
||
}
|
||
const loadMore = async () => {
|
||
pageRef.value.page++
|
||
const { finished } = await getArtworkList()
|
||
localState.value.finished = finished
|
||
}
|
||
watch(()=>{
|
||
return auctionData.value?.artwork?.index
|
||
},(newValue)=>{
|
||
})
|
||
watch(()=>props.show,(newValue)=>{
|
||
if (newValue){
|
||
nextTick(()=>{
|
||
scrollToCurrentItem()
|
||
})
|
||
}
|
||
})
|
||
</script>
|
||
|
||
<template>
|
||
<div>
|
||
<x-popup :show="show" @update:show="close">
|
||
<template #title>
|
||
<div class="text-#000 text-16px">{{ $t('home.tab1')}}</div>
|
||
<div class="text-#939393 text-16px ml-14px">{{ $t('live_room.total') }}{{ pageRef.itemCount }}{{ $t('live_room.lots_num') }}</div>
|
||
</template>
|
||
<div>
|
||
<van-pull-refresh
|
||
v-model="localState.refreshing"
|
||
:success-text="$t('home.refresh_show')"
|
||
:success-duration="700"
|
||
@refresh="onRefresh"
|
||
>
|
||
<template #success>
|
||
<van-icon name="success" /> <span>{{ $t('home.refresh_show') }}</span>
|
||
</template>
|
||
<div v-if="localState.isSearchingCurrentItem" class="searching-item-tip">
|
||
{{ $t('live_room.searching_current_lot') || '正在查找当前拍品...' }}
|
||
</div>
|
||
<van-list
|
||
v-model:loading="storeLoading"
|
||
:finished="localState.finished"
|
||
:finished-text="$t('home.finished_text')"
|
||
@load="loadMore"
|
||
class="list-container"
|
||
>
|
||
<div
|
||
v-for="(item) of itemList"
|
||
:key="item.uuid"
|
||
class="flex mb-21px item-wrapper"
|
||
@click="openShow(item)"
|
||
>
|
||
<div
|
||
class="mr-10px flex-shrink-0 rounded-4px overflow-hidden cursor-pointer relative"
|
||
>
|
||
<xImage
|
||
:preview="false"
|
||
class="w-80px h-80px"
|
||
:src="item.artwork?.hdPic"
|
||
:alt="item?.artworkTitle"
|
||
loading="lazy"
|
||
/>
|
||
<div class="w-45px h-17px bg-#2B53AC text-12px line-height-none flex justify-center items-center absolute top-2px left-2px text-#fff">LOT{{item.index}}</div>
|
||
<div v-show="auctionData?.artwork?.index===item?.index" class="w-80px h-20px bg-#B58047 flex line-height-none justify-center items-center text-#fff text-12px bottom-0 absolute blink">{{ $t('live_room.cast') }}</div>
|
||
</div>
|
||
<div>
|
||
<div class="ellipsis line-height-20px text-16px font-600 min-h-40px">
|
||
{{ item.artworkTitle }}
|
||
</div>
|
||
<div class="text-14px text-#575757">{{ $t('home.start_price') }}:{{item?.startPriceCurrency}} {{item?.startPrice}}</div>
|
||
<div class="text-14px text-#B58047" v-if="item.soldPrice">{{ $t('home.close_price') }}:{{item.soldPrice}}</div>
|
||
</div>
|
||
</div>
|
||
</van-list>
|
||
</van-pull-refresh>
|
||
</div>
|
||
</x-popup>
|
||
<DetailPopup v-model:show="showDetail" :detail-info="showDetailInfo"></DetailPopup>
|
||
</div>
|
||
</template>
|
||
|
||
<style scoped>
|
||
.ellipsis {
|
||
display: -webkit-box;
|
||
-webkit-box-orient: vertical;
|
||
-webkit-line-clamp: 2;
|
||
overflow: hidden;
|
||
text-overflow: ellipsis;
|
||
}
|
||
.blink {
|
||
animation: fade 1s linear infinite;
|
||
}
|
||
|
||
@keyframes fade {
|
||
0%, 100% { opacity: 1; }
|
||
50% { opacity: 0.5; }
|
||
}
|
||
|
||
.searching-item-tip {
|
||
text-align: center;
|
||
padding: 10px 0;
|
||
color: #B58047;
|
||
font-size: 14px;
|
||
}
|
||
|
||
.highlight-item {
|
||
animation: highlight-pulse 2s ease-in-out;
|
||
}
|
||
|
||
@keyframes highlight-pulse {
|
||
0% { box-shadow: 0 0 0 0 rgba(181, 128, 71, 0.7); }
|
||
50% { box-shadow: 0 0 0 10px rgba(181, 128, 71, 0); }
|
||
100% { box-shadow: 0 0 0 0 rgba(181, 128, 71, 0); }
|
||
}
|
||
</style> |