kitchendDevice/pages/menu/menu.vue

178 lines
3.8 KiB
Vue
Raw Normal View History

2023-09-08 15:17:21 +08:00
<template>
<view class="content">
<!-- 搜索 -->
2025-07-28 16:57:16 +08:00
<search></search>
2023-09-08 15:17:21 +08:00
<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-07-28 16:57:16 +08:00
<scroll-view class="right_list" scroll-y="true" @scrolltolower="onPullDown">
<div class="right_inner_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>
</view>
</div>
</scroll-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";
2025-07-28 16:57:16 +08:00
import search from "../../components/search2.vue"
2023-09-08 15:17:21 +08:00
export default {
components: {
search
},
2025-03-25 10:17:30 +08:00
computed: {
2025-07-28 16:57:16 +08:00
...mapState(["menuList","menu_search_value"]),
2025-03-25 10:17:30 +08:00
menu() {
2025-07-28 16:57:16 +08:00
return [...this.menuList,{id:999,name:'搜索'}]
2025-03-25 10:17:30 +08:00
},
},
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: "",
2025-07-28 16:57:16 +08:00
loading: false,
2023-09-08 15:17:21 +08:00
menulist: []
};
},
2025-07-28 16:57:16 +08:00
onLoad(op) {
2023-09-08 15:17:21 +08:00
let that = this
2025-03-25 10:17:30 +08:00
that.page = 1
that.handleCookListLabel()
},
2025-07-28 16:57:16 +08:00
onShow() {
let that = this
if(that.$store.state.menu_search_value != '') {
that.handleSearch(that.$store.state.menu_search_value)
that.$store.state.menu_search_value = ""
}
},
2023-09-08 15:17:21 +08:00
methods: {
2025-07-28 16:57:16 +08:00
onPullDown() {
let that = this
if(that.loading) {
return
}
if (!this.lastPage || this.page >= this.lastPage) {
uni.showToast({
title: '没有更多数据!',
icon: 'none'
})
return
}
this.page++
this.handleCookListLabel()
},
2025-03-25 10:17:30 +08:00
// 食材列表
handleCookListLabel() {
let that = this
2025-07-28 16:57:16 +08:00
that.loading = true
2025-03-25 10:17:30 +08:00
that.$model.getCookListLabel({
cook_label: that.menu[that.index].id,
page: that.page,
}).then(res => {
2025-07-28 16:57:16 +08:00
that.loading = false
2025-03-25 10:17:30 +08:00
if (res.code != 0) return
that.menulist = that.menulist.concat(res.data.content_list)
2025-07-28 16:57:16 +08:00
that.lastPage = res.data.page_total
that.page = res.data.page_now
2025-03-25 10:17:30 +08:00
})
},
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
},
// 商品详情
2025-03-25 10:17:30 +08:00
handleDetail(id) {
2025-04-02 09:49:39 +08:00
if (!uni.getStorageSync('token')) {
this.$tools.msg("登录后查看等多!")
return
}
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 {
2025-07-28 16:57:16 +08:00
uni.showLoading({
title: '搜索中...'
})
that.$model.getMenuSearch({
food_name: ite
2025-03-25 10:17:30 +08:00
}).then(res => {
2025-07-28 16:57:16 +08:00
uni.hideLoading()
2025-03-25 10:17:30 +08:00
if (res.code != 0) return
2025-07-28 16:57:16 +08:00
that.index = that.menu.length - 1
that.menulist = res.data.content_list
2025-03-25 10:17:30 +08:00
})
}
2023-09-08 15:17:21 +08:00
},
}
}
</script>
<style lang="scss" scoped>
2025-07-28 16:57:16 +08:00
.right_list {
padding: 0 !important;
height: 100%;
}
.right_inner_list {
2025-03-25 10:17:30 +08:00
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>