| New file |
| | |
| | | <template> |
| | | <view class="page"> |
| | | <top-bar selectedTitleIndex="kitchenCustomize" textColor="black" bgColor="#ffffff" @changeTab="topBarChange"></top-bar> |
| | | <view class="banner"> |
| | | <image class="banner-img" :src="banner" mode="aspectFill"></image> |
| | | </view> |
| | | <view class="content"> |
| | | <scroll-view class="tags-scroll" scroll-x="true" :show-scrollbar="false"> |
| | | <view class="tags"> |
| | | <view v-for="tag in tags" :key="tag.value" class="tag" :class="{ active: tag.selected }" |
| | | @click="toggleTag(tag)"> |
| | | <text>{{ tag.label }}</text> |
| | | </view> |
| | | </view> |
| | | </scroll-view> |
| | | <!-- 新增商品列表 --> |
| | | <view class="product-list"> |
| | | <view v-for="item in products" :key="item.id" class="product-card" @click="goToDetail(item)"> |
| | | <image class="product-img" :src="item.coverImg" mode="aspectFill"></image> |
| | | <view> |
| | | <view class="product-top"> |
| | | <view class="product-name">{{ item.comboName }}</view> |
| | | <view class="product-num">{{ item.num }}</view> |
| | | |
| | | </view> |
| | | <view class="product-info"> |
| | | <view class="product-remark">{{ item.remark }}</view> |
| | | <view class="product-bottom"> |
| | | <view class="product-orign-price"> |
| | | <text class="symbol">原价¥</text> |
| | | <text class="value">{{ item.orginPrice }}</text> |
| | | </view> |
| | | <view class="product-price"> |
| | | <text class="symbol">¥</text> |
| | | <text class="value">{{ item.price }}</text> |
| | | </view> |
| | | </view> |
| | | </view> |
| | | |
| | | </view> |
| | | </view> |
| | | <view v-if="products.length === 0" class="empty-tip"> |
| | | 暂无相关商品 |
| | | </view> |
| | | <!-- 加载更多提示 --> |
| | | <view class="load-more-tip" v-else> |
| | | <text v-if="loadStatus === 'loading'">加载中...</text> |
| | | <text v-else-if="loadStatus === 'noMore'">没有更多了</text> |
| | | <text v-else>上拉加载更多</text> |
| | | </view> |
| | | </view> |
| | | </view> |
| | | </view> |
| | | </template> |
| | | <script> |
| | | import { getKitchenTag, getKitchenBanner, getKitchenGoods } from "@/api/kitchen.js"; |
| | | import TopBar from "@/components/TopBar.vue"; |
| | | export default { |
| | | components: { |
| | | TopBar, |
| | | }, |
| | | data() { |
| | | return { |
| | | banner: '', |
| | | tags: [], |
| | | // 新增模拟商品数据 |
| | | queryParams: { |
| | | tagId: '', |
| | | pageSize: 5, |
| | | pageNumber: 1, |
| | | }, |
| | | loadStatus: 'more', // more, loading, noMore |
| | | products: [] |
| | | }; |
| | | }, |
| | | computed: { |
| | | // 新增过滤逻辑 |
| | | // filteredProducts() { |
| | | // const selectedValues = this.tags.filter(t => t.selected).map(t => t.value); |
| | | // if (selectedValues.length === 0) { |
| | | // return this.products; |
| | | // } |
| | | // // 新增判断是否包含'全部'标签 |
| | | // if (selectedValues.includes('all')) { |
| | | // return this.products; |
| | | // } |
| | | // return this.products.filter(item => selectedValues.includes(item.category)); |
| | | // } |
| | | }, |
| | | onLoad() { |
| | | this.initData(); |
| | | }, |
| | | onReachBottom() { |
| | | if (this.loadStatus === 'more') { |
| | | this.queryParams.pageNumber++; |
| | | this.getProductList(); |
| | | } |
| | | }, |
| | | methods: { |
| | | async initData() { |
| | | await getKitchenBanner().then(res => { |
| | | if (res.statusCode === 200) { |
| | | this.banner = res.data.data[0].coverUrl; |
| | | console.log(res) |
| | | } |
| | | }); |
| | | await getKitchenTag().then(res => { |
| | | if (res.statusCode === 200) { |
| | | if (res.data.data.length > 0) { |
| | | this.tags = res.data.data |
| | | .sort((a, b) => (a.sort || 0) - (b.sort || 0)) |
| | | .map((item, index) => ({ |
| | | label: item.tagName, |
| | | value: item.id, |
| | | selected: index === 0 |
| | | })); |
| | | } |
| | | } |
| | | }); |
| | | this.queryParams.tagId = this.tags[0].value; |
| | | this.getProductList(); |
| | | |
| | | }, |
| | | getProductList() { |
| | | if (this.loadStatus === 'loading') return; |
| | | this.loadStatus = 'loading'; |
| | | getKitchenGoods(this.queryParams).then(res => { |
| | | if (res.statusCode === 200) { |
| | | const newList = res.data.data || []; |
| | | if (this.queryParams.pageNumber === 1) { |
| | | this.products = newList; |
| | | } else { |
| | | this.products = this.products.concat(newList); |
| | | } |
| | | |
| | | // 判断是否还有更多数据 |
| | | if (newList.length < this.queryParams.pageSize) { |
| | | this.loadStatus = 'noMore'; |
| | | } else { |
| | | this.loadStatus = 'more'; |
| | | } |
| | | } else { |
| | | this.loadStatus = 'more'; |
| | | } |
| | | }).catch(() => { |
| | | this.loadStatus = 'more'; |
| | | }); |
| | | }, |
| | | toggleTag(tag) { |
| | | console.log("点击了标签:", tag); |
| | | if (tag.selected) return; // 已经是选中状态则不重复加载 |
| | | |
| | | // 将所有标签设为未选中,然后将当前点击的标签设为选中(单选逻辑) |
| | | this.tags.forEach(t => { |
| | | t.selected = (t.value === tag.value); |
| | | }); |
| | | |
| | | // 重置分页参数 |
| | | this.queryParams.tagId = tag.value; |
| | | this.queryParams.pageNumber = 1; |
| | | this.products = []; |
| | | this.loadStatus = 'more'; |
| | | |
| | | // 重新获得商品 |
| | | this.getProductList(); |
| | | }, |
| | | goToDetail(item) { |
| | | console.log("跳转详情:", item); |
| | | uni.navigateTo({ |
| | | url: `/pages/product/goods?id=${item.skuId}&goodsId=${item.goodsId}` |
| | | }); |
| | | }, |
| | | topBarChange(titleObj) { |
| | | console.log("顶部导航切换:", titleObj); |
| | | if (titleObj.pagePath) { |
| | | if (titleObj.pagePath.includes('home')) { |
| | | uni.reLaunch({ |
| | | url: titleObj.pagePath |
| | | }); |
| | | } else { |
| | | uni.navigateTo({ |
| | | url: titleObj.pagePath |
| | | }); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }; |
| | | </script> |
| | | <style lang="scss" scoped> |
| | | .page { |
| | | min-height: 100vh; |
| | | background-color: #f4f4f4; |
| | | padding-top: 160rpx; // 增加空间,确保不与导航栏重叠 |
| | | } |
| | | |
| | | .banner { |
| | | width: 100%; |
| | | height: 450rpx; |
| | | padding: 24rpx; |
| | | border-radius: 24rpx; |
| | | box-sizing: border-box; |
| | | margin-top: 10rpx; // 额外增加一点间距 |
| | | } |
| | | |
| | | .banner-img { |
| | | width: 100%; |
| | | height: 100%; |
| | | border-radius: 24rpx; |
| | | } |
| | | |
| | | .content { |
| | | padding: 24rpx; |
| | | } |
| | | |
| | | .tags-scroll { |
| | | width: 100%; |
| | | white-space: nowrap; |
| | | } |
| | | |
| | | .tags { |
| | | display: flex; |
| | | flex-wrap: nowrap; |
| | | padding: 10rpx 0; |
| | | } |
| | | |
| | | .tag { |
| | | height: 80rpx; |
| | | display: inline-flex; |
| | | align-items: center; |
| | | justify-content: center; |
| | | font-size: 30rpx; |
| | | color: black; |
| | | border: 1rpx solid #e5e5e5; |
| | | border-radius: 25rpx 25rpx 0 0; |
| | | background-color: #f7f7f7; |
| | | white-space: nowrap; |
| | | flex-shrink: 0; |
| | | } |
| | | |
| | | .tag.active { |
| | | background: linear-gradient(to bottom, #d2c29e, #FFFFFF); |
| | | border-color: linear-gradient(to bottom, #d2c29e, #FFFFFF); |
| | | } |
| | | |
| | | // 新增商品列表样式 |
| | | .product-list { |
| | | display: flex; |
| | | flex-direction: column; |
| | | gap: 24rpx; |
| | | } |
| | | |
| | | .product-card { |
| | | background-color: #ffffff; |
| | | border-radius: 20rpx; |
| | | padding: 20rpx; |
| | | box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.05); |
| | | } |
| | | |
| | | .product-img { |
| | | background-color: #999; |
| | | width: 100%; |
| | | height: 350rpx; |
| | | border-radius: 12rpx; |
| | | flex-shrink: 0; |
| | | } |
| | | |
| | | .product-info { |
| | | flex: 1; |
| | | margin-left: 20rpx; |
| | | display: flex; |
| | | align-items: center; |
| | | justify-content: space-between; |
| | | overflow: hidden; // 确保子元素溢出隐藏 |
| | | } |
| | | |
| | | .product-top { |
| | | flex: 1; |
| | | margin-left: 20rpx; |
| | | display: flex; |
| | | // flex-direction: column; |
| | | // justify-content: space-between; |
| | | } |
| | | |
| | | .product-name { |
| | | font-size: 30rpx; |
| | | font-weight: bold; |
| | | color: #333; |
| | | line-height: 1.4; |
| | | } |
| | | |
| | | .product-num { |
| | | width: 80rpx; |
| | | border-radius: 25rpx; |
| | | display: flex; |
| | | align-items: center; |
| | | justify-content: center; |
| | | font-size: 24rpx; |
| | | margin-left: 10rpx; |
| | | color: #ae9e7f; |
| | | background-color: #f6f2e3; |
| | | } |
| | | |
| | | .product-remark { |
| | | font-size: 24rpx; |
| | | color: #999; |
| | | flex: 1; // 占据剩余空间 |
| | | margin-right: 20rpx; |
| | | white-space: nowrap; // 不换行 |
| | | overflow: hidden; // 溢出隐藏 |
| | | text-overflow: ellipsis; // 显示省略号 |
| | | } |
| | | |
| | | .product-bottom { |
| | | display: flex; |
| | | justify-content: space-between; |
| | | align-items: flex-end; |
| | | } |
| | | |
| | | .product-orign-price { |
| | | font-size:24rpx; |
| | | color: #999; |
| | | text-decoration: line-through; |
| | | } |
| | | |
| | | .product-price { |
| | | color: #ff573e; |
| | | |
| | | .symbol { |
| | | font-size: 24rpx; |
| | | } |
| | | |
| | | .value { |
| | | font-size: 50rpx; |
| | | font-weight: bold; |
| | | } |
| | | } |
| | | |
| | | .buy-btn { |
| | | padding: 10rpx 24rpx; |
| | | background-color: #333; |
| | | color: #fff; |
| | | font-size: 24rpx; |
| | | border-radius: 30rpx; |
| | | } |
| | | |
| | | .empty-tip { |
| | | text-align: center; |
| | | padding: 100rpx 0; |
| | | color: #999; |
| | | font-size: 28rpx; |
| | | } |
| | | |
| | | .load-more-tip { |
| | | text-align: center; |
| | | padding: 30rpx 0; |
| | | color: #999; |
| | | font-size: 24rpx; |
| | | } |
| | | .topBar { |
| | | position: fixed; |
| | | top: 20rpx; |
| | | left: 20rpx; |
| | | z-index: 1000 |
| | | } |
| | | </style> |