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.
yanzong_qianduan/pages/category/index.vue

276 lines
6.2 KiB

11 months ago
<template>
<view class="category">
<view class="search" @click="goSearch">
<image src="../../static/home/search.png" mode="" class="searchIcon"></image>
<text class="searchInfo">iPone15</text>
</view>
<view class="main">
<view class="menu">
<scroll-view :scroll-top="scrollTop" scroll-y="true" class="scroll-Y" @scrolltoupper="upper"
@scrolltolower="lower" @scroll="scroll">
<view id="demo1" class="menuList" v-for="(item,index) in secondMenu" :key="index"
:style="{'color':secondChose==item.category_id?'#F22029':'#333'}" @click="choseSecondMenu(item)">{{item.name}}</view>
</scroll-view>
</view>
<view class="goods">
<view class="goodsTop">
<scroll-view class="suggest" scroll-x="true">
<view id="demo1" class="sugItem" v-for="(item,index) in menuList" :key="index" @click="choseFirstMenu(item)"
:style="{'border':isChose==item.category_id?'2rpx solid #F22029':none,'color':isChose==item.category_id?'#F22029':'#333'}">
{{item.name}}
</view>
</scroll-view>
</view>
<view class="goodsCenter">
<view class="hotType">
热门分类
</view>
<view class="goodsList">
<view class="listItem" v-for="(item,index) in hotList" :key="index">
<image src="/static/home/goodsDemo.png" mode="" class="goodsImg"></image>
<view class="goodsName">
TCL
</view>
</view>
</view>
</view>
<view class="goodsCenter">
<view class="hotType">
11 months ago
{{typeName}}
</view>
<view class="goodsList">
<view class="listItem" v-for="(item,index) in goodsList" :key="index"
@click="goodsDetail(item)">
11 months ago
<image :src="item.goods_image" mode="" class="goodsImg"></image>
<view class="goodsName">
11 months ago
{{item.goods_name}}
</view>
</view>
</view>
</view>
</view>
</view>
</view>
11 months ago
</template>
<script>
11 months ago
import * as cstegory from '@/api/category'
export default {
data() {
return {
secondChose:'',
menuList: [],
typeName: '空调',
goodsList: [],
isChose: '',
hotList: [],
secondMenu: [],
}
},
onShow() {
11 months ago
this.getGoodsTypeList();
// this.getSonList()
11 months ago
},
methods: {
choseFirstMenu(item){
this.isChose = item.category_id;
this.secondMenu = item.children;
this.secondChose=''
// this.secondChose = this.secondMenu[0].category_id;
this.getSonList(this.isChose)
},
choseSecondMenu(item){
this.secondChose = item.category_id;
this.getSonList(this.secondChose)
},
getGoodsTypeList() {
11 months ago
const that = this;
console.log(cstegory.list(), '接口地址')
11 months ago
return new Promise((resolve, reject) => {
cstegory.list({
is_hot: 0
})
11 months ago
.then(res => {
// 合并新数据
console.log(res, '分类数据')
that.menuList = res.data.list;
that.isChose = that.menuList[0].category_id;
that.secondMenu = that.menuList[0].children;
that.secondChose = that.secondMenu[0].category_id
that.getSonList(that.secondChose)
// that.hotList = that.menuList[0].
11 months ago
})
.catch(reject)
})
},
goSearch() {
uni.navigateTo({
url: '/pages/search/index'
})
},
getSonList(val) {
11 months ago
const that = this;
let params = {
categoryId: val,
page: 1
11 months ago
}
return new Promise((resolve, reject) => {
cstegory.sonList(params)
11 months ago
.then(res => {
// 合并新数据
console.log(res, '子数据')
11 months ago
this.goodsList = res.data.list.data
})
.catch(reject)
})
},
goodsDetail(item) {
11 months ago
// 跳转商品详情
uni.navigateTo({
url: '/pages/goods/detail?goodsId=' + item.goods_id
11 months ago
})
},
}
}
11 months ago
</script>
<style lang="scss" scoped>
.category {
width: 100%;
height: 100%;
background: #F5F5F5;
border-radius: 0rpx 0rpx 0rpx 0rpx;
opacity: 1;
.search {
width: 678rpx;
height: 64rpx;
background: #FFFFFF;
border-radius: 68rpx 68rpx 68rpx 68rpx;
opacity: 1;
margin: 32rpx 0 0 34rpx;
.searchIcon {
width: 28rpx;
height: 28rpx;
border-radius: 0rpx 0rpx 0rpx 0rpx;
opacity: 1;
margin: 18rpx 0 0 26rpx;
}
.searchInfo {
height: 64rpx;
font-size: 28rpx;
font-family: PingFang SC, PingFang SC;
font-weight: 400;
color: #8D8D8D;
line-height: 64rpx;
margin-left: 22rpx;
}
}
.main {
display: flex;
margin-top: 28rpx;
.menu {
width: 172rpx;
height: 100%;
padding-top: 90rpx;
.scroll-Y {
height: 100%;
}
.menuList {
margin-bottom: 54rpx;
text-align: center;
width: 172rpx;
height: 40rpx;
font-size: 28rpx;
font-family: PingFang SC, PingFang SC;
font-weight: 400;
color: #434343;
line-height: 40rpx;
}
}
.goods {
.goodsTop {
width: 500rpx;
.suggest {
width: 100%;
white-space: nowrap;
.sugItem {
display: inline-block;
width: 146rpx;
height: 54rpx;
background: #FEF6F6;
border-radius: 82rpx 82rpx 82rpx 82rpx;
opacity: 1;
// border: 2rpx solid #F22029;
line-height: 54rpx;
margin-right: 34rpx;
text-align: center;
}
}
}
.goodsCenter {
width: 566rpx;
11 months ago
min-height: 700rpx;
background: #FFFFFF;
border-radius: 12rpx 12rpx 12rpx 12rpx;
opacity: 1;
margin-top: 22rpx;
padding-top: 30rpx;
.hotType {
width: 112rpx;
height: 40rpx;
font-size: 28rpx;
font-family: PingFang SC, PingFang SC;
font-weight: 500;
color: #434343;
line-height: 40rpx;
margin: 0rpx 0 0 34rpx;
}
.goodsList {
width: 544rpx;
margin: 26rpx 0 0 8rpx;
display: flex;
flex-wrap: wrap;
}
.listItem {
width: 180rpx;
11 months ago
height: 200rpx;
margin-bottom: 34rpx;
.goodsImg {
11 months ago
width: 154rpx;
height: 154rpx;
}
.goodsName {
width: 180rpx;
height: 40rpx;
font-size: 28rpx;
font-family: PingFang SC, PingFang SC;
font-weight: 500;
color: #434343;
line-height: 40rpx;
text-align: center;
11 months ago
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
}
}
}
}
}
11 months ago
</style>