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.

257 lines
5.5 KiB

<template>
<view class="container">
<view class="head">
<view class="head-left">
<view>
<image src="../../static/menu1.png"></image>
<text>肯悦咖啡体育中心店</text>
</view>
<view>三香路1511号</view>
</view>
<view @click="changeStar" class="head-right">
<u-icon v-if="!hasStar" name="star" color="rgba(0,0,0,0.5)"></u-icon>
<u-icon v-else name="star-fill" color="#d90209"></u-icon>
</view>
</view>
<view class="menu-top">
</view>
<view class="search">
<view class="search-left"></view>
<view class="search-right"></view>
</view>
<view class="main">
<!-- 左侧 -->
<view class="tab-left">
<scroll-view class="menus" :scroll-into-view="menuScrollIntoView" scroll-with-animation scroll-y>
<view class="wrapper">
<view class="menu" :id="`menu-${item.id}`" :class="{'current': item.id === currentCateId,
'current-pre':( currentIndex-1>-1 && currentIndex-1===index)?true:false,
'current-next':(currentIndex+1 === index && currentIndex+1<goods.length)?true:false}"
v-for="(item, index) in goods" :key="index" @tap="handleMenuTap(item.id,index)">
<image :src="item.img"></image>
<view>{{ item.name }}</view>
<!-- <view class="dot" v-show="menuCartNum(item.id)">{{ menuCartNum(item.id) }}</view> -->
</view>
</view>
</scroll-view>
</view>
<view class="tab-right"></view>
</view>
</view>
</template>
<script>
export default {
data() {
return {
hasStar: false,
menuScrollIntoView: '',
currentIndex: -2,
currentCateId: 6905, //默认分类
sizeCalcState: false,
cateScrollTop: 0, // 商品滚动
cart: [], //购物车
goods: [{
id: 0,
name: '疯狂星期四',
img: require("@/static/menu3.png")
}, {
id: 1,
name: '畅销排行榜',
img: require("@/static/menu4.png")
}, {
id: 2,
name: '下午茶',
img: require("@/static/menu5.png")
},{
id: 4,
name: '疯狂星期四',
img: require("@/static/menu6.png")
}, {
id: 5,
name: '畅销排行榜',
img: require("@/static/menu7.png")
}, {
id: 6,
name: '下午茶',
img: require("@/static/menu8.png")
}],
}
},
computed: {
menuCartNum() {
return (id) => this.cart.reduce((acc, cur) => {
if (cur.cate_id === id) {
return acc += cur.number
}
return acc
}, 0)
},
},
methods: {
changeStar() {
this.hasStar = !this.hasStar
},
//点击菜单项事件
handleMenuTap(id, index) {
if (!this.sizeCalcState) {
this.calcSize()
}
this.currentCateId = id
this.currentIndex = index
this.$nextTick(() => this.cateScrollTop = this.goods.find(item => item.id == id).top)
},
calcSize() {
let h = 10
// let view = uni.createSelectorQuery().select('#ads')
// view.fields({
// size: true
// }, data => {
// h += Math.floor(data.height)
// }).exec()
// this.goods.forEach(item => {
// let view = uni.createSelectorQuery().select(`#cate-${item.id}`)
// view.fields({
// size: true
// }, data => {
// item.top = h
// h += data.height
// item.bottom = h
// }).exec()
// })
// this.sizeCalcState = true
},
}
}
</script>
<style lang="scss" scoped>
.container {
width: 100vw;
height: 100vh;
background: #f0f0f0;
font-family: Avenir, Helvetica, Arial, sans-serif;
.head {
background: #fff;
display: flex;
justify-content: space-between;
font-size: 24rpx;
color: rgba(0, 0, 0, .5);
font-weight: 400;
padding: 20rpx 40rpx;
position: fixed;
top:0;
left:0;
height:120rpx;
width:100%;
&-left {
image {
width: 32rpx;
height: 32rpx;
}
text {
font-size: 32rpx;
color: rgba(0, 0, 0, .9);
font-weight: 800;
vertical-align: bottom;
margin-left: 10rpx;
}
}
&-right {
font-size: 32rpx;
}
}
.menu-top{
border-radius: 0 0 40rpx 0;
padding: 40rpx 0;
background-color: #fff;
position: fixed;
width:200rpx;
top:120rpx;
height:80rpx;
left:0;
z-index:10;
}
.search{
width:200rpx;
height:80rpx;
border-radius: 0 0 40rpx 0;
background-color: #fff;
}
.main {
height: calc(100vh -200rpx);
width: 100%;
display: flex;
justify-content: space-between;
background: #fff;
position: absolute;
top:200rpx;
left:0;
width:100%;
.tab-left {
// background-color: #fff;
width: 200rpx;
height: 100%;
background: #f0f0f0;
.menus {
height: 100%;
overflow: hidden;
.wrapper{
margin-top: -18px;
position: relative;
z-index: 1;
}
.menu {
text-align: center;
background: #fff;
font-size: 0;
padding: 40rpx 0;
image {
width: 64rpx;
height: 64rpx;
}
view {
color: rgba(0, 0, 0, .5);
font-size: 20rpx;
margin-top: 10rpx;
}
}
.current {
background: #f0f0f0;
}
.current-pre {
border-radius: 0 0 40rpx 0;
}
.current-next {
border-radius: 0 40rpx 0 0;
}
// background-color: #fff;
}
}
.tab-right {
border-radius: 40rpx 0 0 0;
width: calc(100% - 200rpx);
background: #f0f0f0;
}
}
}
</style>