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.

215 lines
4.2 KiB

2 years ago
<template>
<!-- 产品分类导航:style="list.length <= oneRowNum||scroll ? `height:160rpx` : `height:380rpx`" -->
<view class="wrap">
2 years ago
<view class="menu-category-box" style="height:160rpx">
2 years ago
<swiper
class="menu-swiper-box"
@change="onSwiper"
:autoplay="false"
:interval="3000"
:duration="1000"
>
<swiper-item class="menu-swiper-item" v-for="(itemList, index) in newList" :key="index">
<view class="menu-tab-box u-flex u-flex-wrap">
<view
2 years ago
:class="(index.toString()+i.toString())==activeIndex?'tab-list u-flex-col u-col-center u-row-center active':'tab-list u-flex-col u-col-center u-row-center'"
2 years ago
:style="{ width: 100 / 5 + '%' }"
2 years ago
v-for="(item, i) in itemList"
:key="i"
2 years ago
@tap="getjump(item,index,i)"
2 years ago
>
<image class="tab-img" :src="item.image"></image>
2 years ago
<text class="nametext">{{ item.name }}</text>
2 years ago
</view>
</view>
</swiper-item>
</swiper>
<!-- <view class="menu-category-dots" v-if="newList.length > 1">
<text :class="categoryCurrent === index ? 'category-dot-active' : 'category-dot'" v-for="(dot, index) in newList.length" :key="index"></text>
</view> -->
</view>
</view>
</template>
<script>
/**
* shGridSwiper-滑动宫格列表
* @property {Array} list - 列表数据
* @property {Number|String} oneRowNum - 单行数量
*/
export default {
components: {},
data() {
return {
categoryCurrent: 0 ,//分类轮播下标
2 years ago
activeIndex:'00'
2 years ago
};
},
props: {
list: {
type: Array,
default: () => {
return [];
}
},
oneRowNum: {
type: [Number, String],
default: 5
},
scroll:{
type: Boolean,
default: true
2 years ago
},
isIndex:{
type:Boolean,
default:true,
2 years ago
},
selectedItem:{
type:Object,
default:()=>{
return {}
}
2 years ago
}
},
computed: {
newList() {
if (this.list.length) {
2 years ago
// let data;
// if(this.scroll){
// data = this.$tools.splitData(this.list, this.oneRowNum * 1);
// }else{
// data = this.$tools.splitData(this.list, this.oneRowNum * 2);
// }
let data = this.$tools.splitData(this.list, this.oneRowNum * 1);
2 years ago
// let data = this.list
2 years ago
// console.log(data,"999999")
2 years ago
return data;
}
}
},
methods: {
// 轮播
onSwiper(e) {
this.categoryCurrent = e.detail.current;
},
jump(path, query) {
this.$Router.push({
path: path,
query: query
});
2 years ago
},
2 years ago
getjump(item,index,i){
console.log(item,index,i)
// if(i){
console.log(item,index)
this.activeIndex = (index.toString()+i.toString());
console.log(this.activeIndex)
// }
2 years ago
// if(this.isIndex){
// this.$tools.routerTo(val)
// }else{
2 years ago
this.$emit("catagory",item)
2 years ago
// }
2 years ago
}
2 years ago
},
watch:{
newList:{
deep:true,
handler:function(newV){
console.log(newV,"8888")
if(newV&&newV.length>0){
this.getjump(this.newList[0][0],'0','0')
}
}
},
selectedItem:{
deep:true,
handler:function(newV){
console.log(newV,"ld")
this.newList.forEach((item,index)=>{
if(item.include(newV)){
console.log(index)
}
})
}
}
},
mounted() {
this.activeIndex = '00'
// console.log(this.newList,"8888")
// this.getjump(this.newList[0][0],'0','0')
2 years ago
}
};
</script>
<style lang="scss">
// 产品分类
.menu-category-box,
.menu-swiper-box {
position: relative;
background: #fff;
2 years ago
height: 100%;
2 years ago
.menu-swiper-item {
background: #fff;
height: 100%;
width: 100%;
}
.menu-tab-box {
.tab-list {
2 years ago
font-size: 22rpx;
2 years ago
font-weight: 500;
color: rgba(51, 51, 51, 1);
margin: 20rpx 0;
2 years ago
2 years ago
.tab-img {
2 years ago
width: 82rpx;
height: 82rpx;
2 years ago
margin-bottom: 10rpx;
2 years ago
border-radius:20rpx;
2 years ago
}
}
}
.menu-category-dots {
display: flex;
position: absolute;
left: 50%;
transform: translateX(-50%);
bottom: 10rpx;
.category-dot {
width: 12rpx;
height: 12rpx;
background: #eeeeee;
border-radius: 50%;
margin-right: 10rpx;
}
.category-dot-active {
width: 12rpx;
height: 12rpx;
background: #17C161;
border-radius: 50%;
margin-right: 10rpx;
}
}
}
2 years ago
.active{
.nametext{
color:#ffffff;
background-color: #17C161;
padding: 4rpx 20rpx;
border-radius: 20px;
}
image{
border:2px solid #17C161;
}
}
2 years ago
</style>