kitchendDevice/pageTwo/me/foodlist.vue

637 lines
13 KiB
Vue
Raw Normal View History

2023-09-08 15:17:21 +08:00
<template>
<view class="content">
<!-- 搜索 -->
2025-11-25 14:21:22 +08:00
<view class="serachBox">
<view class="serach-box">
<view class="searchInput">
<input placeholder="请输入..." class="city-serach-input" v-model="search_value" />
<icon v-if="search_value" class="iconfont icon-error" @click="handlecolse"></icon>
2025-04-03 16:29:29 +08:00
</view>
2025-11-25 14:21:22 +08:00
<view class="searchBtn">
<view @click="handleSerach">搜索</view>
2023-09-08 15:17:21 +08:00
</view>
</view>
2025-11-25 14:21:22 +08:00
</view>
<!-- 历史搜索 -->
<view class="content-box" v-if="!search_list.length">
<view v-if="history_food.length" class="search-history">
<view class="title">
<view class="quan mr-5"></view>历史搜索
</view>
2025-11-29 10:02:33 +08:00
<view class="button-container" @click="showAll =! showAll" v-if="history_food.length>8">
2025-11-25 14:21:22 +08:00
<image :src="showAll?'/static/arrow-up.png':'/static/arrow-down.png'"></image>
</view>
<view class="history-list">
<view class="history-list-item"
2025-11-29 10:02:33 +08:00
v-for="(item,index) in showAll?history_food:history_food.slice(0, 8)"
2025-11-25 14:21:22 +08:00
@click="handleSearchHistory(item.keyword)">
{{item.keyword}}
2023-09-08 15:17:21 +08:00
</view>
</view>
2025-11-25 14:21:22 +08:00
</view>
<view class="popular-container">
<view class="title">
<view class="quan mr-5"></view>猜你想搜
</view>
<view class="popular-food-item" v-for="(ite,index) in popular_food" :key="index">
<view class="food-title">{{ite.title}}</view>
<view class="popular-food-inner">
<text class="popular-food-subitem" v-for="(sub_item,sub_index) in ite.list"
@click="handleSearchHistory(sub_item.name)" :key="sub_index">{{sub_item.name}}
</text>
</view>
2025-03-25 10:17:30 +08:00
</view>
2023-09-08 15:17:21 +08:00
</view>
</view>
2025-11-25 14:21:22 +08:00
<!-- 搜索列表 -->
<view class="search_list" v-if="search_list.length">
<view class="search_list_item" v-for="(ite,ind) in search_list" @click="handleDetail(ite,1)">
<image :src="ite.pic_url"></image>
<view>
2023-09-08 15:17:21 +08:00
<text>{{ite.name}}</text>
2025-11-25 14:21:22 +08:00
<text>100g/{{ite.kcal}}kcal</text>
</view>
<view v-if="ActiveList.indexOf(ite)!=-1" class="dui">
<uni-icons type="checkmarkempty" size="22" color="#F7931E"></uni-icons>
2023-09-08 15:17:21 +08:00
</view>
</view>
2025-11-25 14:21:22 +08:00
<view class="endtext" v-if="!lastPage || page >= lastPage"> 到底了看看别的吧 </view>
</view>
2025-11-29 10:02:33 +08:00
<!-- 底部购物车 -->
<view class="groupbtn">
<view class="jilu">
<view class="che" @click="isShop =! isShop">
<text>{{ActiveList.length||0}}</text>
<icon class="t-icon t-icon-canpan"></icon>
2025-11-25 14:21:22 +08:00
</view>
2025-12-04 15:02:07 +08:00
<!-- <view class="subbtn" @click="handlesubbtn"> 确定</view> -->
2023-09-08 15:17:21 +08:00
</view>
2025-12-04 15:02:07 +08:00
<view class="mic-icon" @touchstart="onVoiceTouchStart" @touchend="onVoiceTouchEnd"
@touchcancel="cancelRecording">
2025-11-29 10:02:33 +08:00
<uni-icons type="mic-filled" size="20" :color="mic_touch ? '#777777' : '#fff'"></uni-icons>
语音搜索
2025-11-25 14:21:22 +08:00
</view>
</view>
<!-- 购物车列表 -->
<view class="wrapper activeList" v-if="isShop">
<view class="bg" @click='isShop=false'>
<view class="box2" @click.stop>
<view class="list" v-if="ActiveList.length">
<view class="item" v-for="(ite,ind) in ActiveList" :key="ind">
<view class="">
<text class="name">{{ite.name}}</text>
</view>
<icon class="iconfont icon-ashbin" color="red" size="26" @click="handledelactive(ite)">
</icon>
</view>
</view>
<view v-else class="nolist list">
<icon class="iconfont icon-wancan"></icon>
<text>还没有记录哦</text>
</view>
</view>
</view>
</view>
2025-12-04 15:02:07 +08:00
<!-- -->
<!-- 语音弹框 -->
<view class="wrapper" v-if="showAutoSearchDlg">
<view class="auto-search-dialog">
<view class="auto-search-inner">
<view class="voice-wave">
<view class="wave-bar"></view>
<view class="wave-bar"></view>
<view class="wave-bar"></view>
<view class="wave-bar"></view>
<view class="wave-bar"></view>
<view class="wave-bar"></view>
</view>
</view>
</view>
</view>
2025-11-25 14:21:22 +08:00
2023-09-08 15:17:21 +08:00
</view>
</template>
<script>
2025-03-25 10:17:30 +08:00
import {
mapState
} from "vuex";
2025-11-25 14:21:22 +08:00
const plugin = requirePlugin("WechatSI")
2023-09-08 15:17:21 +08:00
export default {
data() {
return {
index: 0,
2025-03-25 10:17:30 +08:00
page: 1,
2025-11-25 14:21:22 +08:00
isShop: false,
showAll: false,
IsWeight: false,
search_list: [],
ActiveList: [],
2025-03-25 10:17:30 +08:00
lastPage: "",
2025-11-25 14:21:22 +08:00
search_value: '',
mic_touch: false,
voiceManager: null,
autoSearchContent: "",
showAutoSearchDlg: false
2023-09-08 15:17:21 +08:00
};
},
2025-03-25 10:17:30 +08:00
computed: {
2025-11-25 14:21:22 +08:00
...mapState(["configInfo", "user"]),
popular_food() {
return this.configInfo.search_guess.food_data
2025-03-25 10:17:30 +08:00
},
2025-11-25 14:21:22 +08:00
history_food() {
return this.configInfo.search_history.food
}
},
onLoad() {
let that = this
2025-03-25 10:17:30 +08:00
},
2025-11-25 14:21:22 +08:00
mounted() {
2023-09-08 15:17:21 +08:00
let that = this
2025-11-25 14:21:22 +08:00
that.voiceManager = plugin.getRecordRecognitionManager()
that.voiceManager.onStop = function(res) {
that.autoSearchContent = res.result.replace('。', '')
}
that.voiceManager.onError = function(res) {
console.error("error msg", res.retcode)
2025-03-25 10:17:30 +08:00
}
2025-11-25 14:21:22 +08:00
that.voiceManager.stop()
2025-03-25 10:17:30 +08:00
},
2025-11-25 14:21:22 +08:00
onReachBottom() {
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++
2025-11-25 14:21:22 +08:00
this.handleSerach()
2023-09-08 15:17:21 +08:00
},
methods: {
2025-11-25 14:21:22 +08:00
// 食物选择
2025-04-03 16:29:29 +08:00
handleDetail(ite, ind) {
2025-11-25 14:21:22 +08:00
let that = this
2025-04-03 16:29:29 +08:00
let list = []
2025-12-04 15:02:07 +08:00
let pages = getCurrentPages()
let prevPage = pages[pages.length - 2]
2025-04-03 16:29:29 +08:00
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-12-04 15:02:07 +08:00
prevPage.$vm.getAddFood(that.ActiveList)
2023-09-08 15:17:21 +08:00
},
2025-11-25 14:21:22 +08:00
// 搜索
handleSerach() {
let that = this
2025-12-04 15:02:07 +08:00
that.search_list = []
2025-11-29 10:02:33 +08:00
if (that.search_value == "") {
that.$tools.msg("输入关键字后搜索")
return
}
2025-11-25 14:21:22 +08:00
that.$model.getFoodSearch({
page: that.page,
search_data: that.search_value
}).then(res => {
if (res.code != 0) {
uni.showToast({
title: res.msg,
icon: 'error'
})
return
}
that.search_list = that.search_list.concat(res.data.content_list)
})
},
// 取消搜索
handlecolse() {
this.search_value = ""
this.search_list = []
},
// 历史搜索
handleSearchHistory(text) {
let that = this
that.search_value = text
that.showAutoSearchDlg = false
that.autoSearchContent = ''
that.handleSerach()
},
// 开始说话
onVoiceTouchStart() {
let that = this
2025-12-04 15:02:07 +08:00
that.showAutoSearchDlg = true
2025-11-25 14:21:22 +08:00
that.voiceManager.start({
duration: 60000,
lang: "zh_CN"
})
},
// 语音结束
onVoiceTouchEnd() {
let that = this
2025-12-04 15:02:07 +08:00
that.showAutoSearchDlg = false
2025-11-25 14:21:22 +08:00
that.voiceManager.stop()
2025-03-25 10:17:30 +08:00
},
2025-12-04 15:02:07 +08:00
// 取消录音
cancelRecording() {
// #ifdef MP-WEIXIN
if (this.voiceManager) {
this.voiceManager.stop()
this.showAutoSearchDlg = false
}
// #endif
},
2025-11-25 14:21:22 +08:00
// 购物车提交
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-11-25 14:21:22 +08:00
//删除购物车食材
handledelactive(ite) {
2025-03-25 10:17:30 +08:00
let that = this
2025-12-04 15:02:07 +08:00
let pages = getCurrentPages()
let prevPage = pages[pages.length - 2]
prevPage.$vm.handledel(ite.id, "食材")
2025-11-25 14:21:22 +08:00
that.ActiveList.splice(that.ActiveList.indexOf(ite), 1);
2023-09-08 15:17:21 +08:00
},
}
}
</script>
<style lang="scss" scoped>
2025-11-25 14:21:22 +08:00
.serachBox {
height: 80rpx;
2025-04-03 16:29:29 +08:00
position: fixed;
2025-11-25 14:21:22 +08:00
top: 0;
left: 0;
right: 0;
padding: 30rpx 20rpx;
z-index: 19;
background-color: #efefef;
2025-03-25 10:17:30 +08:00
2025-11-25 14:21:22 +08:00
.serach-box {
height: 80rpx;
border-radius: 20rpx;
position: relative;
background-color: #fff;
}
2025-03-25 10:17:30 +08:00
2025-11-25 14:21:22 +08:00
.searchInput {
position: absolute;
left: 0;
right: 120rpx;
height: 80rpx;
icon {
position: absolute;
right: 20rpx;
top: 20rpx;
display: flex;
z-index: 9;
}
2025-03-25 10:17:30 +08:00
2025-11-25 14:21:22 +08:00
.voice {
display: flex;
justify-content: flex-end;
align-items: center;
position: absolute;
right: 20rpx;
top: 0;
bottom: 0;
width: 150rpx;
display: flex;
z-index: 9;
.mic {
margin-right: 10rpx;
2025-03-25 10:17:30 +08:00
}
}
}
2025-11-25 14:21:22 +08:00
.searchBtn {
position: absolute;
width: 120rpx;
right: 0px;
height: 80rpx;
line-height: 80rpx;
background: $maincolor;
border-radius: 0 20rpx 20rpx 0;
text-align: center;
2025-03-25 10:17:30 +08:00
color: #fff;
}
2025-11-25 14:21:22 +08:00
input {
height: 80rpx;
padding: 0 5px;
text-align: center;
position: absolute;
left: 0px;
right: 0px;
border-radius: 20rpx;
}
.icon {
width: 100rpx;
height: 80rpx;
position: absolute;
right: 30rpx;
display: flex;
align-items: center;
justify-content: center;
}
2025-03-25 10:17:30 +08:00
}
2025-11-25 14:21:22 +08:00
.content-box {
border-radius: 20rpx 20rpx 0 0;
2025-04-03 16:29:29 +08:00
position: relative;
2025-11-25 14:21:22 +08:00
z-index: 9;
width: 100%;
margin: 65px 0 30rpx;
background: #fff;
2023-09-08 15:17:21 +08:00
}
2025-11-25 14:21:22 +08:00
.search-history {
width: 100%;
height: auto;
overflow: hidden;
2023-09-08 15:17:21 +08:00
2025-11-25 14:21:22 +08:00
uni-icons {
color: #333333;
font-size: 60rpx;
position: absolute;
top: 13px;
right: 30rpx;
}
}
.history-list {
width: calc(100% - 40rpx);
margin: 20rpx 20rpx 0;
height: auto;
display: flex;
flex-wrap: wrap;
.history-list-item {
border: 1px solid #dfdfdf;
padding: 3px 24rpx;
border-radius: 20rpx;
margin-bottom: 20rpx;
margin-right: 20rpx;
}
}
.title {
width: 90%;
font-size: 30rpx;
font-weight: bold;
color: #000;
margin-top: 30rpx;
margin-left: 30rpx;
display: flex;
align-items: center;
}
.popular-container {
width: 100%;
margin-top: 30rpx;
2025-11-29 10:02:33 +08:00
margin-bottom: 120px;
2025-11-25 14:21:22 +08:00
.popular-food-item {
display: flex;
flex-direction: column;
align-items: center;
margin: 20rpx;
padding: 20rpx;
box-sizing: border-box;
border-radius: 20rpx;
background: linear-gradient(#EDFFF4, #ffffff 80%);
.food-title {
font-size: 34rpx;
font-weight: 700;
}
2023-09-08 15:17:21 +08:00
2025-11-25 14:21:22 +08:00
.popular-food-inner {
2023-09-08 15:17:21 +08:00
display: flex;
2025-11-25 14:21:22 +08:00
flex-wrap: wrap;
justify-content: flex-start;
width: 100%;
margin-top: 20rpx;
.popular-food-subitem {
display: flex;
align-items: center;
margin-bottom: 20rpx;
padding: 10rpx 20rpx;
background-color: #fff;
margin-right: 20rpx;
border-radius: 20rpx;
border: 1px solid #f7f7f7;
2023-09-08 15:17:21 +08:00
}
}
}
2025-11-25 14:21:22 +08:00
}
.search_list {
display: flex;
padding: 0 20rpx;
flex-wrap: wrap;
2025-11-29 10:02:33 +08:00
margin: 75px 20rpx 120px;
2025-11-25 14:21:22 +08:00
width: calc(100% - 80rpx);
justify-content: space-between;
background: #fff;
border-radius: 20rpx;
.search_list_item {
width: 100%;
display: flex;
align-items: center;
border-bottom: 1px solid #f7f7f7;
padding: 20rpx 0;
position: relative;
image {
width: 80rpx;
height: 80rpx;
margin-right: 20rpx;
border-radius: 20rpx;
}
text {
width: 100%;
display: inline-block;
}
.dui {
position: absolute;
right: 30rpx;
}
:nth-child(2) text {
margin-top: 5px;
}
}
}
.auto-search-dialog {
display: flex;
justify-content: center;
align-items: center;
position: fixed;
left: 0;
top: 0;
width: 100%;
2025-12-04 15:02:07 +08:00
bottom: 75px;
2025-11-25 14:21:22 +08:00
background-color: rgba(0, 0, 0, 0.5);
z-index: 999;
2023-09-08 15:17:21 +08:00
2025-11-25 14:21:22 +08:00
.auto-search-inner {
2023-09-08 15:17:21 +08:00
display: flex;
2025-11-25 14:21:22 +08:00
flex-direction: column;
2023-09-08 15:17:21 +08:00
justify-content: space-between;
2025-11-25 14:21:22 +08:00
align-items: center;
position: relative;
2025-12-04 15:02:07 +08:00
width: 50%;
padding: 60rpx 0;
2025-11-25 14:21:22 +08:00
background-color: #fff;
border-radius: 20rpx;
box-shadow: 0 0 20rpx #ccc;
}
}
2025-12-04 15:02:07 +08:00
2025-11-25 14:21:22 +08:00
.activeList {
z-index: 12;
2025-11-29 10:02:33 +08:00
bottom: 200rpx;
2023-09-08 15:17:21 +08:00
2025-11-25 14:21:22 +08:00
.box2 {
height: 500rpx;
background: #fff;
position: absolute;
width: 100%;
bottom: 70px;
2025-11-29 10:02:33 +08:00
padding-bottom: 120px;
2025-11-25 14:21:22 +08:00
border-radius: 20rpx 20rpx 0 0;
}
.list {
padding-bottom: 55px;
.name {
margin-right: 5px;
}
icon {
font-size: 22px;
}
}
}
.groupbtn {
display: flex;
align-items: center;
justify-content: space-between;
2025-12-04 15:02:07 +08:00
padding: 0 20rpx;
2025-11-25 14:21:22 +08:00
position: fixed;
2025-12-04 15:02:07 +08:00
bottom: 0rpx;
2025-11-25 14:21:22 +08:00
left: 0;
right: 0;
2025-12-04 15:02:07 +08:00
height: 60px;
padding-bottom: 15px;
z-index: 15;
2025-11-25 14:21:22 +08:00
background-color: #fff;
overflow: hidden;
box-shadow: 0px 1px 5px 2px #dfe2e1fc;
.subbtn {
color: #fff;
2025-11-29 10:02:33 +08:00
width: 60%;
2025-11-25 14:21:22 +08:00
text-align: center;
border-radius: 20rpx;
height: 35px;
line-height: 35px;
background-color: #f0ae43;
}
2025-12-04 15:02:07 +08:00
.jilu {
width: 110px;
2025-11-29 10:02:33 +08:00
display: flex;
align-items: center;
justify-content: space-between;
}
2025-11-25 14:21:22 +08:00
.che {
width: 120rpx;
height: 120rpx;
position: relative;
text {
position: absolute;
height: 30rpx;
background: red;
width: 30rpx;
border-radius: 50%;
display: inline-block;
2023-09-08 15:17:21 +08:00
color: #fff;
2025-11-25 14:21:22 +08:00
line-height: 30rpx;
text-align: center;
font-size: 24rpx;
right: 0;
top: 5px;
}
image,
.t-icon {
width: 120rpx;
height: 120rpx;
border-radius: 50%;
2023-09-08 15:17:21 +08:00
}
}
}
2025-11-25 14:21:22 +08:00
.btn {
color: #fff;
width: 60%;
margin: auto;
background-color: #f0ae43;
}
2025-11-29 10:02:33 +08:00
.mic-icon {
color: #fff;
2025-12-04 15:02:07 +08:00
width: calc(100% - 120px);
2025-11-29 10:02:33 +08:00
padding: 8px 0;
2025-12-04 15:02:07 +08:00
background: #3CB383;
2025-11-29 10:02:33 +08:00
display: flex;
align-items: center;
justify-content: center;
border-radius: 20rpx;
}
2025-11-25 14:21:22 +08:00
.button-container {
position: absolute;
top: 20rpx;
right: 30rpx;
font-size: 40rpx;
image {
width: 50rpx;
height: 50rpx;
2025-04-03 16:29:29 +08:00
}
2023-09-08 15:17:21 +08:00
}
2025-03-25 10:17:30 +08:00
</style>