chore: 纳入小程序完整源码

Co-authored-by: Cursor <cursoragent@cursor.com>
这个提交包含在:
可乐加冰
2026-09-23 20:25:01 +08:00
父节点 7f8c4966aa
当前提交 9d2488a631
共有 338 个文件被更改,包括 72261 次插入 和 0 次删除

查看文件

@@ -0,0 +1,304 @@
<template>
<view class="content_box">
<view class="u-flex u-col-center wrapper-box">
<view class="scroll-box" style="background-color: #F6F6F6;">
<scroll-view class="left u-flex-col u-col-center" enable-flex enable-back-to-top scroll-y>
<view class="type-list u-ellipsis-1" :class="[{ 'list-active': listId == index }]"
v-for="(item, index) in categoryData" :key="index" @tap="onType(index)">
<view class="line" :class="[{ 'line-active': listId == index }]"></view>
{{ item.name }}
</view>
<view class="hack-tabbar"></view>
</scroll-view>
</view>
<view style="height: 100%;width: 100%;">
<scroll-view @scrolltolower="loadMore" scroll-y class="scroll-box" enable-back-to-top
scroll-with-animation>
<view class="right" v-if="categoryData.length">
<image class="type-img" v-if="categoryData[listId].image" :src="categoryData[listId].image"
mode="aspectFill"></image>
<view class="item-list">
<view class="item-box u-flex">
<view class="u-flex-col u-col-center goods-item"
@tap="jump('/pages/goods/detail', { id: goods.id })"
v-for="(goods, index1) in goodsList" :key="goods.id">
<image class="item-img" lazy-load :src="goods.image" mode="aspectFill"></image>
<text class="item-title u-ellipsis-1 ">{{ goods.title }}</text>
<view class="item-price">{{ goods.price }}</view>
</view>
</view>
</view>
<!-- 缺省页 -->
<shopro-empty v-if="isEmpty" marginTop="200rpx"
:image="$IMG_URL + '/imgs/empty/empty_goods.png'"
tipText="暂无该商品,还有更多好货等着你噢~"></shopro-empty>
<!-- 加载更多 -->
<u-loadmore v-if="!isEmpty" height="80rpx" :status="loadStatus" icon-type="flower"
color="#ccc" />
<view class="hack-tabbar"></view>
</view>
</scroll-view>
</view>
</view>
</view>
</template>
<script>
import {
mapMutations,
mapActions,
mapState,
mapGetters
} from 'vuex';
export default {
components: {},
data() {
return {
listId: 0,
categoryData: {},
categoryID: 0, //分类id
isEmpty: false,
currentPage: 1,
lastPage: 1,
loadStatus: 'loadmore', //loadmore-加载前的状态,loading-加载中的状态,nomore-没有更多的状态
goodsList: [] //商品数据
};
},
props: {
categoryStyleId: {
// 分类样式ID
type: Number,
default: 0
},
oldCategoryType: {
type: Number,
default: 0
},
categoryIndex: {
type: Number,
default: -1
}
},
computed: {},
created() {
this.getCategory();
},
methods: {
// 获取分类
getCategory() {
this.$http('category.detail', {
id: this.categoryStyleId
}).then(res => {
if (res.code === 1) {
this.categoryData = res.data.children;
this.categoryID = res.data.children[0].id;
this.listId = this.categoryIndex < 0 ? 0 : this.categoryIndex;
// 如果oldCategoryType = 3并且分类下没有子分类则显示商品
if (this.oldCategoryType == 3 && !this.categoryData[this.listId].children.length) {
this.categoryID = this.categoryData[this.listId].id;
this.handleCategoryChange(2, this.listId);
}
this.getGoodsList();
}
});
},
// 分类类型切换
handleCategoryChange(categoryType, categoryIndex = -1) {
this.$emit('categoryChange', {
type: categoryType,
index: categoryIndex
});
},
// 获取分类商品
getGoodsList() {
let that = this;
that.$http('goods.lists', {
category_id: that.categoryID,
page: that.currentPage
}, '加载中...').then(res => {
if (res.code === 1) {
that.goodsList = [...that.goodsList, ...res.data.data];
that.isEmpty = !that.goodsList.length;
that.lastPage = res.data.last_page;
that.loadStatus = that.currentPage < res.data.last_page ? 'loadmore' : 'nomore';
}
});
},
// 商品底部
loadMore() {
if (this.currentPage < this.lastPage) {
this.currentPage += 1;
this.getGoodsList();
}
},
onType(index) {
this.listId = index;
this.categoryID = this.categoryData[index].id;
this.goodsList = [];
this.currentPage = 1;
// 如果oldCategoryType = 3并且点击的分类下有子分类则切换到二级分类
if (this.oldCategoryType == 3 && this.categoryData[index].children.length) {
this.handleCategoryChange(3, index);
return false;
}
this.getGoodsList();
},
// 路由跳转
jump(path, parmas) {
this.$Router.push({
path: path,
query: parmas
});
}
}
};
</script>
<style lang="scss">
.hack-tabbar {
height: calc(100rpx + env(safe-area-inset-bottom) / 2);
width: 100%;
}
.content_box {
margin-top: 1upx;
display: flex;
flex-direction: column;
overflow: hidden;
height: 100%;
}
.wrapper-box {
flex: 1;
margin-top: 1upx;
height: 100%;
}
.scroll-box {
height: 100%;
flex: 1;
background: #fff;
}
.left {
width: 200upx;
height: 100%;
flex: 1;
.list-active {
background: #fff;
color: #333333 !important;
font-weight: bold !important;
}
.line-active {
background: #4C7AF3;
}
.type-list {
height: 110upx;
position: relative;
width: 200rpx;
padding-left: 16rpx;
line-height: 110rpx;
font-size: 28upx;
font-weight: 400;
color: rgba(102, 102, 102, 1);
.line {
width: 10upx;
height: 40rpx;
position: absolute;
left: 0;
border-radius: 5rpx;
top:35rpx;
}
}
}
.right {
padding: 0 30upx;
flex: 1;
height: 100%;
.type-img {
width: 505rpx;
height: 150rpx;
background: #ccc;
margin: 20rpx 0;
border-radius: 10rpx;
}
.item-list {
.type-box {
height: 84rpx;
.type-title {
font-size: 28rpx;
font-weight: bold;
}
.more {
font-size: 26rpx;
color: #999;
}
}
.item-box {
flex-wrap: wrap;
width: 504rpx;
.goods-item {
margin-right: 12rpx;
margin-bottom: 12rpx;
background: #ffffff;
box-shadow: 0px 0px 20rpx 4rpx rgba(199, 199, 199, 0.22);
border-radius: 10rpx;
&:nth-child(2n) {
margin-right: 0;
}
.item-img {
width: 245rpx;
height: 246rpx;
border-radius: 10rpx 10rpx 0px 0px;
background: #f5f5f5;
}
.item-title {
font-size: 24rpx;
line-height: 24rpx;
margin-top: 10rpx;
width: 200rpx;
text-align: left;
margin: 20rpx;
}
.item-price {
font-size: 28rpx;
font-weight: 500;
color: #ff3000;
text-align: left;
width: 200rpx;
margin: 0 20rpx 20rpx;
&::before {
content: '¥';
font-size: 22rpx;
}
}
}
}
}
}
</style>

