187 行
4.4 KiB
Vue
187 行
4.4 KiB
Vue
<!-- 分类 -->
|
||
<template>
|
||
<view class="category-box">
|
||
<!-- 自定义导航栏(带返回按钮) -->
|
||
<view class="custom-navbar">
|
||
<view class="u-status-bar" :style="{ height: statusBarHeight + 'px' }"></view>
|
||
<view class="navbar-content u-flex u-col-center u-row-between">
|
||
<view class="back-btn u-flex u-row-center u-col-center" @tap.stop="goBack">
|
||
<text class="u-iconfont uicon-arrow-left" style="font-size: 38rpx; color: #333;"></text>
|
||
</view>
|
||
<view class="navbar-title">{{ categoryTitle || '分类' }}</view>
|
||
<view class="right-place"></view>
|
||
</view>
|
||
</view>
|
||
|
||
<view class="category-content">
|
||
<!-- 三级分类 -->
|
||
<three-catgory :categoryStyleId="categoryStyleId" v-if="categoryType === 4"></three-catgory>
|
||
<!-- 二级分类 -->
|
||
<two-catgory @categoryChange="categoryChange" :categoryIndex="categoryIndex" :oldCategoryType="oldCategoryType" :categoryStyleId="categoryStyleId" v-if="categoryType === 3"></two-catgory>
|
||
<!-- 一级分类-->
|
||
<one-catgory @categoryChange="categoryChange" :categoryIndex="categoryIndex" :oldCategoryType="oldCategoryType" :categoryStyleId="categoryStyleId" v-if="categoryType === 2"></one-catgory>
|
||
<!--直接购买 -->
|
||
<takeout-catgory :categoryStyleId="categoryStyleId" v-if="categoryType === 1"></takeout-catgory>
|
||
</view>
|
||
|
||
<!-- 登录提示 -->
|
||
<shopro-auth-modal v-if="authType"></shopro-auth-modal>
|
||
<shopro-tabbar></shopro-tabbar>
|
||
</view>
|
||
</template>
|
||
|
||
<script>
|
||
import takeoutCatgory from './category/takeout-catgory.vue';
|
||
import threeCatgory from './category/three-catgory.vue';
|
||
import twoCatgory from './category/two-catgory.vue';
|
||
import oneCatgory from './category/one-catgory.vue';
|
||
import { mapMutations, mapActions, mapState, mapGetters } from 'vuex';
|
||
|
||
let systemInfo = uni.getSystemInfoSync();
|
||
|
||
export default {
|
||
components: {
|
||
takeoutCatgory,
|
||
threeCatgory,
|
||
twoCatgory,
|
||
oneCatgory
|
||
},
|
||
data() {
|
||
return {
|
||
statusBarHeight: systemInfo.statusBarHeight || 0,
|
||
categoryTitle: '分类',
|
||
oldCategoryType: -1, // 原type,如果是3并且3下面没有子分类则显示商品列表
|
||
categoryType: 0, // 1:快速购买,2:一级分类,3:二级分类,4:三级分类
|
||
categoryStyleId: 0 ,// 分类Id
|
||
categoryIndex: -1 // 分类索引
|
||
};
|
||
},
|
||
computed: {
|
||
...mapGetters(['authType'])
|
||
},
|
||
onLoad() {
|
||
uni.hideTabBar();
|
||
this.getCategory();
|
||
},
|
||
methods: {
|
||
// 返回上一页或首页
|
||
goBack() {
|
||
let pages = getCurrentPages();
|
||
if (pages && pages.length > 1) {
|
||
// #ifdef MP-WEIXIN
|
||
wx.navigateBack({
|
||
delta: 1,
|
||
fail: () => {
|
||
this.$tools.routerTo('/pages/index/index');
|
||
}
|
||
});
|
||
// #endif
|
||
// #ifndef MP-WEIXIN
|
||
uni.navigateBack({
|
||
delta: 1,
|
||
fail: () => {
|
||
this.$tools.routerTo('/pages/index/index');
|
||
}
|
||
});
|
||
// #endif
|
||
} else {
|
||
this.$tools.routerTo('/pages/index/index');
|
||
}
|
||
},
|
||
// 分类切换
|
||
categoryChange(e) {
|
||
this.categoryType = e.type;
|
||
if (e.index >= 0) {
|
||
this.categoryIndex = e.index;
|
||
}
|
||
},
|
||
/**
|
||
* 获取分类数据
|
||
* type4:三级分类, type3:二级分类 ,type2:一级分类,type1:快速购买
|
||
*/
|
||
getCategory() {
|
||
this.$http('category.info', {
|
||
id: this.$Route.query.id ? this.$Route.query.id : 0
|
||
}).then(res => {
|
||
if (res.code === 1) {
|
||
if (res.data?.type) {
|
||
this.categoryType = Number(res.data.type);
|
||
this.categoryStyleId = Number(res.data.id);
|
||
this.categoryTitle = res.data?.name || '分类';
|
||
|
||
if (this.categoryType == 3) {
|
||
this.oldCategoryType = 3;
|
||
}
|
||
|
||
uni.setNavigationBarTitle({
|
||
title: res.data?.name || '分类'
|
||
});
|
||
}
|
||
}
|
||
});
|
||
}
|
||
}
|
||
};
|
||
</script>
|
||
|
||
<style lang="scss">
|
||
.category-box {
|
||
height: 100vh;
|
||
display: flex;
|
||
flex-direction: column;
|
||
overflow: hidden;
|
||
background: #fff;
|
||
}
|
||
|
||
.custom-navbar {
|
||
width: 100%;
|
||
background: #ffffff;
|
||
border-bottom: 1rpx solid #f5f5f5;
|
||
position: relative;
|
||
z-index: 99;
|
||
|
||
.u-status-bar {
|
||
width: 100%;
|
||
}
|
||
|
||
.navbar-content {
|
||
height: 88rpx;
|
||
padding: 0 20rpx;
|
||
position: relative;
|
||
}
|
||
|
||
.back-btn {
|
||
width: 70rpx;
|
||
height: 70rpx;
|
||
border-radius: 50%;
|
||
position: relative;
|
||
z-index: 100;
|
||
cursor: pointer;
|
||
|
||
&:active {
|
||
background: #f0f0f0;
|
||
}
|
||
}
|
||
|
||
.navbar-title {
|
||
font-size: 32rpx;
|
||
font-weight: bold;
|
||
color: #333;
|
||
position: absolute;
|
||
left: 50%;
|
||
transform: translateX(-50%);
|
||
pointer-events: none;
|
||
}
|
||
|
||
.right-place {
|
||
width: 70rpx;
|
||
}
|
||
}
|
||
|
||
.category-content {
|
||
flex: 1;
|
||
height: 0;
|
||
overflow: hidden;
|
||
}
|
||
</style>
|