kitchendDevice/pageTwo/me/foodlist.vue

365 lines
7.4 KiB
Vue
Raw Normal View History

2023-09-08 15:17:21 +08:00
<template>
<view class="content">
<!-- 搜索 -->
<search @handleSearch="handleSearch"></search>
2025-04-03 16:29:29 +08:00
<!-- 头部1级菜单栏 -->
<view class="tab_list">
<scroll-view class="scroll-menu" scroll-x="true" style="white-space: nowrap;">
<view class="tabbar" v-for="(ite,ind) in menuTop" :key="ind" @click="handleToggle(ind)">
<view :class="[index ==ind?'active':'']">{{ite.name}}</view>
</view>
</scroll-view>
</view>
<view class="box menu" :class="[ActiveList.length?'maxheight':'']">
2025-03-25 10:17:30 +08:00
<!-- 左侧2级商品 -->
2025-04-03 16:29:29 +08:00
<view class="left">
2025-03-25 10:17:30 +08:00
<view class="name" v-for="(ite,ind) in menu2" :key="ind" :class="[leftInd==ind?'active':'']"
@click="handleToggleLeft(ind)">
2023-09-08 15:17:21 +08:00
{{ite.name}}
</view>
</view>
2025-03-25 10:17:30 +08:00
<!-- 右侧3级 -->
2025-04-03 16:29:29 +08:00
<view class="right">
2025-03-25 10:17:30 +08:00
<view class="list mt-15">
2025-04-03 16:29:29 +08:00
<view class="item" v-for="(ite,ind) in menu3" :key="ind" @click="handleDetail(ite,1)"
2025-03-25 10:17:30 +08:00
:class="[ActiveList.indexOf(ite)!=-1?'active0':'']">
2025-04-03 16:29:29 +08:00
<text class="overflow">{{ite.name}}</text>
2025-03-25 10:17:30 +08:00
<icon class="iconfont" :class="[ActiveList.indexOf(ite)!=-1?'icon-xuanzhong':'icon-add']" />
2023-09-08 15:17:21 +08:00
</view>
2025-07-28 16:57:16 +08:00
<!-- <div class="slot" style="width: 100%;height: 340rpx;" v-if="ActiveList.length>0"></div> -->
2023-09-08 15:17:21 +08:00
</view>
2025-03-25 10:17:30 +08:00
<view v-if="!menu3.length" class="nolist">
<icon class="iconfont icon-wancan"></icon>
<text>还没有数据哦</text>
</view>
2023-09-08 15:17:21 +08:00
</view>
</view>
<!-- 选中区 -->
<view class="activeList" v-if="ActiveList.length">
<view class="list">
<view class="item" v-for="(ite,ind) in ActiveList" :key="ind">
<text>{{ite.name}}</text>
2025-04-03 16:29:29 +08:00
<icon class="iconfont icon-quxiao" @click="handleDetail(ite,2)"></icon>
2023-09-08 15:17:21 +08:00
</view>
</view>
<view class="groupbtn">
<view @click="handledelete">清空</view>
<view class="subbtn" @click="handlesubbtn"> 确定</view>
</view>
</view>
</view>
</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
},
data() {
return {
text: "",
index: 0,
2025-03-25 10:17:30 +08:00
leftInd: 0,
2023-09-08 15:17:21 +08:00
menu: [],
2025-03-25 10:17:30 +08:00
menu2: [],
menu3: [],
2023-09-08 15:17:21 +08:00
menulist: [],
ActiveList: [],
2025-03-25 10:17:30 +08:00
page: 1,
2023-09-08 15:17:21 +08:00
type: "",
2025-03-25 10:17:30 +08:00
name: "",
lastPage: "",
2023-09-08 15:17:21 +08:00
};
},
2025-03-25 10:17:30 +08:00
computed: {
...mapState(["foodList"]),
menuTop() {
2025-07-28 16:57:16 +08:00
this.menu2 = this.foodList.length ? this.foodList[0].list : [],
console.log([...this.foodList, {
id: 4,
list: [],
name: '搜索'
}])
return [...this.foodList, {
id: 4,
list: [],
name: '搜索'
}]
2025-03-25 10:17:30 +08:00
},
},
onLoad(options) {
2023-09-08 15:17:21 +08:00
let that = this
2025-03-25 10:17:30 +08:00
if (options && options.list) {
let list = JSON.parse(options.list)
console.log("11111111", list)
}
that.handleHomeInfo()
},
2025-04-03 16:29:29 +08:00
onPullDownRefresh() {
2025-03-25 10:17:30 +08:00
let that = this
if (!this.lastPage || this.page >= this.lastPage) {
uni.showToast({
title: '没有更多数据!',
icon: 'none'
})
return
}
this.page++
if (that.menu2.length) {
that.handleHomeInfo()
}
2025-04-03 16:29:29 +08:00
setTimeout(function() {
uni.stopPullDownRefresh();
}, 500);
2023-09-08 15:17:21 +08:00
},
methods: {
2025-03-25 10:17:30 +08:00
handleHomeInfo() {
2023-09-08 15:17:21 +08:00
let that = this
2025-03-25 10:17:30 +08:00
that.$model.getCookFoodList({
food_level2_id: that.menu2[that.leftInd].id,
page: that.page,
search_data: that.name
}).then(res => {
if (res.code != 0) return
that.lastPage = res.data.page_total
that.menu3 = that.menu3.concat(res.data.content_list)
})
2023-09-08 15:17:21 +08:00
},
2025-03-25 10:17:30 +08:00
// 头部切换
handleToggle(ind) {
let that = this
that.index = ind
that.leftInd = 0
that.menu2 = that.menuTop[ind].list
that.menu3 = []
that.page = 1
if (that.menu2.length) {
that.handleHomeInfo()
}
},
// 左侧切换
handleToggleLeft(ind) {
let that = this
that.leftInd = ind
that.menu3 = []
that.page = 1
that.handleHomeInfo()
2023-09-08 15:17:21 +08:00
},
// 商品选择
2025-04-03 16:29:29 +08:00
handleDetail(ite, ind) {
2023-09-08 15:17:21 +08:00
var that = this;
2025-04-03 16:29:29 +08:00
let list = []
if (ind == 1) {
list.push(ite)
that.ActiveList = that.$tools.mergeAndDeduplicate(that.ActiveList, list, 'name')
2023-09-08 15:17:21 +08:00
} else {
2025-04-03 16:29:29 +08:00
for (var n = 0; n < that.ActiveList.length; n++) {
if (ite.name == that.ActiveList[n].name) {
that.ActiveList.splice(n, 1)
}
}
2023-09-08 15:17:21 +08:00
}
},
2025-03-25 10:17:30 +08:00
// 商品清空
handledelete() {
this.ActiveList = []
},
2023-09-08 15:17:21 +08:00
// 商品提交
handlesubbtn() {
let that = this
let pages = getCurrentPages()
let prevPage = pages[pages.length - 2]
prevPage.$vm.getAddFood(that.ActiveList)
uni.navigateBack({
delta: 1
})
},
// 搜索
2025-03-25 10:17:30 +08:00
handleSearch(name) {
let that = this
let list = []
if (name != "") {
2025-07-28 16:57:16 +08:00
that.$model.getFoodSearch({
food_name: name
}).then(res => {
if (res.code != 0) {
uni.showToast({
title: res.msg,
icon: 'error'
})
return
}
that.index = 3
that.menu2 = []
that.menu3 = res.data
2025-03-25 10:17:30 +08:00
})
}
2023-09-08 15:17:21 +08:00
},
}
}
</script>
<style lang="scss" scoped>
2025-03-25 10:17:30 +08:00
.tab_list {
display: flex;
2025-04-03 16:29:29 +08:00
top: 50px;
width: 100%;
position: fixed;
z-index: 99;
height: 45px;
background: #FFF;
2025-03-25 10:17:30 +08:00
justify-content: space-between;
.scroll-menu {
width: 100%;
.tabbar {
padding: 10px;
display: inline-block;
view {
display: inline-block;
}
}
}
.active {
color: #fff;
padding: 5px 8px;
border-radius: 5px;
background-color: #ff4c4f;
}
}
2025-04-03 16:29:29 +08:00
.menu {
width: 100%;
position: relative;
margin-top: 101px;
height: calc(100vh - 101px) !important;
2025-07-28 16:57:16 +08:00
.left {
top: 101px !important;
position: fixed;
background-color: #f7f7f7;
height: calc(100vh - 100px);
}
.right {
top: 0px !important;
height: calc(100vh - 100px);
.list {
display: flex;
flex-wrap: wrap;
}
.item {
width: 29%;
border: 1px solid #dfdfdf;
display: flex;
align-items: center;
box-sizing: border-box;
justify-content: space-between;
height: 30px;
border-radius: 5px;
margin: 0 2% 10px;
padding: 0 5px;
text {
margin-bottom: 0 !important;
}
}
.icon-xuanzhong {
color: $maincolor;
}
.active0 {
border: 1px solid $maincolor;
}
}
2023-09-08 15:17:21 +08:00
}
.activeList {
position: fixed;
bottom: 0px;
left: 0;
right: 0;
z-index: 999;
background: #fff;
2025-03-25 10:17:30 +08:00
padding: 10px 0;
2023-09-08 15:17:21 +08:00
border-radius: 10px 10px 0 0;
box-shadow: 0px 1px 5px 2px #dfe2e1fc;
.list {
height: 340rpx;
overflow: scroll;
padding-bottom: 55px;
2025-04-03 16:29:29 +08:00
// display: flex;
// flex-wrap: wrap;
2023-09-08 15:17:21 +08:00
.item {
2025-03-25 10:17:30 +08:00
border: 1px solid $maincolor;
2023-09-08 15:17:21 +08:00
display: flex;
2025-04-03 16:29:29 +08:00
justify-content: space-between;
2023-09-08 15:17:21 +08:00
height: 28px;
2025-03-25 10:17:30 +08:00
box-sizing: border-box;
2023-09-08 15:17:21 +08:00
border-radius: 5px;
align-items: center;
2025-03-25 10:17:30 +08:00
margin: 0 2% 10px;
2025-04-03 16:29:29 +08:00
float: left;
2025-07-28 16:57:16 +08:00
padding: 0 10px;
2023-09-08 15:17:21 +08:00
icon {
2025-03-25 10:17:30 +08:00
color: $maincolor;
2023-09-08 15:17:21 +08:00
font-size: 16px;
2025-07-28 16:57:16 +08:00
margin-left: 10rpx;
2023-09-08 15:17:21 +08:00
}
}
}
.groupbtn {
display: flex;
justify-content: space-between;
position: absolute;
left: 0px;
right: 0px;
bottom: 0px;
padding: 10px;
background: #fff;
border-top: 1px solid #f7f7f7;
view {
width: 40%;
text-align: center;
border: 1px solid #dfdfdf;
border-radius: 10px;
height: 31px;
line-height: 31px;
}
.subbtn {
color: #fff;
2025-03-25 10:17:30 +08:00
border-color: $maincolor;
background-color: $maincolor;
2023-09-08 15:17:21 +08:00
}
}
}
.maxheight {
2025-04-03 16:29:29 +08:00
.left {
2025-07-28 16:57:16 +08:00
height: calc(100vh - 680rpx);
2025-04-03 16:29:29 +08:00
}
2025-07-28 16:57:16 +08:00
.right {
height: calc(100vh - 680rpx);
}
2023-09-08 15:17:21 +08:00
}
2025-03-25 10:17:30 +08:00
</style>