kitchendDevice/pageTwo/me/foodlist.vue

355 lines
7.1 KiB
Vue

<template>
<view class="content">
<!-- 搜索 -->
<search @handleSearch="handleSearch"></search>
<!-- 头部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':'']">
<!-- 左侧2级商品 -->
<view class="left">
<view class="name" v-for="(ite,ind) in menu2" :key="ind" :class="[leftInd==ind?'active':'']"
@click="handleToggleLeft(ind)">
{{ite.name}}
</view>
</view>
<!-- 右侧3级 -->
<view class="right">
<view class="list mt-15">
<view class="item" v-for="(ite,ind) in menu3" :key="ind" @click="handleDetail(ite,1)"
:class="[ActiveList.indexOf(ite)!=-1?'active0':'']">
<text class="overflow">{{ite.name}}</text>
<icon class="iconfont" :class="[ActiveList.indexOf(ite)!=-1?'icon-xuanzhong':'icon-add']" />
</view>
</view>
<view v-if="!menu3.length" class="nolist">
<icon class="iconfont icon-wancan"></icon>
<text>还没有数据哦!</text>
</view>
</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>
<icon class="iconfont icon-quxiao" @click="handleDetail(ite,2)"></icon>
</view>
</view>
<view class="groupbtn">
<view @click="handledelete">清空</view>
<view class="subbtn" @click="handlesubbtn"> 确定</view>
</view>
</view>
</view>
</template>
<script>
import {
mapState
} from "vuex";
import search from "../../components/search.vue"
export default {
components: {
search
},
data() {
return {
text: "",
index: 0,
leftInd: 0,
menu: [],
menu2: [],
menu3: [],
menulist: [],
ActiveList: [],
searchResults: [],
page: 1,
type: "",
name: "",
lastPage: "",
};
},
computed: {
...mapState(["foodList"]),
menuTop() {
this.menu2 = this.foodList.length ? this.foodList[0].list : []
return this.foodList
},
},
onLoad(options) {
let that = this
if (options && options.list) {
let list = JSON.parse(options.list)
console.log("11111111", list)
}
that.handleHomeInfo()
},
onPullDownRefresh() {
let that = this
if (!this.lastPage || this.page >= this.lastPage) {
uni.showToast({
title: '没有更多数据!',
icon: 'none'
})
return
}
this.page++
if (that.menu2.length) {
that.handleHomeInfo()
}
setTimeout(function() {
uni.stopPullDownRefresh();
}, 500);
},
methods: {
handleHomeInfo() {
let that = this
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)
})
},
// 头部切换
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()
},
// 商品选择
handleDetail(ite, ind) {
var that = this;
let list = []
if (ind == 1) {
list.push(ite)
that.ActiveList = that.$tools.mergeAndDeduplicate(that.ActiveList, list, 'name')
} else {
for (var n = 0; n < that.ActiveList.length; n++) {
if (ite.name == that.ActiveList[n].name) {
that.ActiveList.splice(n, 1)
}
}
}
},
// 商品清空
handledelete() {
this.ActiveList = []
},
// 商品提交
handlesubbtn() {
let that = this
let pages = getCurrentPages()
let prevPage = pages[pages.length - 2]
prevPage.$vm.getAddFood(that.ActiveList)
uni.navigateBack({
delta: 1
})
},
// 搜索
handleSearch(name) {
let that = this
let list = []
if (name != "") {
that.searchResults = []
that.menu.forEach((item, index) => {
item.list.forEach((ite, ind) => {
ite.list.forEach((it, id) => {
if (it.name.indexOf(name) !== -1) {
that.searchResults.push(it)
return
}
})
})
})
that.index = that.menu.findIndex(ite => ite.id == that.searchResults[0].one_id)
console.log("arr", that.searchResults, )
} else {
that.index = 0
that.searchResults = []
}
},
}
}
</script>
<style lang="scss" scoped>
.tab_list {
display: flex;
top: 50px;
width: 100%;
position: fixed;
z-index: 99;
height: 45px;
background: #FFF;
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;
}
}
.menu {
width: 100%;
position: relative;
margin-top: 101px;
height: calc(100vh - 101px) !important;
}
.left {
top: 101px !important;
position: fixed;
background-color: #f7f7f7;
}
.right {
top: 0px !important;
.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;
}
}
.activeList {
position: fixed;
bottom: 0px;
left: 0;
right: 0;
z-index: 999;
background: #fff;
padding: 10px 0;
border-radius: 10px 10px 0 0;
box-shadow: 0px 1px 5px 2px #dfe2e1fc;
.list {
height: 340rpx;
overflow: scroll;
padding-bottom: 55px;
// display: flex;
// flex-wrap: wrap;
.item {
width: 29%;
border: 1px solid $maincolor;
display: flex;
justify-content: space-between;
height: 28px;
box-sizing: border-box;
border-radius: 5px;
align-items: center;
margin: 0 2% 10px;
float: left;
padding: 0 5px;
icon {
color: $maincolor;
font-size: 16px;
}
}
}
.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;
border-color: $maincolor;
background-color: $maincolor;
}
}
}
.maxheight {
padding-bottom: 265rpx;
.left {
height: calc(100vh - 500rpx);
}
}
</style>