martial-arts/pages/tabbar/shop/shop.vue

151 lines
3.9 KiB
Vue
Raw Normal View History

2022-08-01 09:03:10 +00:00
<template>
2022-08-03 13:28:45 +00:00
<view>
<status-container :ifReturn="false" titlet="产品列表">
2022-08-01 09:03:10 +00:00
<view slot="content">
2022-08-03 13:28:45 +00:00
<view class="posi-sticky" :style="{top:newtop+'px'}" style="margin-top: -20rpx;">
<swiper-tab id="tab" :ifBetween="false" :list="dataList" v-model="current" @changeEv="clickTab" :itemColor="'#e42417'" :lineColor="'#e42417'"></swiper-tab>
</view>
<view class="pad-zy20">
<list ref="refproduct" @goDetail="goDetail"></list>
2022-08-16 10:06:46 +00:00
<view class="" v-if="loading">
<pitera :textStr="`${noMore && total > $refs.refproduct.list.length?'上滑加载更多':'到底了'}~~`" textColor="#b0aaa9" paddingStr="40rpx 0 20rpx 0"></pitera>
</view>
2022-08-03 13:28:45 +00:00
</view>
2022-08-01 09:03:10 +00:00
</view>
</status-container>
2022-08-16 10:06:46 +00:00
<!-- 购物车图标 -->
2022-08-18 08:21:58 +00:00
<view class="posi cart-box">
<image @tap="goCart" class="" src="/static/tabbar/icon-cart.png" mode="" lazy-load></image>
<view class="colf fon24 disjcac">{{cartNum}}</view>
</view>
2022-08-01 09:03:10 +00:00
<!-- 底部tab -->
<foot-tab current="1"></foot-tab>
</view>
</template>
<script>
// 底部组件
import footTab from '@/components/foot-tabs/foot-tab.vue';
2022-08-03 13:28:45 +00:00
import swiperTab from '@/components/swiper-tab/swiper-tab.vue';
import list from '@/components/list.vue';
import pitera from '@/components/nothing/pitera.vue';
2022-08-18 06:22:40 +00:00
import { mapState } from 'vuex';
import { checkCartNum } from '@/jsFile/public-api.js';
2022-08-01 09:03:10 +00:00
export default {
components:{
'foot-tab' :footTab,
2022-08-03 13:28:45 +00:00
swiperTab,
list,
pitera
2022-08-01 09:03:10 +00:00
},
data() {
return {
2022-08-03 13:28:45 +00:00
newtop:uni.getSystemInfoSync().statusBarHeight + 42,
current:0,//当前分类索引
dataList:[],//分类列表
classId:'',//分类id
page:1,
size:10,
total:0,
noMore:false,//是否没有更多
2022-08-16 10:06:46 +00:00
loading:false
2022-08-01 09:03:10 +00:00
}
},
2022-08-18 06:22:40 +00:00
computed:{
...mapState({
cartNum: state => state.moduleA.cartNum
})
},
onLoad() {
// 调用获取分类列表
this.getHomeCate();
2022-08-18 06:22:40 +00:00
this.cartNumEv();
},
onReachBottom() {
if(this.total!=this.$refs.refproduct.list.length){
this.page++;
// 调用获取商品产品列表
this.getProductList();
}
},
onShow() {
uni.removeStorageSync('orderInfo');
uni.removeStorageSync('skuList');
},
2022-08-01 09:03:10 +00:00
methods: {
2022-08-18 06:22:40 +00:00
// 查询购物车数量
cartNumEv(){
checkCartNum().then(res=>{
if(res.code==0){
this.$store.commit('setCartNum',res.data.count);
}
})
},
2022-08-03 13:28:45 +00:00
// tab点击事件
clickTab(index){
this.current = index;
this.page = 1;
this.noMore = false;
// 设置分类id
this.classId = this.dataList[index].id;
// 调用获取商品产品列表
this.getProductList();
},
// 获取分类列表
getHomeCate(){
this.$requst.get('/api/spu/category',{type:'normal',need_all:1}).then(res=>{
// 设置分类列表
this.dataList = res.data;
// 如果分类列表不为空
if(this.dataList.length){
// 设置分类id
this.classId = this.dataList[0].id;
// 调用获取商品产品列表
this.getProductList();
}
})
},
// 获取商品产品列表
getProductList(){
2022-08-16 10:06:46 +00:00
this.loading = false;
let params = {
category_id:this.classId,
page:this.page,
size:this.size
}
this.$requst.post('/api/spu/list',params).then(res=>{
if(res.code==0){
// 设置总数
this.total = res.data.total;
if(this.page==1){this.$refs.refproduct.list=[];}
// 设置产品列表
this.$refs.refproduct.list = [...this.$refs.refproduct.list,...res.data.list];
if(this.total==this.$refs.refproduct.list.length && this.page!=1){
this.noMore = true;
}
2022-08-16 10:06:46 +00:00
this.loading = true;
}
})
2022-08-03 13:28:45 +00:00
},
// 去商品详情
goDetail(id){
2022-08-14 14:27:26 +00:00
if(this.$toolAll.tools.judgeAuth()) {
uni.navigateTo({
url:`/pagesB/shop-detail/shop-detail?id=${id}`
})
}
2022-08-16 10:06:46 +00:00
},
// 前往购物车
goCart(){
if(this.$toolAll.tools.judgeAuth()) {
this.$toolAll.tools.goPage('/pagesB/cart/cart')
}
2022-08-03 13:28:45 +00:00
}
2022-08-01 09:03:10 +00:00
}
}
</script>
<style>
</style>