kitchendDevice/pageTwo/count/food.vue

587 lines
13 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">
2025-03-25 10:17:30 +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>
<!-- 左侧2菜单栏 -->
2023-09-08 15:17:21 +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>
<!-- 右侧商品 -->
<view class="right">
2025-03-25 10:17:30 +08:00
<view class="right_list">
<view class="list mt-20">
<view class="item" v-for="(it,id) in menu3" :key="id" @click="handleDetail(it)">
2023-09-08 15:17:21 +08:00
<text>{{it.name}}</text>
</view>
</view>
</view>
</view>
</view>
<!-- 底部购物车 -->
<view class="groupbtn">
<view class="che" @click="isShop =! isShop">
<text v-if="ActiveList.length">{{ActiveList.length}}</text>
<!-- <image src="../../static/pan.png"></image> -->
<icon class="t-icon t-icon-canpan"></icon>
</view>
<view class="subbtn" @click="handlesubbtn"> 确定</view>
</view>
<!-- 购物车列表 -->
<view class="wrapper activeList" v-if="isShop">
<view class="bg" @click='isShop=false'>
<view class="box" @click.stop>
<view class="title">{{ActiveList.length}}条记录</view>
<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>
<text>{{ite.weight}}{{ite.unit}}</text>
</view>
<icon class="iconfont icon-ashbin" @click="handledelactive(ite)"></icon>
</view>
</view>
<view v-else class="nolist list">
<icon class="iconfont icon-wancan"></icon>
<text>还没有记录哦</text>
</view>
</view>
</view>
</view>
<!-- 称重区 -->
<view class="wrapper" v-if="IsWeight">
<view class="bg" @click='IsWeight=false'>
<view class="box" @click.stop>
<view class="title">
<view class="weight" @click="handleWeight()">
<icon class="iconfont icon-lianjie"></icon>
食物秤称重
</view>
<view class="cancel">
<icon class="iconfont icon-error" @click="Cancelword()"></icon>
</view>
</view>
<view class="name">{{activeType.name}}</view>
<view class="val">
2025-03-25 10:17:30 +08:00
<text>{{activeType.weight?activeType.weight:'0'}}</text>g
2023-09-08 15:17:21 +08:00
</view>
<view class="mybrankmask">
<view class="MymaskAll">
<view class="MymaskList">
<view class="maskListItem" @click="NumberCk(1)">1</view>
<view class="maskListItem" @click="NumberCk(2)">2</view>
<view class="maskListItem" @click="NumberCk(3)">3</view>
</view>
<view class="MymaskList">
<view class="maskListItem" @click="NumberCk(4)">4</view>
<view class="maskListItem" @click="NumberCk(5)">5</view>
<view class="maskListItem" @click="NumberCk(6)">6</view>
</view>
<view class="MymaskList">
<view class="maskListItem" @click="NumberCk(7)">7</view>
<view class="maskListItem" @click="NumberCk(8)">8</view>
<view class="maskListItem" @click="NumberCk(9)">9</view>
</view>
<view class="MymaskList">
<view class="maskListItem" @click="NumberCk('.')">.</view>
<view class="maskListItem" @click="NumberCk(0)">0</view>
<view class="maskListItem" @click="Cancelword()">
<image src="../../static/Clear.png"></image>
</view>
</view>
</view>
<view class="MymaskList MymaskList2">
<view class="maskListItem text" @click="Tuige()">
<image src="../../static/close.png" class="close"></image>
</view>
<view class="maskListItem text" @click="Clear()">清空</view>
<view class="maskListItem width48" @click="Next()">保存</view>
</view>
</view>
</view>
</view>
</view>
<!--蓝牙连接区 -->
<view class="wrapper" v-if="isBle">
<view class="bg" @click='isBle=false'>
<view class="box" @click.stop>
<view class="title">
<view class="name">{{activeType.name}}</view>
<icon class="iconfont icon-error" @click='isBle=false'></icon>
</view>
2025-04-02 09:49:39 +08:00
<blue-tooth @handleBle="handleBle" :weightType="'2'" :weightKcal="weightKcal"></blue-tooth>
2023-09-08 15:17:21 +08:00
</view>
</view>
</view>
</view>
</template>
<script>
import {
mapState
} from "vuex";
let myTime
const plugin = requirePlugin("sdkPlugin").AiLink;
import search from "../../components/search.vue"
import blueTooth from "../../components/bluetooth.vue"
export default {
components: {
search,
blueTooth
},
data() {
return {
typename: "",
typeind: 0,
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
myvalue: [],
2025-03-25 10:17:30 +08:00
searchResults: [],
2023-09-08 15:17:21 +08:00
ActiveList: [],
activeType: {},
IsWeight: false,
isShop: false,
isBle: false,
2025-04-02 09:49:39 +08:00
weightKcal: "",
2023-09-08 15:17:21 +08:00
kcal: "",
weight: "",
stopblue: true,
isConnection: 0, //是否连接成功
};
},
computed: {
2025-03-25 10:17:30 +08:00
...mapState(["user", 'isConnected', "isBluetoothTyle", 'foodList']),
menuTop() {
this.menu2 = this.foodList.length ? this.foodList[0].list : []
return this.foodList
},
2023-09-08 15:17:21 +08:00
},
onLoad(options) {
let that = this
that.typename = options.name
that.typeind = options.ind
2025-03-25 10:17:30 +08:00
that.handleHomeInfo()
},
onReachBottom() {
let that = this
if (!this.lastPage || this.page >= this.lastPage) {
uni.showToast({
title: '没有更多数据!',
icon: 'none'
})
return
}
this.page++
if (that.menu2.length) {
that.handleHomeInfo()
}
2023-09-08 15:17:21 +08:00
},
methods: {
2025-03-25 10:17:30 +08:00
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()
}
2023-09-08 15:17:21 +08:00
},
// 左侧切换
2025-03-25 10:17:30 +08:00
handleToggleLeft(ind) {
2023-09-08 15:17:21 +08:00
let that = this
2025-03-25 10:17:30 +08:00
that.leftInd = ind
that.menu3 = []
that.page = 1
that.handleHomeInfo()
},
// 搜索
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 = []
}
2023-09-08 15:17:21 +08:00
},
// 商品选择
handleDetail(ite) {
var that = this;
that.myvalue = []
that.activeType = ite
that.activeType.weight = 100
that.IsWeight = true
that.isShop = false
console.log("选中的商品", ite)
},
// 购物车提交
handlesubbtn() {
let that = this
2025-03-25 10:17:30 +08:00
that.$model.getAddIntakeFood({
aud_id: that.user.aud_id,
meals_type: that.typename,
food_list: that.ActiveList
}).then(res => {
if (res.code != 0) return
uni.navigateBack({
delta: 1
})
2023-09-08 15:17:21 +08:00
})
},
//删除购物车食材
handledelactive(ite) {
let that = this
that.ActiveList.splice(that.ActiveList.indexOf(ite), 1);
},
// 键盘点击
NumberCk(val) {
let that = this
that.myvalue = that.myvalue[0] == '.' ? [0, '.'].concat(val) : that.myvalue.concat(val)
if (that.myvalue.toString().indexOf('.') != -1) {
let ind = that.myvalue.indexOf(".")
that.myvalue = that.myvalue.slice(0, ind + 2)
}
if (that.myvalue.toString().indexOf('.') == -1 && that.myvalue.length > 3) {
that.myvalue = ["9", "9", "9"]
}
that.activeType.weight = that.myvalue.join("")
},
// 键盘退格
Tuige() {
let that = this
var txt = that.myvalue
if (txt.length >= 1) {
if (txt[txt.length - 2] != '.') {
that.myvalue = txt.slice(0, txt.length - 1)
} else {
that.myvalue = txt.slice(0, txt.length - 2)
}
}
that.activeType.weight = that.myvalue.join("")
// console.log("退格1", txt, that.myvalue.join(""))
},
// 键盘取消
Cancelword() {
this.IsWeight = false
this.myvalue = []
this.activeType = {}
// console.log("取消")
},
// 键盘清空
Clear() {
this.myvalue = []
this.activeType.weight = null
// console.log("清空")
},
// 键盘保存
Next() {
let that = this
let ite = that.activeType
that.IsWeight = false
if (that.ActiveList.indexOf(ite) == -1) {
that.ActiveList.push(ite);
} else {
let index = that.ActiveList.indexOf(ite)
that.ActiveList[index].weight = that.activeType.weight;
that.ActiveList[index].unit = that.activeType.unit;
}
console.log("保存", that.ActiveList)
},
// 称重
handleWeight() {
let that = this
2025-04-02 09:49:39 +08:00
that.weightKcal = that.activeType.kcal
2023-09-08 15:17:21 +08:00
that.isBle = true
that.IsWeight = false
},
//称重返回
handleBle(weight, unit, kcal) {
let that = this
that.isBle = false
that.activeType.weight = weight
that.activeType.unit = unit
that.Next()
console.log("返回", that.activeType, weight, unit, kcal)
}
}
}
</script>
<style lang="scss" scoped>
2025-03-25 10:17:30 +08:00
.tab_list {
display: flex;
margin: 45px -10px 0;
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;
}
}
.left {
top: 90px !important;
}
2023-09-08 15:17:21 +08:00
.right {
2025-03-25 10:17:30 +08:00
top: 90px !important;
2023-09-08 15:17:21 +08:00
.item {
2025-03-25 10:17:30 +08:00
width: 29%;
2023-09-08 15:17:21 +08:00
border: 1px solid #f7f7f7;
display: flex;
align-items: center;
2025-03-25 10:17:30 +08:00
box-sizing: border-box;
2023-09-08 15:17:21 +08:00
justify-content: space-around;
2025-03-25 10:17:30 +08:00
height: 30px;
border-radius: 5px;
margin: 0 2% 10px;
2023-09-08 15:17:21 +08:00
text {
margin-bottom: 0 !important;
}
}
.icon-xuanzhong {
2025-03-25 10:17:30 +08:00
color: $maincolor;
2023-09-08 15:17:21 +08:00
}
.active0 {
2025-03-25 10:17:30 +08:00
border: 1px solid $maincolor;
2023-09-08 15:17:21 +08:00
}
}
.weightPages {
display: flex;
flex-wrap: wrap;
flex-direction: column;
position: absolute;
left: 0;
right: 0;
bottom: 20px;
top: 60px;
justify-content: space-around;
.weight {
background: #fff;
color: #666;
font-size: 16px;
flex-wrap: wrap;
text-align: center;
view {
width: 60%;
height: 50px;
display: flex;
margin-left: 25%;
align-items: flex-end;
margin-bottom: 15px;
text {
width: 80px;
display: inline-block;
border-bottom: 1px solid #dfdfdf;
margin: 0 10px;
font-size: 18px;
font-weight: bold;
color: #f0ae43;
}
}
}
.tips {
font-size: 12px;
text-align: center;
}
.btn {
color: #fff;
width: 80%;
margin-left: 10%;
}
.table {
width: 100%;
font-size: 16px;
font-weight: bold;
text-align: center;
margin: 15px 0;
}
.image {
width: 160px;
height: 160px;
margin: auto;
image {
width: 100%;
height: 100%;
}
}
.tips {
margin-bottom: 15px;
margin-left: 15px;
display: flex;
color: #999;
}
}
.groupbtn {
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 10px;
position: absolute;
bottom: 0;
left: 0;
right: 0;
height: 55px;
z-index: 15;
background-color: #fff;
overflow: hidden;
box-shadow: 0px 1px 5px 2px #dfe2e1fc;
.subbtn {
color: #fff;
width: 40%;
text-align: center;
border-radius: 10px;
height: 31px;
line-height: 31px;
2025-03-25 10:17:30 +08:00
background-color: $maincolor;
2023-09-08 15:17:21 +08:00
}
.che {
width: 50px;
height: 40px;
position: relative;
text {
position: absolute;
height: 15px;
background: red;
width: 15px;
border-radius: 50%;
display: inline-block;
color: #fff;
line-height: 15px;
text-align: center;
font-size: 12px;
right: 0;
top: 5px;
}
image,
.t-icon {
width: 50px;
height: 50px;
margin-top: -3px;
border-radius: 50%;
}
}
}
.menu {
.left {
bottom: 55px;
height: calc(100vh - 120px);
}
.right {
bottom: 55px;
height: calc(100vh - 120px);
}
}
.activeList {
z-index: 12;
bottom: 50px;
.title {
font-weight: bold;
margin: 5px 0;
}
.list {
padding-bottom: 55px;
.name {
margin-right: 5px;
}
}
}
.icon-error {
font-size: 45px;
margin-top: -30px;
background: #fff;
border-radius: 50%;
width: 45px;
height: 45px;
}
2025-03-25 10:17:30 +08:00
</style>