查看文件

@@ -0,0 +1,646 @@
<template>
<view class="catgory-wrap">
<view class="u-flex wrapper-box">
<!-- 左侧分类列表 -->
<scroll-view enable-flex scroll-y scroll-with-animation class="u-tab-view menu-scroll-view"
:scroll-top="scrollLeftTop">
<view v-for="(item, index) in tabbarList" :key="index" class="u-tab-item u-ellipsis-1"
:class="[currentTab == index ? 'u-tab-item-active' : '']" :data-current="index"
@tap.stop="swichMenu(index)">
<text class="menu-name">{{ item.name }}</text>
</view>
<view class="hack-tabbar"></view>
</scroll-view>
<!-- 右侧商品列表 -->
<view class="right-wrap ">
<scroll-view scroll-y class="right-box menu-scroll-view" @scrolltolower="loadMore"
v-if="tabbarList.length">
<view class="u-flex u-row-center" v-if="tabbarList[currentTab].image">
<image class="category-img" :src="tabbarList[currentTab].image" mode="aspectFill"></image>
</view>
<view class="category-title">{{ tabbarList[currentTab].name }}</view>
<view class="sh-big-card-wrap u-m-20 " v-for="(item, index) in goodsList" :key="item.id">
<view class="big-goods-card" @tap="jump('/pages/goods/detail', { id: item.id })">
<view class="img-wrap u-m-b-20">
<image class="goods-img" :src="item.image" mode="aspectFill"></image>
<image class="goods-tag" v-if="item.is_hot && !item.activity"
:src="$IMG_URL + '/goods/goods_hot_tag.png'" mode=""></image>
</view>
<view class="goods-title u-p-x-20 u-m-b-10 u-ellipsis-2">
<view v-if="item.activity_type" class=" sm cu-tag radius title-tag u-m-r-10"
:style="{ backgroundColor: typeMap[item.activity_type].tagBg, color: '#fff' }">
{{ typeMap[item.activity_type].text }}
</view>
{{ item.title }}
</view>
<view class="goods-subtitle u-p-x-20 u-m-b-10 u-ellipsis-1">{{ item.subtitle }}</view>
<!-- 满减,满折 -->
<view class="u-p-x-20" v-if="item.activity_discounts_tags.length">
<view class="tag-box u-m-b-10 u-m-r-10"
v-for="(tag, index1) in item.activity_discounts_tags" :key="index1">{{ tag }}</view>
</view>
<view class="goods-progress u-p-x-20 u-flex u-m-b-10">
<view style="width:230rpx;">
<u-line-progress height="16" :show-percent="false" :percent="Number(item.percent)"
active-color="#4C7AF3"></u-line-progress>
</view>
<view class="googs-send-num u-m-l-20">已售{{ item.sales }}件</view>
</view>
<view class="u-flex u-row-between u-p-x-20">
<view class="price-box u-flex font-OPPOSANS">
<view class="price neutra-font">{{ item.price }}</view>
<view class="origin-price u-m-l-10 neutra-font">¥{{ item.original_price }}</view>
</view>
<view class="cart-box">
<!-- 单规格 -->
<view class="" v-if="!item.activity">
<view v-if="!item.is_sku">
<button v-if="!isCart(item.id)"
:style="item.activity_type ? typeMap[item.activity_type].btnBg : ''"
@tap.stop="addCart(item.sku_price[0])" class="u-reset-button cart-btn">
加入购物车
</button>
<view class="num-step" @tap.stop v-else>
<u-number-box :value="checkCart[item.id].num" :long-press="false"
:min="0" :max="maxStep" :step="1" :index="index"
@min="onMin(item.id)" @plus="plus($event, item.sku_price[0])"
@change="onChangeNum($event, item.sku_price[0])"></u-number-box>
</view>
</view>
<!-- 多规格 -->
<button class="u-reset-button item-btn sel-sku "
:style="item.activity_type ? typeMap[item.activity_type].btnBg : ''"
@tap.stop="selSku(item)" v-else>
选规格
</button>
</view>
<button class="u-reset-button item-btn sel-sku"
:style="item.activity_type ? typeMap[item.activity_type].btnBg : ''"
v-else>立即抢购</button>
</view>
</view>
</view>
</view>
<!-- 缺省页 -->
<shopro-empty v-if="isEmpty" marginTop="200rpx" :image="$IMG_URL + '/imgs/empty/empty_goods.png'"
tipText="暂无该商品,还有更多好货等着你噢~"></shopro-empty>
<!-- 加载更多 -->
<u-loadmore v-if="goodsList.length" height="80rpx" :status="loadStatus" icon-type="flower"
color="#ccc" />
<view class="hack-tabbar"></view>
</scroll-view>
</view>
</view>
<!-- 规格弹窗 -->
<shopro-sku v-if="showSku && goodsInfo.id" v-model="showSku" :goodsInfo="goodsInfo" :buyType="'cart'">
</shopro-sku>
</view>
</template>
<script>
import {
mapMutations,
mapActions,
mapState,
mapGetters
} from 'vuex';
export default {
components: {},
data() {
return {
showSku: false, //是否显示规格弹窗
isEmpty: false,
currentTab: 0,
categoryID: 0, //分类id
scrollLeftTop: 0, //左边滚动距离
menuHeight: 0, // 左边菜单的高度
menuItemHeight: 0, // 左边菜单item的高度
tabbarList: [], //左侧分类列表
goodsList: [], //商品列表
goodsInfo: {}, //点击商品详情
numberDisabled: false, //购物车计数器
loadStatus: 'loadmore', //loadmore-加载前的状态,loading-加载中的状态,nomore-没有更多的状态
currentPage: 1,
lastPage: 1,
maxStep: 999,
typeMap: {
seckill: {
text: '秒杀',
tagBg: '#FF5854',
goodsBg: '/imgs/tag/seckill_x_bg.png',
btnText: '去抢购',
btnBg: 'background: linear-gradient(90deg, #D01325, #ED3C30);'
},
robbuy: {
text: '预约抢购',
tagBg: '#FF5854',
goodsBg: '/imgs/tag/seckill_x_bg.png',
btnText: '去抢购',
btnBg: 'background: linear-gradient(90deg, #D01325, #ED3C30);'
},
groupon: {
text: '拼团',
tagBg: '#FE832A',
goodsBg: '/imgs/tag/groupon_x_bg.png',
btnText: '马上拼',
btnBg: 'background: linear-gradient(90deg, #FF6600 0%, #FE832A 100%);'
}
}
};
},
props: {
categoryStyleId: {
type: Number,
default: 0
},
oldCategoryType: {
type: Number,
default: 0
},
categoryIndex: {
type: Number,
default: -1
}
},
computed: {
...mapGetters(['totalCount', 'isSel', 'cartNum', 'cartList', 'isLogin']),
// 购物车检测
checkCart() {
let obj = {};
this.cartList.forEach(item => {
obj[item.goods_id] = {
num: item.goods_num,
cartOrderId: item.id
};
});
return obj;
}
},
async created() {
await this.getCategory();
let res = await this.getGoodsList();
},
methods: {
...mapActions(['getCartList', 'changeCartList', 'addCartGoods']),
// 跳转详情
toGoodDetail(id) {
this.$Router.push({
path: '/pages/goods/detail',
query: {
id: id
}
});
},
// 百分比
getProgress(sales, stock) {
let unit = '';
if (stock + sales > 0) {
let num = (sales / (sales + stock)) * 100;
unit = num.toFixed(2) + '%';
} else {
unit = '0%';
}
return unit;
},
// 加载更多
loadMore() {
if (this.currentPage < this.lastPage) {
this.currentPage += 1;
this.getGoodsList();
}
},
// 获取分类
async getCategory() {
const tabbarData = await this.$http('category.detail', {
id: this.categoryStyleId
});
this.tabbarList = tabbarData.data.children;
this.currentTab = this.categoryIndex >= 0 ? this.categoryIndex : 0;
this.categoryID = this.tabbarList[this.currentTab]?.id;
},
// 获取分类商品
getGoodsList() {
let that = this;
that.loadStatus = 'loading';
that.$http(
'goods.lists', {
category_id: that.categoryID,
page: that.currentPage
},
'加载中...'
)
.then(res => {
if (res.code === 1) {
that.goodsList = [...that.goodsList, ...res.data.data];
that.goodsList.map(item => {
item.percent = item.stock + item.sales > 0 ? ((item.sales / (item.sales + item
.stock)) * 100).toFixed(2) : 0;
});
that.isEmpty = !that.goodsList.length;
that.lastPage = res.data.last_page;
that.loadStatus = that.currentPage < res.data.last_page ? 'loadmore' : 'nomore';
}
})
.then(() => {
that.isLogin && that.getCartList();
});
},
// 点击左边的栏目切换
async swichMenu(index) {
if (index == this.currentTab) return;
this.currentTab = index;
this.categoryID = this.tabbarList[index].id;
this.currentPage = 1;
this.lastPage = 1;
this.goodsList = [];
// 如果oldCategoryType = 3并且点击的分类下有子分类则切换到二级分类
if (this.oldCategoryType == 3 && this.tabbarList[index].children.length) {
this.handleCategoryChange(3, index);
return false;
}
await this.getGoodsList();
// 如果为0,意味着尚未初始化
if (this.menuHeight == 0 || this.menuItemHeight == 0) {
await this.getElRect('menu-scroll-view', 'menuHeight');
await this.getElRect('u-tab-item', 'menuItemHeight');
}
// 将菜单菜单活动item垂直居中
this.scrollTop = index * this.menuItemHeight + this.menuItemHeight / 2 - this.menuHeight / 2;
},
// 分类类型切换
handleCategoryChange(categoryType, categoryIndex = -1) {
this.$emit('categoryChange', {
type: categoryType,
index: categoryIndex
});
},
// 获取一个目标元素的高度
getElRect(elClass, dataVal) {
new Promise((resolve, reject) => {
const query = uni.createSelectorQuery().in(this);
query
.select('.' + elClass)
.fields({
size: true
}, res => {
// 如果节点尚未生成,res值为null,循环调用执行
if (!res) {
setTimeout(() => {
this.getElRect(elClass);
}, 10);
return;
}
this[dataVal] = res.height;
})
.exec();
});
},
// 加入购物车
addCart(goods) {
let obj = {
goods_id: goods.goods_id,
goods_num: 1,
sku_price_id: goods.id,
goods_price: goods.price
};
let confirmGoodsList = {
list: [obj],
from: 'goods'
};
this.addCartGoods(confirmGoodsList).then(res => {
if (res.code === 1) {
this.$u.toast(res.msg);
}
});
},
// 检测商品在购物车中的下标
checkGoodsIndex(id) {
let cIndex = 0;
this.cartList.forEach((item, index) => {
if (id == item.goods_id) {
cIndex = index;
}
});
return cIndex;
},
// 到达最小值
onMin(goodsId) {
const that = this;
let cartGoodId = 0;
cartGoodId = this.cartList.filter(item => item.goods_id === goodsId)[0].id;
uni.showModal({
title: '删除提示',
confirmColor: '#f0c785',
content: `是否确认从购物车中删除此商品?`,
success: res => {
res.confirm && this.changeCartList({
ids: [cartGoodId],
art: 'delete'
});
}
});
},
// 增加
plus(e, sku) {
if (e.value >= sku.stock) {
this.maxStep = sku.stock > 999 ? 999 : sku.stock;
this.$u.toast('库存不足');
return;
}
if (this.detail.activity_type === 'seckill' || this.detail.activity_type === 'groupon') {
let rules = this.detail.activity.rules;
if (rules.limit_buy != 0 && e.value >= rules.limit_buy) {
this.maxStep = rules.limit_buy;
this.$u.toast('本次活动最多购买' + rules.limit_buy + '件');
return;
}
}
},
// 更改商品数
// 更改商品数
async onChangeNum(e, sku) {
let gIndex = this.checkGoodsIndex(sku.goods_id);
if (e.value != this.checkCart[sku.goods_id].num) {
uni.showLoading({
mask: true
});
this.$set(this.cartList[gIndex], 'goods_num', +e.value);
await this.changeCartList({
ids: [this.checkCart[sku.goods_id].cartOrderId],
goodsNum: +e.value,
art: 'change'
});
await uni.hideLoading();
}
},
// 检测是否为购物车商品
isCart(id) {
let goodsId = id + '';
return Object.keys(this.checkCart).includes(goodsId);
},
// 添加购物车
async selSku(info) {
this.goodsInfo = {};
this.getGoodsDetail(info.id);
this.showSku = true;
},
// 商品详情
getGoodsDetail(id) {
let that = this;
that.$http('goods.detail', {
id: id
}).then(res => {
if (res.code === 1) {
that.goodsInfo = res.data;
}
});
},
// 路由跳转
jump(path, parmas) {
this.$Router.push({
path: path,
query: parmas
});
}
}
};
</script>
<style lang="scss" scoped>
.hack-tabbar {
height: calc(100rpx + env(safe-area-inset-bottom) / 2);
width: 100%;
}
// 最外层结构包裹
.catgory-wrap {
height: calc(100vh);
/* #ifdef H5 */
height: calc(100vh - var(--window-top));
/* #endif */
display: flex;
flex-direction: column;
}
.wrapper-box {
flex: 1;
display: flex;
overflow: hidden;
// 左侧menu
.u-tab-view {
width: 200rpx;
height: 100%;
.u-tab-item {
height: 84rpx;
background: #f6f6f6;
width: 200rpx;
padding-left: 16rpx;
font-size: 26rpx;
color: #444;
font-weight: 400;
line-height: 84rpx;
}
.u-tab-item-active {
position: relative;
color: #000;
font-size: 30rpx;
font-weight: bold;
background: #fff;
}
.u-tab-item-active::before {
content: '';
position: absolute;
border-left: 4px solid #4C7AF3;
height: 32rpx;
left: 0;
top: 26rpx;
}
}
}
// 右侧商品滚动
.right-wrap {
background-color: #fff;
height: 100%;
width: 100%;
.category-img {
width: 505rpx;
height: 150rpx;
background: #ccc;
margin: 20rpx auto;
border-radius: 10rpx;
}
.category-title {
font-size: 30rpx;
font-weight: bold;
color: #000;
margin: 20rpx;
}
.right-box {
height: 100%;
}
}
.big-goods-card {
background-color: #fff;
border-radius: 20rpx;
width: 100%;
box-shadow: 0 0 8rpx 2rpx rgba(199, 199, 199, 0.3);
padding-bottom: 20rpx;
.img-wrap {
position: relative;
overflow: hidden;
height: 256rpx;
width: 100%;
.goods-img {
width: 100%;
height: 256rpx;
border-radius: 20rpx 20rpx 0 0;
background: #f5f5f5;
}
.goods-tag {
position: absolute;
top: 16rpx;
left: 16rpx;
width: 88rpx;
height: 88rpx;
}
}
.goods-title {
font-size: 30rpx;
font-weight: bold;
color: #333333;
line-height: 36rpx;
padding-top: 6rpx;
.title-tag {
transform: scale(0.9);
position: relative;
top: -6rpx;
}
}
.goods-subtitle {
font-size: 24rpx;
font-weight: 400;
color: #999999;
line-height: 36rpx;
width: 480rpx;
}
.tag-box {
border: 1rpx solid #ff0000;
display: inline-block;
font-size: 20rpx;
line-height: 30rpx;
padding: 0 10rpx;
color: #ff0000;
border-radius: 8rpx;
}
.goods-progress {
.cu-progress {
width: 200rpx;
height: 20rpx;
background: rgba(#ff6361, 0.2);
overflow: visible;
position: relative;
.progress--ing {
background: #ff6361;
border-radius: 20rpx;
}
.round-tag {
position: absolute;
bottom: 0;
width: 20rpx;
height: 28rpx;
margin-left: -10rpx;
.round-tag-img {
width: 20rpx;
height: 28rpx;
}
}
}
.googs-send-num {
font-size: 24rpx;
font-weight: 400;
color: #bebebe;
}
}
.price-box {
vertical-align: text-bottom;
.price {
font-size: 42rpx;
color: #ff0000;
font-weight: 600;
&::before {
content: '¥';
font-size: 28rpx;
}
vertical-align: text-bottom;
}
.origin-price {
vertical-align: text-bottom;
font-size: 26rpx;
font-weight: 400;
text-decoration: line-through;
color: #c4c4c4;
}
}
.cart-box {
.cart-btn,
.sel-sku {
width: 172rpx;
line-height: 58rpx;
background: linear-gradient(90deg, rgba(233, 180, 97, 1), rgba(238, 204, 137, 1));
box-shadow: 0px 7rpx 6rpx 0px rgba(229, 138, 0, 0.22);
border-radius: 30rpx;
padding: 0;
font-size: 26rpx;
font-weight: 500;
color: #ffffff;
}
}
}
</style>

查看文件

@@ -0,0 +1,209 @@
<template>
<view class="content_box">
<view class="u-flex u-col-center wrapper-box">
<view class="scroll-box" style="background-color: #F6F6F6;">
<scroll-view class="left u-flex-col u-col-center" enable-flex enable-back-to-top scroll-y>
<view class="type-list u-ellipsis-1" :class="[{ 'list-active': listId == index }]" v-for="(item, index) in categoryData" :key="index" @tap="onType(index)">
<view class="line" :class="[{ 'line-active': listId == index }]"></view>
{{ item.name }}
</view>
<view class="hack-tabbar"></view>
</scroll-view>
</view>
<view style="height: 100%;width: 100%;">
<scroll-view scroll-y class="scroll-box" enable-flex enable-back-to-top scroll-with-animation>
<view class="right" v-if="categoryData.length">
<image class="type-img" v-if="categoryData[listId].image" :src="categoryData[listId].image" mode="aspectFill"></image>
<view class="item-list" v-for="(list, index1) in categoryData[listId].children" :key="index1">
<view class="type-box u-flex u-row-between u-col-center">
<text class="type-title">{{ list.name }}</text>
<view class="more u-flex u-col-center" @tap="jump('/pages/goods/list', { id: list.id })">
<text>查看更多</text>
<view class="u-iconfont uicon-arrow-right" style="color: #999;font-size: 28rpx;"></view>
</view>
</view>
<view class="item-box u-flex">
<view class="u-flex-col goods-item" @tap="jump('/pages/goods/list', { id: mlist.id })" v-for="(mlist, index2) in list.children" :key="index2">
<image class="item-img" lazy-load :src="mlist.image" mode="aspectFill"></image>
<view class="item-title u-ellipsis-1 ">{{ mlist.name }}</view>
</view>
</view>
</view>
<!-- 缺省页 -->
<shopro-empty
v-show="!categoryData[listId].children.length"
:image="$IMG_URL + '/imgs/empty/empty_goods.png'"
tipText="暂无该商品,还有更多好货等着你噢~"
></shopro-empty>
<view class="hack-tabbar"></view>
</view>
</scroll-view>
</view>
</view>
</view>
</template>
<script>
import { mapMutations, mapActions, mapState, mapGetters } from 'vuex';
export default {
components: {},
data() {
return {
listId: 0,
categoryData: {}
};
},
computed: {},
props: {
categoryStyleId: {
type: Number,
default: 0
}
},
async created() {
console.log('%c当前分类:三级分类', 'color:green;background:yellow');
await this.getCategory();
},
methods: {
getCategory() {
this.$http('category.detail', {
id: this.categoryStyleId
}).then(res => {
if (res.code === 1) {
this.categoryData = res.data.children;
}
});
},
onType(id) {
this.listId = id;
},
// 路由跳转
jump(path, parmas) {
this.$Router.push({
path: path,
query: parmas
});
}
}
};
</script>
<style lang="scss">
.hack-tabbar {
height: calc(100rpx + env(safe-area-inset-bottom) / 2);
width: 100%;
}
.content_box {
margin-top: 1upx;
display: flex;
flex-direction: column;
overflow: hidden;
height: 100%;
}
.wrapper-box {
flex: 1;
margin-top: 1upx;
height: 100%;
}
.scroll-box {
height: 100%;
flex: 1;
background: #fff;
}
.left {
width: 200upx;
height: 100%;
flex: 1;
.list-active {
background: #fff;
color: #333333 !important;
font-weight: bold !important;
}
.line-active {
background: #4C7AF3;
}
.type-list {
height: 84upx;
position: relative;
width: 200rpx;
padding-left: 16rpx;
line-height: 84rpx;
font-size: 28upx;
font-weight: 400;
color: rgba(102, 102, 102, 1);
.line {
width: 10upx;
height: 100%;
position: absolute;
left: 0;
}
}
}
.right {
padding: 0 30upx;
flex: 1;
height: 100%;
.type-img {
width: 505rpx;
height: 150rpx;
background: #ccc;
border-radius: 10rpx;
margin-top: 30rpx;
}
.item-list {
.type-box {
height: 84rpx;
.type-title {
font-size: 28rpx;
font-weight: bold;
}
.more {
font-size: 26rpx;
color: #999;
}
}
.item-box {
flex-wrap: wrap;
.goods-item {
margin-right: 20rpx;
margin-bottom: 20rpx;
&:nth-child(3n) {
margin-right: 0;
}
.item-img {
width: 150rpx;
height: 150rpx;
background: #f5f5f5;
border-radius: 6rpx;
}
.item-title {
font-size: 24rpx;
line-height: 24rpx;
margin-top: 10rpx;
width: 150rpx;
text-align: center;
}
}
}
}
}
</style>

查看文件

@@ -0,0 +1,239 @@
<template>
<view class="content_box">
<view class="u-flex u-col-center wrapper-box">
<view class="scroll-box" style="background-color: #F6F6F6;">
<scroll-view class="left u-flex-col u-col-center" enable-flex enable-back-to-top scroll-y>
<view class="type-list u-flex u-col-center" :class="[{ 'list-active': listId == index }]"
v-for="(item, index) in categoryData" :key="index" @tap="onType(index)">
<view class="u-ellipsis-1 list-item" :class="[{ 'line-active': listId == index }]">
{{ item.name }}
</view>
</view>
<view class="hack-tabbar"></view>
</scroll-view>
</view>
<view style="height: 100%;width: 100%;">
<scroll-view scroll-y class="scroll-box" enable-back-to-top scroll-with-animation>
<view class="right" v-if="categoryData.length">
<image class="type-img" v-if="categoryData[listId].image" :src="categoryData[listId].image"
lazy-load mode="aspectFill"></image>
<view class="type-box u-flex u-col-center u-row-center">
<view class="u-iconfont uicon-minus" style="color: #d3d3d3;font-size: 28rpx;"></view>
<text class="type-title">{{ categoryData[listId].name }}</text>
<view class="u-iconfont uicon-minus" style="color: #d3d3d3;font-size: 28rpx;"></view>
</view>
<view class="item-list">
<view class="item-box u-flex">
<view class="u-flex-col u-col-center goods-item"
@tap="jump('/pages/goods/list', { id: list.id })"
v-for="(list, index1) in categoryData[listId].children" :key="index1">
<image class="item-img" lazy-load :src="list.image" mode="aspectFill"></image>
<view class="item-title u-ellipsis-1 ">{{ list.name }}</view>
</view>
</view>
<!-- 缺省页 -->
<shopro-empty v-show="!categoryData[listId].children.length"
:image="$IMG_URL + '/imgs/empty/empty_goods.png'" marginTop="200rpx"
tipText="暂无该商品,还有更多好货等着你噢~"></shopro-empty>
<view class="hack-tabbar"></view>
</view>
</view>
</scroll-view>
</view>
</view>
</view>
</template>
<script>
import {
mapMutations,
mapActions,
mapState,
mapGetters
} from 'vuex';
export default {
components: {},
data() {
return {
listId: 0,
categoryData: {}
};
},
computed: {},
props: {
categoryStyleId: {
type: Number,
default: 0
},
oldCategoryType: {
type: Number,
default: 0
},
categoryIndex: {
type: Number,
default: -1
}
},
created() {
this.getCategory();
},
methods: {
getCategory() {
this.$http('category.detail', {
id: this.categoryStyleId
}).then(res => {
if (res.code === 1) {
this.categoryData = res.data.children;
this.listId = this.categoryIndex < 0 ? 0 : this.categoryIndex;
// 如果oldCategoryType = 3并且分类下没有子分类则显示商品
if (this.oldCategoryType == 3 && !this.categoryData[this.listId].children.length) {
this.handleCategoryChange(2, this.listId);
}
}
});
},
onType(id) {
this.listId = id;
// 如果oldCategoryType = 3并且点击的分类下没有子分类则显示商品
if (this.oldCategoryType == 3 && !this.categoryData[id].children.length) {
this.handleCategoryChange(2, id);
}
},
// 分类类型切换
handleCategoryChange(categoryType, categoryIndex) {
this.$emit('categoryChange', {
type: categoryType,
index: categoryIndex
});
},
// 路由跳转
jump(path, parmas) {
this.$Router.push({
path: path,
query: parmas
});
}
}
};
</script>
<style lang="scss">
.hack-tabbar {
height: calc(100rpx + env(safe-area-inset-bottom) / 2);
width: 100%;
}
.content_box {
display: flex;
flex-direction: column;
overflow: hidden;
height: 100%;
}
.wrapper-box {
flex: 1;
margin-top: 1upx;
height: 100%;
}
.scroll-box {
height: 100%;
flex: 1;
background: #fff;
}
.left {
width: 200upx;
height: 100%;
flex: 1;
.list-active {
background: #fff;
color: #ffff !important;
}
.list-item {
width: 180rpx;
height: 64rpx;
line-height: 64rpx;
padding-left: 14rpx;
}
.line-active {
width: 180rpx;
height: 64rpx;
background: #4C7AF3;
border-radius: 0rpx 32rpx 32rpx 0rpx;
color: #fff;
}
.type-list {
height: 100rpx;
position: relative;
width: 200rpx;
font-size: 28upx;
font-weight: 400;
color: rgba(102, 102, 102, 1);
}
}
.right {
padding: 0 30upx;
flex: 1;
height: 100%;
.type-img {
width: 505rpx;
height: 150rpx;
background: #ccc;
margin-top: 30rpx;
border-radius: 10rpx;
}
.type-box {
height: 84rpx;
.type-title {
font-size: 28rpx;
font-weight: bold;
padding: 0 16rpx;
}
.more {
font-size: 26rpx;
color: #999;
}
}
.item-list {
.item-box {
flex-wrap: wrap;
.goods-item {
margin-right: 20rpx;
margin-bottom: 20rpx;
&:nth-child(3n) {
margin-right: 0;
}
.item-img {
width: 150rpx;
height: 150rpx;
border-radius: 6rpx;
background: #f5f5f5;
}
.item-title {
font-size: 24rpx;
margin-top: 10rpx;
width: 150rpx;
text-align: center;
}
}
}
}
}
</style>