FlowPacs/yudao-ui-app/pages/category/category.vue

188 lines
4.4 KiB
Vue
Raw Normal View History

2022-04-06 16:08:26 +08:00
<template>
<view class="container">
<view class="search-wrap">
<u-search placeholder="搜索" disabled height="32" :show-action="false" @click="handleSearchClick"></u-search>
</view>
<view class="category-box">
<view class="box-left">
<u-list @scrolltolower="scrolltolower">
<u-list-item class="category-item" v-for="(item, index) in categoryList" :key="item.id">
<view class="item-title" :class="{ active: currentIndex === index }" @click="handleCategoryClick(index)">
<text>{{ item.name }}</text>
</view>
</u-list-item>
</u-list>
</view>
<view class="box-right">
<view class="category-image">
<u--image :showLoading="true" :src="categoryList[currentIndex].image" width="530rpx" height="160rpx" @click="click"></u--image>
</view>
2022-04-17 14:43:07 +08:00
<view class="sub-category-box" v-for="(item, index) in categoryList[currentIndex].children" :key="item.id">
<view class="sub-category-header">
<view class="title">{{ item.title }}</view>
<view class="more">查看更多</view>
</view>
<u-grid class="sub-category-grid" col="3">
<u-grid-item v-for="(subItem, index) in item.category" :key="subItem.id">
<view class="sub-category-item">
<u-icon name="photo" :size="80"></u-icon>
<text class="sub-category-title">{{ subItem.title }}</text>
</view>
2022-04-17 14:43:07 +08:00
</u-grid-item>
</u-grid>
</view>
</view>
</view>
</view>
2022-04-06 16:08:26 +08:00
</template>
<script>
export default {
data() {
return {
currentIndex: 0,
2022-04-17 14:43:07 +08:00
categoryList: []
}
},
onLoad() {
for (let i = 0; i < 10; i++) {
this.categoryList.push({
id: i,
image: '',
name: '商品分类' + i,
children: [
{
id: 0,
title: '分类' + i + '-1',
category: [
{
id: 0,
image: '',
title: '分类' + i + '-1-1'
},
{
id: 2,
image: '',
title: '分类' + i + '-1-2'
},
{
id: 3,
image: '',
title: '分类' + i + '-1-3'
}
]
},
{
id: 1,
title: '分类' + i + '-2',
category: [
{
id: 0,
image: '',
title: '分类' + i + '-2-1'
},
{
id: 2,
image: '',
title: '分类' + i + '-2-2'
},
{
id: 3,
image: '',
title: '分类' + i + '-2-3'
}
]
}
]
})
}
},
methods: {
handleSearchClick(e) {
2022-04-17 14:43:07 +08:00
uni.$u.route('/pages/search/search')
},
handleCategoryClick(index) {
if (this.currentIndex !== index) {
this.currentIndex = index
}
}
}
}
2022-04-06 16:08:26 +08:00
</script>
<style lang="scss" scoped>
2022-04-17 14:43:07 +08:00
.container {
height: calc(100vh - 50px);
overflow: hidden;
}
.search-wrap {
background: $custom-bg-color;
padding: 20rpx;
}
.category-box {
display: flex;
.box-left {
width: 180rpx;
padding-top: 20rpx;
border-right: $custom-border-style;
.category-item {
border-bottom: $custom-border-style;
padding: 20rpx 0;
.item-title {
padding-left: 30rpx;
font-size: 30rpx;
&.active {
border-left: 6rpx solid $u-primary;
font-weight: 700;
}
}
}
}
.box-right {
2022-04-17 14:43:07 +08:00
width: 570rpx;
.category-image {
padding: 20rpx;
}
2022-04-17 14:43:07 +08:00
.sub-category-box {
.sub-category-header {
@include flex-space-between;
2022-04-17 14:43:07 +08:00
padding: 20rpx;
2022-04-17 14:43:07 +08:00
.title {
font-size: 28rpx;
font-weight: 700;
}
.more {
font-size: 22rpx;
color: #939393;
}
2022-04-17 14:43:07 +08:00
}
.sub-category-grid {
padding: 0 15rpx;
.sub-category-item {
@include flex-center(column);
background: #fff;
2022-04-17 14:43:07 +08:00
.sub-category-image {
border-radius: 10rpx;
/deep/ * {
border-radius: 10rpx;
}
}
2022-04-17 14:43:07 +08:00
.sub-category-title {
margin: 15rpx 0;
font-size: 24rpx;
}
}
}
}
}
}
2022-04-06 16:08:26 +08:00
</style>