uniapp 学习笔记十六 底部菜单结构自定义搭建
底部菜单触发不同分类数据渲染
分类遮罩交互渲染
cake.vue
<template>
<view>
<nav-custom></nav-custom>
<view class="cont">
<good-item v-for="(item,index) in glist" :gdata="item"></good-item>
</view>
<view class="fixed flex justify-center bg-fff padding-sm">
<view v-for="(item,index) in tabArr" :key="index" @tap="handleTab(item)"
class="flex justify-around align-center">
<view class="">{{item.name}}</view>
<u-line v-if="index<tabArr.length-1" direction="col" length="15" margin="30upx"></u-line>
</view>
</view>
<u-popup :show="show" mode="left" @close="handleClose">
<view class="pop-cont">
<view v-for="(item,index) in cfylist" class="padding-sm u-border-bottom">
{{item.bname}}
<view v-if="index==0">
<view @tap="listShow=!listShow" class="padding-tb-sm u-border-top margin-top">
口味筛选
</view>
<u-cell-group v-if="listShow">
<u-cell v-for="(itm,idx) in item.list" :title="itm.tname" isLink></u-cell>
</u-cell-group>
<view @tap="sceneShow=!sceneShow" class="padding-tb-sm u-border-top">
场景筛选
</view>
<u-cell-group v-if="sceneShow">
<u-cell v-for="(itm,idx) in item.scene" :title="itm.tname" isLink></u-cell>
</u-cell-group>
</view>
</view>
</view>
</u-popup>
</view>
</template>
<script>
export default {
data() {
return {
cfylist:[],
sceneShow:false,
listShow:false,
show: false,
glist: [],
page: 0,
tabArr: [{
name: '分类',
bcid: '',
target: ''
},
{
name: '蛋糕',
bcid: '1',
target: '/pages/cake'
},
{
name: '面包',
bcid: '11',
target: '/pages/bread'
},
{
name: '小食',
bcid: '6',
target: '/pages/food'
},
{
name: '购物车',
bcid: '',
target: '/pages/cart'
}
]
}
},
computed:{
num(){
return this.$store.state.num
}
},
methods: {
handleDetail(idx) {
console.log(idx);
uni.navigateTo({
url: '../detail/detail?idx=' + idx
})
},
loadData(bcid = 1) {
let skip = this.page * 8
let url = `/1.1/classes/goods?where={"bcid":${bcid}}&limit=8&skip=${skip}`;
this.$get(url).then(res => {
uni.stopPullDownRefresh()
let {
results
} = res
if (results.length) {
this.page++
this.glist = [
...this.glist,
...res.results
]
return
}
uni.showToast({
title: '这回真没了...',
icon: 'none'
})
})
},
handleTab(item) {
let {
bcid,
target
} = item
if (bcid) {
this.glist = []
this.page = 0
this.loadData(bcid)
}
if (!bcid && !target) {
this.show = true
}
},
handleClose(){
this.show = false
}
},
onLoad() {
this.loadData()
this.$get('/1.1/classes/classify').then(res=>{
console.log(res)
this.cfylist = res.results
})
},
onReachBottom() {
console.log('触底了');
this.loadData()
},
onPullDownRefresh() {
this.glist = []
this.page = 0
this.loadData()
}
}
</script>
<style lang="scss">
page {
padding-top: 100upx;
padding-bottom: 120upx;
}
.cont {
display: flex;
flex-wrap: wrap;
padding: 15upx;
justify-content: space-between;
}
.fixed {
position: fixed;
bottom: 0;
left: 0;
width: 100%;
box-shadow: 0 0 10upx 2upx rgba(0, 0, 0, 0.2);
}
.cu-bar{
position: fixed;
top: 0;
left: 0;
width: 100%;
z-index: 2;
}
.pop-cont{
width: 400upx;
margin-top: 200upx;
}
</style>
page.json
{
"path" : "pages/cake/cake",
"style" :
{
"navigationBarTitleText": "",
"enablePullDownRefresh": true,
"navigationStyle": "custom"
}
},
nav-custom.vue
<template>
<view class="cu-bar bg-white">
<view class="action">
<text class="cuIcon-locationfill text-gray"></text>
重庆
</view>
<view class="content text-bold">
Macoffee
</view>
<view class="action text-gray">
<text class="cuIcon-search"></text>
<u-line direction="col" length="15" margin="20upx"></u-line>
<text class="cuIcon-sort"></text>
</view>
</view>
</template>
<script>
export default {
name:"nav-custom",
data() {
return {
};
}
}
</script>
<style lang="scss">
.cu-bar{
position: fixed;
top: 0;
left: 0;
width: 100%;
z-index: 2;
}
</style>