You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
zhishifufei_uniapp/pages/store/index.vue

625 lines
14 KiB

10 months ago
<template>
<BaseContainer class="store" :fixedNav="false">
9 months ago
<view class="header"
9 months ago
:style="'padding-top:' + (menutop * 2 + 58 + 18) + 'rpx;'">
9 months ago
<view class="search"
@click="getsearch()"
9 months ago
:style="{background: scrollTop > 10 ? '#f5f5f5' : 'transparent', paddingTop: (menutop * 2) + 'rpx', paddingBottom: '20rpx', height: (menutop * 2 + 58 + 20) + 'rpx'}"
9 months ago
>
9 months ago
<view>
9 months ago
<image class="image_icon" :src="getImgPath('/public/images/icon.png')" mode="aspectFill" />
<view class="name">
搜索商品
</view>
9 months ago
</view>
9 months ago
</view>
</view>
<view style="padding: 0 30rpx;">
<view class="swiper-box">
10 months ago
<swiper class="custom-banner" indicator-dots autoplay
@click="handleBannerClick" @change="getChangeImage">
<swiper-item v-for="(item, index) in banner" :key="index" :data-url="item.url" class="swiper-item">
<image :data-url="item.url" mode="aspectFill" :src="item.pic" :alt="item.title" />
</swiper-item>
</swiper>
</view>
<view class="tab-bar-placeholder">
9 months ago
<view class="flex tab-content">
9 months ago
<view :data-idx="index" class="tab-item" v-for="(item, index) in categoryList" :key="item.id" @click="handleCateClick(item)">
9 months ago
<image v-if="item.id > 0" :src="item.pic" mode="aspectFill"></image>
<image v-else :src="getImgPath('/static/frontend/more.png')" mode="aspectFill"></image>
<view>{{ item.name }}</view>
9 months ago
</view>
</view>
10 months ago
</view>
9 months ago
<!-- 广告 -->
9 months ago
<advert />
10 months ago
<view class="goods-section">
9 months ago
<view class="goods-title">精品推荐</view>
10 months ago
<view class="list">
9 months ago
<navigator hover-class="none" v-for="item in goodsList" :key="item.id" class="item flex"
10 months ago
:url="'/pages/store/detail?id=' + item.id">
<view class="image">
<image mode="aspectFit" class="img" :src="item.image" alt="" />
</view>
<view class="text">
<view class="title">{{ item.store_name }}</view>
<view class="group">
9 months ago
<view class="group-l">
<view class="price">
<span class="num">{{ item.price }}</span>
</view>
<view class="sale">已售{{ item.sales }}</view>
</view>
<view class="group-r">
<view class="auth-btn flex">
<image src="@/static/images/store/icon.png" mode="aspectFill"></image>
正版授权
</view>
</view>
10 months ago
</view>
</view>
</navigator>
</view>
<view v-if="goodsList.length && !loading" class="finished">{{ loadTitle }}</view>
<view v-if="finished && !goodsList.length" class="empty">
<image mode="aspectFill" :src="getImgPath('/wap/first/zsff/images/empty.png')" alt="暂无商品" />
<view>暂无商品</view>
</view>
<!-- <view style="height: var(--tab-bar-height)"></view> -->
</view>
</view>
</BaseContainer>
</template>
<script>
9 months ago
import { getGoodsCateList, getGoodsList, getRecommendGoodsList, getIndexData } from "@/api/store";
9 months ago
import RecommendPoster from "@/components/RecommendPoster/index.vue";
9 months ago
import Advert from '@/components/Advert/index.vue';
10 months ago
export default {
9 months ago
components: {
RecommendPoster,
9 months ago
Advert,
9 months ago
},
10 months ago
data() {
const systemInfo = this.$util.getSystemInfo();
const { statusBarHeight } = systemInfo;
return {
9 months ago
advertList: [
{
"id": 46,
"title": "广告1",
"url": "#",
"banner": "https://mytest101011.oss-cn-shenzhen.aliyuncs.com/d588f202305161726583206.png",
"sort": "0"
}
],
10 months ago
statusBarHeight,
banner: [],
categoryList: [],
goodsList: [],
activeId: 0,
loadTitle: "",
page: 1,
limit: 16,
loading: false,
finished: false,
isFixed: false,
offsetTop: 0,
offsetHeight: 0,
tabBarFixed: false,
tabBarTopSize: 0,
color_one: '',
9 months ago
color_two: '',
menutop: 10,
9 months ago
scrollTop: 0,
10 months ago
};
},
onLoad() {
this.handlePageScroll = this.$util.debounce(this.handlePageScroll, 30);
9 months ago
let menuButtonInfo = uni.getMenuButtonBoundingClientRect();
/* #ifdef MP-WEIXIN || MP-KUAISHOU */
this.menutop = menuButtonInfo.top;
/* #endif */
/* #ifdef APP-PLUS */
let platform = uni.getSystemInfoSync().platform
if(platform === 'ios'){
this.menutop = 60;
}else{
this.menutop = 40;
}
/* #endif */
/* #ifdef MP-TOUTIAO */
this.menutop = 10;
/* #endif */
this.getGoodsCateList();
9 months ago
// this.getGoodsList();
this.getRecommendGoodsList();
10 months ago
this.getIndexData();
},
onReachBottom() {
9 months ago
// this.getGoodsList();
10 months ago
},
onPageScroll({ scrollTop }) {
9 months ago
this.scrollTop = scrollTop;
10 months ago
this.handlePageScroll(scrollTop);
},
onShareAppMessage() {
return {};
},
onShareTimeline() {
return {};
},
mounted() {
},
methods: {
9 months ago
getsearch() {
uni.navigateTo({
url:'/pages/store/goodsList'
})
},
10 months ago
handlePageScroll(scrollTop) {
9 months ago
console.log(scrollTop);
10 months ago
this.tabBarFixed = scrollTop + this.statusBarHeight >= this.tabBarTopSize;
},
async getIndexData() {
try {
const { data } = await getIndexData();
this.banner = data;
if(!this.color_one && !this.color_two){
this.color_one = this.banner[0].color_one;
this.color_two = this.banner[0].color_two;
}
} catch (err) { }
},
// 点击轮播图
handleBannerClick(e) {
if (e.target.dataset.url === undefined) return;
uni.navigateTo({
url: e.target.dataset.url,
});
},
getChangeImage(e) {
this.banner.forEach((item, index) => {
if (index == e.detail.current) {
this.color_one = item.color_one;
this.color_two = item.color_two;
}
});
},
// 获取分类
async getGoodsCateList() {
try {
const { data } = await getGoodsCateList();
console.log(data);
this.categoryList = data.category_list.concat([
{
name: "全部",
id: 0,
},
]);
} catch (err) { }
},
9 months ago
async getRecommendGoodsList() {
// if (this.loading || this.finished) {
// return;
// }
this.loadTitle = "";
this.loading = true;
try {
const { data } = await getRecommendGoodsList({});
console.log('recommendGoodsList', data);
this.goodsList = data;
console.log(this.goodsList);
} catch (err) {
console.log(err);
}
this.loading = false;
},
10 months ago
// 获取商品列表
async getGoodsList() {
if (this.loading || this.finished) {
return;
}
this.loadTitle = "";
this.loading = true;
try {
const { data } = await getGoodsList({
cId: this.activeId,
page: this.page++,
limit: this.limit,
});
9 months ago
9 months ago
this.goodsList = this.goodsList.concat(data);
9 months ago
console.log(this.goodsList);
10 months ago
this.finished = data.length < this.limit;
this.loadTitle = this.finished ? "已全部加载完" : "上拉加载更多";
9 months ago
} catch (err) {
console.log(err);
}
10 months ago
this.loading = false;
},
// 点击商品分类
9 months ago
handleCateClick(item) {
if (item.name === '全部') {
9 months ago
console.log(1);
uni.navigateTo({
url: '/pages/store/goodsCate'
});
} else {
uni.navigateTo({
9 months ago
url: `/pages/store/goodsList?categoryId=${item.id}`
9 months ago
});
}
10 months ago
},
},
};
</script>
<style>
page{
background: #F7F8F9;
}
</style>
<style lang="scss" scoped>
9 months ago
.goods-section{
width: 690rpx;
border-radius: 24rpx;
margin: auto;
.goods-title {
padding-left: 23rpx;
position: relative;
color: #333;
font-size: 34rpx;
line-height: 74rpx;
margin-bottom: 33rpx;
margin-top: 48rpx;
&:before {
content: '';
background: linear-gradient(0deg, #24a9e1, #0f74bb);
position: absolute;
top: 50%;
left: 0;
transform: translateY(-50%);
width: 8rpx;
height: 26rpx;
border-radius: 4rpx;
}
}
}
.advert {
9 months ago
background: transparent;
padding: 0;
>image {
width: 100%;
height: 110rpx;
}
}
swiper {
/deep/ {
.wx-swiper-dots-horizontal,
.uni-swiper-dots-horizontal {
left: 70%;
}
.wx-swiper-dot,
.uni-swiper-dot {
width: 12rpx;
height: 8rpx;
background: #8ab1ff;
border-radius: 4rpx;
float: left;
}
.wx-swiper-dot-active,
.uni-swiper-dot-active {
width: 24rpx;
height: 8rpx;
background: #FFFFFF !important;
border-radius: 4rpx;
}
}
}
10 months ago
.nothing {
position: absolute;
top: 50%;
left: 50%;
width: 400rpx;
height: 400rpx;
transform: translate(-50%, -50%);
}
.swiper-box {
/* #ifndef MP-TOUTIAO */
height: 306rpx;
/* #endif */
}
.custom-banner {
9 months ago
width: 690rpx;
height: 290rpx;
10 months ago
margin: 0 auto;
overflow: hidden;
}
.swiper-item {
padding: 30rpx 0;
}
.swiper-item image {
width: 100%;
height: 100%;
}
swiper {
/deep/ {
.wx-swiper-dots-horizontal,
.uni-swiper-dots-horizontal {
bottom: 60rpx;
}
.wx-swiper-dot,
.uni-swiper-dot {
width: 10rpx;
height: 10rpx;
border-radius: 5rpx;
margin-right: 5rpx;
margin-left: 5rpx;
}
.wx-swiper-dot-active,
.uni-swiper-dot-active {
width: 20rpx;
}
}
}
.tab-content {
9 months ago
width: 690rpx;
margin: 30rpx auto 22rpx;
background: #fff;
flex-wrap: wrap;
padding-top: 30rpx;
border-radius: 10rpx;
10 months ago
}
.tab-item {
9 months ago
width: 25%;
font-size: 24rpx;
line-height: 24rpx;
10 months ago
font-weight: 400;
9 months ago
color: #666;
margin-bottom: 50rpx;
display: flex;
flex-direction: column;
align-items: center;
>image {
width: 94rpx;
height: 94rpx;
margin-bottom: 11rpx;
}
>view {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
10 months ago
}
/* #ifdef MP-KUAISHOU */
.swiper-item{
padding: 0 !important;
}
/* #endif */
.store{
9 months ago
// padding-bottom: calc(var(--tab-bar-height) + 60rpx);
9 months ago
background: linear-gradient(to top, transparent 0%, #f6f6f6 70%, #D3F2FF 80%, #53B2F5 100%);
9 months ago
}
.store .header {
z-index: 99;
width: 100%;
}
9 months ago
.store .header .search {width: 100%;
9 months ago
font-size: 26rpx;
color: #aaa;
padding: 0;
9 months ago
position: fixed;
top: 0;
left: 0;
z-index: 100;
>view {
width: 90%;
background-color: #fff;
display: flex;
align-items: center;
border-radius: 40rpx;
height: 100%;
margin-left: 5%;
/* #ifdef MP-WEIXIN */
width: 65%;
/* #endif */
}
9 months ago
.iconfont2,
.iconfont {
margin-right: 16rpx;
font-size: 28rpx;
;
line-height: 1;
color: #aaa;
}
.image_icon {
width: 42rpx;
height: 42rpx;
margin-left: 28rpx;
}
.name {
margin-left: 10rpx;
}
}
10 months ago
/* 商品列表 */
.store .finished,
.store .loading {
font-size: 28rpx;
line-height: 100rpx;
text-align: center;
color: #bbb;
}
.store .fa-spin {
animation: fa-spin 1s infinite linear;
}
.store .empty {
margin-top: 100rpx;
font-size: 28rpx;
text-align: center;
color: #bbb;
}
.store .empty image {
display: block;
width: 414rpx;
height: 305rpx;
margin: 0 auto;
pointer-events: none;
}
.store .banner {
position: relative;
padding-top: 30rpx;
padding-bottom: 30rpx;
}
.store .banner .swiper-container {
width: 710rpx;
height: 310rpx;
border-radius: 20rpx;
}
.store .banner image {
display: block;
width: 100%;
height: 100%;
border-radius: 20rpx;
object-fit: cover;
pointer-events: none;
}
.store .nothing {
display: block;
width: 414rpx;
margin: 30rpx auto;
pointer-events: none;
-webkit-touch-callout: none;
}
.store .list {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
}
.store .list .item {
9 months ago
width: 334rpx;
height: 455rpx;
margin-bottom: 20rpx;
background: #fff;
flex-direction: column;
align-items: center;
padding-bottom: 25rpx;
&:nth-child(2n + 1) {
margin-right: 20rpx;
}
10 months ago
}
.store .list .image {
9 months ago
width: 250rpx;
height: 225rpx;
10 months ago
overflow: hidden;
display: flex;
justify-content: center;
align-items: center;
9 months ago
margin-bottom: 30rpx;
10 months ago
}
.store .list .image .img {
9 months ago
width: 100%;
height: 100%;
10 months ago
object-fit: scale-down;
pointer-events: none;
-webkit-touch-callout: none;
}
.store .list .text {
9 months ago
flex: 1;
9 months ago
width: 100%;
10 months ago
display: flex;
flex-direction: column;
justify-content: space-between;
9 months ago
padding: 0 20rpx;
10 months ago
}
.store .list .title {
overflow: hidden;
font-size: 28rpx;
9 months ago
line-height: 35rpx;
height: 70rpx;
color: #333;
10 months ago
-webkit-line-clamp: 2;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-box-orient: vertical;
}
.store .list .group {
display: flex;
justify-content: space-between;
align-items: center;
9 months ago
margin-top: auto;
10 months ago
}
.store .list .price {
9 months ago
font-size: 22rpx;
line-height: 32rpx;
color: #F8473E;
10 months ago
}
.store .list .price .num {
font-size: 32rpx;
}
.store .list .sale {
9 months ago
font-size: 20rpx;
line-height: 20rpx;
color: #999;
margin-top: 7rpx;
}
.store .list .auth-btn {
width: 130rpx;
height: 39rpx;
border-radius: 6rpx;
border: 1px solid #0F74BB;
justify-content: center;
color: #0F74BB;
font-size: 20rpx;
9 months ago
line-height: 39rpx;
9 months ago
image {
width: 20rpx;
height: 23rpx;
margin-right: 8rpx;
9 months ago
margin-top: 7rpx;
9 months ago
}
}
10 months ago
</style>