zdtap-uniapp-main/pages/activityList/styleSelection.vue

446 lines
8.8 KiB
Vue
Raw Normal View History

2025-03-29 16:01:43 +08:00
<template>
<view class="page">
<!-- 筛选导航 -->
<Sieving
ref="filterDropdown"
:dropdownMenu="dropdownMenuList"
themeColor="#D42E78"
@confirm="handleFilterConfirm"
@close="handleFilterClose"
@open="handleFilterOpen"
/>
<!-- 统计信息 -->
<view class="stats-bar">
<text class="stats-text"> {{totalBeers}} 款在售酒款</text>
2025-03-29 16:01:43 +08:00
</view>
<!-- 内容区域 -->
<view class="content-container">
<scroll-view
scroll-y
class="beer-list"
@scrolltolower="loadMore"
refresher-enabled
:refresher-triggered="isRefreshing"
@refresherrefresh="onRefresh"
>
<view
class="beer-card hover-effect"
v-for="beer in beerList"
:key="beer.id"
@click="navigateToBeerDetail(beer)"
>
<view class="beer-info">
<image
:src="beer.cover"
class="beer-image"
mode="aspectFill"
:lazy-load="true"
/>
<view class="beer-details">
<text class="beer-name text-ellipsis">{{beer.beerName}}</text>
<text class="beer-style text-ellipsis">{{beer.beerStyles}}</text>
<text class="brand-name text-ellipsis">{{beer.brandName}}</text>
2025-03-29 16:01:43 +08:00
</view>
<image
src="/static/icons/arrow-right.png"
class="arrow-icon"
/>
2025-03-29 16:01:43 +08:00
</view>
</view>
<!-- 加载状态 -->
<template v-if="beerList.length === 0 && !loading">
<view class="empty-state">
<image src="/static/images/empty.png" class="empty-image" />
<text class="empty-text">暂无相关酒款</text>
</view>
</template>
<view class="loading-status" v-else>
<view v-if="loading" class="loading-wrapper">
<image src="/static/images/loading.gif" class="loading-icon" />
<text class="loading-text">加载中...</text>
</view>
<text v-else-if="!hasMore" class="no-more">没有更多了</text>
</view>
2025-03-29 16:01:43 +08:00
</scroll-view>
</view>
</view>
</template>
<script>
import {
getLastSixMonth,
getNewBeerListByMonth,
popularStyle,
getBrands,
getBeerStyles,
getBeerByStyle
2025-03-29 16:01:43 +08:00
} from "@/api/platform.js"
import Sieving from '@/components/sieving/index.vue'
2025-03-29 16:01:43 +08:00
export default {
name: 'StyleSelection',
2025-03-29 16:01:43 +08:00
components: {
Sieving
},
data() {
return {
// 列表数据
beerList: [],
totalBeers: 0,
loading: false,
isRefreshing: false,
hasMore: true,
// 筛选相关
activeTab: '',
// 查询参数
queryParams: {
pageNum: 1,
pageSize: 10,
styleId: ''
2025-03-29 16:01:43 +08:00
},
// 筛选配置
2025-03-29 16:01:43 +08:00
dropdownMenuList: [
{
title: '品牌',
type: 'cell',
prop: 'brand',
value: '',
options: [],
showIcon: true,
activeColor: '#D42E78'
},
{
title: '风格',
type: 'cell',
prop: 'style',
value: '',
options: [],
showIcon: true,
activeColor: '#D42E78'
},
{
title: '价格',
type: 'slider',
prop: 'price',
value: {
min: 100,
max: 3000
},
showIcon: true,
activeColor: '#D42E78'
},
{
title: '排序',
type: 'cell',
prop: 'sort',
value: 'comprehensive',
showIcon: true,
activeColor: '#D42E78',
options: [
{ label: '不限', value: 'comprehensive' },
{ label: '高分优先', value: 'rating' },
{ label: '热门优先', value: 'popular' },
{ label: '最新发布', value: 'latest' }
]
}
2025-03-29 16:01:43 +08:00
],
}
2025-03-29 16:01:43 +08:00
},
created() {
this.initData()
2025-03-29 16:01:43 +08:00
},
methods: {
// 初始化数据
async initData() {
try {
await Promise.all([
this.getBrandOptions(),
this.getStyleOptions()
])
await this.getBeerList()
} catch (error) {
console.error('初始化数据失败:', error)
uni.showToast({
title: '加载失败,请重试',
icon: 'none'
})
}
2025-03-29 16:01:43 +08:00
},
// 获取品牌选项
async getBrandOptions() {
try {
const res = await getBrands()
const brands = res.data || []
this.dropdownMenuList[0].options = brands.map(brand => ({
label: brand.brandName,
value: brand.id
}))
} catch (error) {
console.error('获取品牌列表失败:', error)
}
},
// 获取风格选项
async getStyleOptions() {
try {
const res = await getBeerStyles()
const styles = res.data || []
this.dropdownMenuList[1].options = styles.map(style => ({
label: style.beerStyles,
value: style.id
}))
} catch (error) {
console.error('获取风格列表失败:', error)
}
2025-03-29 16:01:43 +08:00
},
// 获取啤酒列表
async getBeerList(isRefresh = false) {
if (this.loading) return
try {
this.loading = true
if (isRefresh) {
this.queryParams.pageNum = 1
this.beerList = []
}
const res = await getBeerByStyle(this.queryParams)
const newList = res.data || []
this.beerList = isRefresh ?
newList : [...this.beerList, ...newList]
this.totalBeers = res.total || 0
this.hasMore = newList.length >= this.queryParams.pageSize
} catch (error) {
console.error('获取啤酒列表失败:', error)
uni.showToast({
title: '加载失败,请重试',
icon: 'none'
})
} finally {
this.loading = false
this.isRefreshing = false
}
2025-03-29 16:01:43 +08:00
},
// 筛选相关方法
handleFilterConfirm(value, allValues) {
const { brand, style, price, sort } = allValues
this.queryParams = {
...this.queryParams,
brandId: brand,
styleId: style,
priceMin: price?.min,
priceMax: price?.max,
sortType: sort
}
this.getBeerList(true)
2025-03-29 16:01:43 +08:00
},
handleFilterOpen(tabName) {
this.activeTab = tabName
2025-03-29 16:01:43 +08:00
},
handleFilterClose() {
this.activeTab = ''
2025-03-29 16:01:43 +08:00
},
// 列表相关方法
loadMore() {
if (!this.hasMore || this.loading) return
this.queryParams.pageNum++
this.getBeerList()
2025-03-29 16:01:43 +08:00
},
async onRefresh() {
this.isRefreshing = true
await this.getBeerList(true)
2025-03-29 16:01:43 +08:00
},
// 导航方法
navigateToBeerDetail(beer) {
uni.navigateTo({
url: `/pages/index/review?beerId=${beer.id}`
})
}
2025-03-29 16:01:43 +08:00
}
}
</script>
<style lang="scss" scoped>
.page {
min-height: 100vh;
background: #F9F9F9;
// 统计信息
.stats-bar {
padding: 16rpx 24rpx;
background: #FFFFFF;
margin-bottom: 24rpx;
box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.05);
.stats-text {
font-size: 24rpx;
color: #999999;
}
}
// 内容区域
.content-container {
flex: 1;
overflow: hidden;
.beer-list {
height: calc(100vh - 180rpx);
padding: 0 24rpx;
.beer-card {
background: #FFFFFF;
border-radius: 16rpx;
margin-bottom: 24rpx;
box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.05);
.beer-info {
display: flex;
align-items: center;
padding: 24rpx;
.beer-image {
width: 120rpx;
height: 120rpx;
border-radius: 12rpx;
margin-right: 24rpx;
object-fit: cover;
}
.beer-details {
flex: 1;
.beer-name {
font-size: 28rpx;
font-weight: 600;
color: #333333;
margin-bottom: 8rpx;
}
.beer-style {
font-size: 24rpx;
color: #666666;
margin-bottom: 8rpx;
}
.brand-name {
font-size: 24rpx;
color: #999999;
}
}
.arrow-icon {
width: 32rpx;
height: 32rpx;
margin-left: 16rpx;
opacity: 0.3;
}
2025-03-29 16:01:43 +08:00
}
}
.empty-state {
display: flex;
flex-direction: column;
align-items: center;
padding: 96rpx 0;
.empty-image {
width: 240rpx;
height: 240rpx;
margin-bottom: 32rpx;
}
.empty-text {
font-size: 28rpx;
color: #999999;
}
}
.loading-status {
padding: 32rpx 0;
text-align: center;
.loading-wrapper {
display: flex;
align-items: center;
justify-content: center;
.loading-icon {
width: 40rpx;
height: 40rpx;
margin-right: 16rpx;
}
.loading-text {
font-size: 24rpx;
color: #999999;
}
}
.no-more {
font-size: 24rpx;
color: #999999;
}
}
2025-03-29 16:01:43 +08:00
}
}
}
// 添加按键反馈效果
.hover-effect {
transition: all 0.2s ease;
&:active {
transform: scale(0.96);
opacity: 0.8;
}
}
// 添加图片加载优化相关样式
.beer-image {
will-change: transform;
backface-visibility: hidden;
transform: translateZ(0);
}
// 添加骨架屏样式
.skeleton {
background: linear-gradient(90deg, #f2f2f2 25%, #e6e6e6 37%, #f2f2f2 63%);
background-size: 400% 100%;
animation: skeleton-loading 1.4s ease infinite;
}
@keyframes skeleton-loading {
0% {
background-position: 100% 50%;
2025-03-29 16:01:43 +08:00
}
100% {
background-position: 0 50%;
}
}
// 文本省略
.text-ellipsis {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
2025-03-29 16:01:43 +08:00
</style>