kitchendDevice/pages/menu/menu.vue

156 lines
3.0 KiB
Vue
Raw Normal View History

2023-09-08 15:17:21 +08:00
<template>
<view class="content">
<!-- 搜索 -->
<search @handleSearch="handleSearch"></search>
<view class="box menu">
<!-- 左侧菜单栏 -->
<view class="left">
<view class="name" v-for="(ite,ind) in menu" :key="ind" :class="[index==ind?'active':'']"
@click="handleToggle(ind)">
{{ite.name}}
</view>
</view>
<!-- 右侧商品 -->
<view class="right">
2025-03-25 10:17:30 +08:00
<view class="right_list">
<view class="list" v-for="(ite,ind) in menulist" :key="ind" @click="handleDetail(ite.id)"
v-if="menulist.length">
<image :src="ite.cover" mode="aspectFill"></image>
<text class="overflow">{{ite.title}}</text>
2023-09-08 15:17:21 +08:00
</view>
</view>
2025-03-25 10:17:30 +08:00
<view v-if="!menulist.length" class="nolist">
<icon class="iconfont icon-wancan"></icon>
<text>还没有记录哦</text>
</view>
2023-09-08 15:17:21 +08:00
</view>
</view>
</view>
2025-03-25 10:17:30 +08:00
</view>
2023-09-08 15:17:21 +08:00
</template>
<script>
2025-03-25 10:17:30 +08:00
import {
mapState
} from "vuex";
2023-09-08 15:17:21 +08:00
import search from "../../components/search.vue"
export default {
components: {
search
},
2025-03-25 10:17:30 +08:00
computed: {
...mapState(["menuList"]),
menu() {
return this.menuList
},
},
2023-09-08 15:17:21 +08:00
data() {
return {
2025-03-25 10:17:30 +08:00
page: 1,
2023-09-08 15:17:21 +08:00
text: "",
index: 0,
2025-03-25 10:17:30 +08:00
lastPage: "",
2023-09-08 15:17:21 +08:00
menulist: []
};
},
onLoad() {
let that = this
2025-03-25 10:17:30 +08:00
that.page = 1
that.handleCookListLabel()
},
onReachBottom() {
let that = this
if (!this.lastPage || this.page >= this.lastPage) {
uni.showToast({
title: '没有更多数据!',
icon: 'none'
})
return
}
this.page++
this.handleCookListLabel()
2023-09-08 15:17:21 +08:00
},
methods: {
2025-03-25 10:17:30 +08:00
// 食材列表
handleCookListLabel() {
let that = this
that.$model.getCookListLabel({
cook_label: that.menu[that.index].id,
page: that.page,
}).then(res => {
if (res.code != 0) return
that.menulist = that.menulist.concat(res.data.content_list)
})
},
2023-09-08 15:17:21 +08:00
// 左侧切换
2025-03-25 10:17:30 +08:00
handleToggle(ind) {
2023-09-08 15:17:21 +08:00
let that = this
2025-03-25 10:17:30 +08:00
that.index = ind
that.page = 1
that.menulist = []
that.handleCookListLabel()
2023-09-08 15:17:21 +08:00
},
// 查看更多
handleList() {
uni.navigateTo({
url: "/pageTwo/me/mymenu?type=" + this.text
})
},
// 商品详情
2025-03-25 10:17:30 +08:00
handleDetail(id) {
2023-09-08 15:17:21 +08:00
uni.navigateTo({
2025-03-25 10:17:30 +08:00
url: "/pageTwo/me/menudetail?id=" + id
2023-09-08 15:17:21 +08:00
})
},
// 搜索
handleSearch(ite) {
2025-03-25 10:17:30 +08:00
let that = this
console.log("搜索", ite)
that.page = 1
that.menulist = []
if (ite == '') {
that.index = 0
that.handleCookListLabel()
} else {
that.$model.getHomeSearch({
search_data: ite
}).then(res => {
if (res.code != 0) return
that.index = null
that.menulist = res.data
})
}
2023-09-08 15:17:21 +08:00
},
}
}
</script>
<style lang="scss" scoped>
2025-03-25 10:17:30 +08:00
.right_list {
padding: 0 !important;
display: flex;
flex-wrap: wrap;
margin-top: 10px;
// justify-content: space-between;
}
.list {
width: 33.3%;
image {
margin: auto;
width: 140rpx;
height: 140rpx;
border-radius: 10px;
}
text {
width: 100%;
display: inline-block;
text-align: center;
margin-bottom: 10px;
}
}
</style>