2022-05-25 09:55:44 +00:00
|
|
|
<template>
|
|
|
|
<view>
|
|
|
|
<status-container :ifReturn="false" titlet="分类">
|
|
|
|
<view slot="content" style="margin: -20rpx -20rpx 0 -20rpx;">
|
|
|
|
<view class="dis">
|
2022-05-26 10:35:10 +00:00
|
|
|
<view class="cate-left-box">
|
2022-05-25 09:55:44 +00:00
|
|
|
<scroll-view scroll-y :style="{height: scrollHeight +'px'}" class="bacf">
|
2022-06-13 08:13:03 +00:00
|
|
|
<view>
|
2022-05-25 09:55:44 +00:00
|
|
|
<view class="flexs clips1 pad-z20 fon24"
|
2022-05-27 06:57:50 +00:00
|
|
|
@tap="chooseCate(index,item.id)" :style="{backgroundColor: current==index ? '#ff3673' : '#FFFFFF',color: current==index ? '#FFFFFF' : '#000000'}"
|
2022-05-25 09:55:44 +00:00
|
|
|
v-for="(item,index) in cateList" :key="index" style="min-width: 160rpx;height: 86rpx;line-height: 86rpx;box-sizing: border-box;" >{{item.title}}</view>
|
|
|
|
</view>
|
|
|
|
</scroll-view>
|
|
|
|
</view>
|
2022-06-02 08:55:16 +00:00
|
|
|
<view class="pad-zy20" style="width: 100%;">
|
2022-06-13 08:13:03 +00:00
|
|
|
<scroll-view :style="{height: scrollHeight +'px'}" style="padding-bottom: 130rpx;"
|
|
|
|
scroll-y="true"
|
|
|
|
:scroll-into-view="doms"
|
|
|
|
scroll-with-animation
|
|
|
|
@scroll="scrolls"
|
|
|
|
@scrolltolower="scrollBottomEv">
|
|
|
|
<view class="posir" :id="'product'+index" v-for="(item,index) in dataList" :key="index">
|
|
|
|
<view class="disac bbt-d9 pad-sx30" @tap="goDetail(item.id)" v-for="(item1,index1) in item" :key="index1">
|
|
|
|
<view class="cate-title" v-if="item.length > 0">{{cateList[index].title}}</view>
|
|
|
|
<view class="cate-txt">
|
|
|
|
<image class="radius30 flexs borbot-cc" :src="item1.imgsrc" mode="aspectFill" style="width: 240rpx;height: 240rpx;"></image>
|
|
|
|
<view class="width100 disjb fc mar-z20" style="height: 240rpx;">
|
|
|
|
<view class="fon30 colb clips2">{{item1.title}}</view>
|
|
|
|
<view class="">
|
|
|
|
<view class="fon36 textc mar-x36">¥{{item1.price}}</view>
|
|
|
|
<view @tap.stop="addCartEv(item1.skuId)" class="colf disjcac fon24 radius30 cate-btn">
|
|
|
|
<i class="icon icon-shop-cart mar-y10" style="font-size: 36rpx;"></i>
|
|
|
|
立即选购
|
|
|
|
</view>
|
2022-05-26 10:35:10 +00:00
|
|
|
</view>
|
|
|
|
</view>
|
2022-05-25 09:55:44 +00:00
|
|
|
</view>
|
|
|
|
</view>
|
|
|
|
</view>
|
2022-05-26 10:35:10 +00:00
|
|
|
</scroll-view>
|
2022-05-25 09:55:44 +00:00
|
|
|
</view>
|
|
|
|
</view>
|
|
|
|
</view>
|
|
|
|
</status-container>
|
|
|
|
<!-- 底部tab -->
|
2022-05-26 10:35:10 +00:00
|
|
|
<foot-tab current="1"></foot-tab>
|
2022-05-25 09:55:44 +00:00
|
|
|
</view>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import listOne from '@/components/list/list-one';
|
|
|
|
import pitera from '@/components/nothing/pitera';
|
|
|
|
import swiperTabJl from '@/components/swiper-tab/swiper-tab-jl.vue';
|
|
|
|
// 底部组件
|
|
|
|
import footTab from '@/components/foot-tabs/foot-tab.vue';
|
2022-06-06 05:49:21 +00:00
|
|
|
import {getCartNum} from '@/jsFile/public-api.js';
|
2022-05-27 06:57:50 +00:00
|
|
|
import { mapState } from 'vuex'//引入mapState
|
2022-05-25 09:55:44 +00:00
|
|
|
export default {
|
|
|
|
components:{
|
|
|
|
'foot-tab' :footTab,
|
|
|
|
listOne,
|
|
|
|
pitera,
|
|
|
|
swiperTabJl
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
current:0,
|
|
|
|
scrollHeight:uni.getSystemInfoSync().windowHeight - uni.getSystemInfoSync().statusBarHeight - 50,
|
2022-05-26 10:35:10 +00:00
|
|
|
newWidth:uni.getSystemInfoSync().windowWidth,
|
2022-06-02 08:55:16 +00:00
|
|
|
cateList:[], //分类导航列表
|
2022-05-27 11:59:47 +00:00
|
|
|
activeIndex:0,
|
2022-06-02 08:55:16 +00:00
|
|
|
secendCateList:[],
|
|
|
|
dataList:[], //商品列表
|
2022-05-26 10:35:10 +00:00
|
|
|
total:0,
|
|
|
|
flag:true,
|
2022-05-27 06:57:50 +00:00
|
|
|
ifLoading:false,
|
2022-06-13 08:13:03 +00:00
|
|
|
pid:'',//分类id
|
|
|
|
doms:'',
|
|
|
|
topList:[]
|
2022-05-25 09:55:44 +00:00
|
|
|
}
|
|
|
|
},
|
2022-05-26 10:35:10 +00:00
|
|
|
computed:{
|
|
|
|
...mapState({
|
|
|
|
footHeight: state => state.moduleA.footHeight,
|
|
|
|
}),
|
|
|
|
},
|
2022-05-25 09:55:44 +00:00
|
|
|
onLoad(op) {
|
2022-05-26 10:35:10 +00:00
|
|
|
this.scrollHeight = this.scrollHeight - this.footHeight;
|
2022-05-25 09:55:44 +00:00
|
|
|
if(op.index) {
|
|
|
|
this.current = op.index;
|
|
|
|
}
|
2022-05-27 06:57:50 +00:00
|
|
|
this.checkShopCate();
|
2022-05-25 09:55:44 +00:00
|
|
|
},
|
|
|
|
methods: {
|
2022-05-27 06:57:50 +00:00
|
|
|
// 查询商品列表
|
2022-06-13 08:13:03 +00:00
|
|
|
checkShopList(){
|
|
|
|
for(let i=0;i<this.cateList.length;i++){
|
|
|
|
console.log(i)
|
|
|
|
this.ifLoading = true;
|
|
|
|
let params = {
|
|
|
|
category_id:this.cateList[i].id
|
|
|
|
}
|
|
|
|
this.$requst.post('/api/spu/list',params).then(res=>{
|
|
|
|
if(res.code==0) {
|
|
|
|
this.total = res.data.total;
|
|
|
|
let newArr = [];
|
2022-05-27 06:57:50 +00:00
|
|
|
res.data.list.forEach(item=>{
|
|
|
|
let obj = {
|
|
|
|
id:item.id,
|
2022-05-27 09:43:21 +00:00
|
|
|
skuId:item.skuId,
|
2022-05-27 06:57:50 +00:00
|
|
|
imgsrc:item.cover,
|
|
|
|
title:item.name,
|
|
|
|
price:this.$toolAll.tools.changeNum(parseInt(item.price)+'')
|
|
|
|
}
|
2022-06-13 08:13:03 +00:00
|
|
|
newArr.push(obj);
|
2022-05-27 06:57:50 +00:00
|
|
|
})
|
2022-06-13 08:13:03 +00:00
|
|
|
this.dataList[i] = newArr;
|
|
|
|
if(i == this.cateList.length-1){
|
|
|
|
console.log(i,123)
|
|
|
|
this.getNodesInfo();
|
|
|
|
this.ifLoading = false;
|
|
|
|
}
|
2022-05-27 06:57:50 +00:00
|
|
|
}
|
2022-06-13 08:13:03 +00:00
|
|
|
})
|
|
|
|
}
|
2022-05-27 06:57:50 +00:00
|
|
|
},
|
2022-06-02 08:55:16 +00:00
|
|
|
|
2022-05-27 06:57:50 +00:00
|
|
|
// 查询左侧分类列表
|
|
|
|
checkShopCate(){
|
2022-05-27 11:59:47 +00:00
|
|
|
this.$requst.post('/api/spu/category',{hasChildren:1}).then(res=>{
|
2022-05-27 06:57:50 +00:00
|
|
|
if(res.code==0) {
|
|
|
|
this.cateList = res.data;
|
|
|
|
setTimeout(()=>{
|
|
|
|
// 获取元素宽
|
|
|
|
const query = wx.createSelectorQuery().in(this)
|
|
|
|
query.select('.cate-left-box').boundingClientRect((rect) => {
|
|
|
|
this.newWidth = this.newWidth - rect.width - 20;
|
|
|
|
}).exec()
|
|
|
|
},200)
|
2022-06-13 08:13:03 +00:00
|
|
|
this.checkShopList();
|
2022-05-27 06:57:50 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
2022-06-02 08:55:16 +00:00
|
|
|
|
2022-05-27 06:57:50 +00:00
|
|
|
scrollBottomEv(){
|
|
|
|
console.log('触底了');
|
2022-06-13 08:13:03 +00:00
|
|
|
// setTimeout(()=>{
|
|
|
|
// this.current =this.cateList.length - 1;
|
|
|
|
// },80)
|
2022-05-25 09:55:44 +00:00
|
|
|
},
|
2022-06-02 08:55:16 +00:00
|
|
|
|
2022-05-25 09:55:44 +00:00
|
|
|
// 一级分类选择
|
2022-05-27 06:57:50 +00:00
|
|
|
chooseCate(index,id) {
|
2022-06-13 08:13:03 +00:00
|
|
|
this.current =index
|
|
|
|
this.doms = 'product'+index
|
|
|
|
},
|
|
|
|
|
|
|
|
// 滚动
|
|
|
|
scrolls(e){
|
|
|
|
let scrollTop = e.target.scrollTop
|
|
|
|
for(let i =0;i<this.topList.length;i++){
|
|
|
|
let h1 = this.topList[i]
|
|
|
|
let h2 = this.topList[i+1]
|
|
|
|
if(scrollTop>=h1&&scrollTop<h2){
|
|
|
|
this.current = i
|
|
|
|
}
|
2022-05-27 11:59:47 +00:00
|
|
|
}
|
2022-05-25 09:55:44 +00:00
|
|
|
},
|
2022-06-02 08:55:16 +00:00
|
|
|
|
2022-06-13 08:13:03 +00:00
|
|
|
// 改变topList
|
|
|
|
getNodesInfo(){
|
|
|
|
setTimeout(()=>{
|
|
|
|
const query = uni.createSelectorQuery().in(this);
|
|
|
|
query.selectAll('.posir').boundingClientRect().exec((res)=>{
|
|
|
|
console.log(res,234)
|
|
|
|
let nodes = res[0]
|
|
|
|
let rel =[];
|
|
|
|
nodes.map(item=>{
|
|
|
|
rel.push(item.top)
|
|
|
|
})
|
|
|
|
this.topList = rel
|
|
|
|
})
|
|
|
|
},200)
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
// 跳转详情页
|
2022-05-25 09:55:44 +00:00
|
|
|
goDetail(id) {
|
|
|
|
uni.navigateTo({
|
2022-06-02 08:55:16 +00:00
|
|
|
url:'/pagesB/shop-detail/shop-detail?id='+id
|
2022-05-25 09:55:44 +00:00
|
|
|
})
|
|
|
|
},
|
2022-06-02 08:55:16 +00:00
|
|
|
|
2022-06-13 08:13:03 +00:00
|
|
|
// 加入购物车
|
2022-05-25 09:55:44 +00:00
|
|
|
addCartEv(id) {
|
2022-05-27 06:57:50 +00:00
|
|
|
this.$requst.post('/api/order/shopping-cart-add',{sku_id:id,num:1}).then(res=>{
|
|
|
|
if(res.code==0) {
|
2022-06-02 08:55:16 +00:00
|
|
|
this.$toolAll.tools.showToast('加入购物车成功(*^▽^*)');
|
2022-06-06 05:49:21 +00:00
|
|
|
getCartNum();
|
2022-05-27 06:57:50 +00:00
|
|
|
} else {
|
|
|
|
this.$toolAll.tools.showToast(res.msg)
|
|
|
|
}
|
|
|
|
})
|
2022-05-25 09:55:44 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
.cate-btn{background: linear-gradient(to right,#ff3772 0%,#fd5549 100%);width: 170rpx;height: 60rpx;box-shadow: 0rpx 6rpx 10rpx rgba(255, 55, 114, .3);}
|
2022-06-13 08:13:03 +00:00
|
|
|
.disac {flex-wrap: wrap;}
|
|
|
|
.cate-txt{
|
|
|
|
display: flex;
|
|
|
|
}
|
|
|
|
.cate-title{width: 100%;font-size: 24rpx;line-height: 1.5;padding-bottom: 30rpx;color: #666;}
|
2022-05-25 09:55:44 +00:00
|
|
|
</style>
|