kitchendDevice/pageTwo/count/food.vue

587 lines
13 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<view class="content">
<!-- 搜索 -->
<search @handleSearch="handleSearch"></search>
<view class="box menu">
<!-- 头部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菜单栏 -->
<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>
<!-- 右侧商品 -->
<view class="right">
<view class="right_list">
<view class="list mt-20">
<view class="item" v-for="(it,id) in menu3" :key="id" @click="handleDetail(it)">
<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">
<text>{{activeType.weight?activeType.weight:'0'}}</text>g
</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>
<blue-tooth @handleBle="handleBle" :weightType="'2'" :weightKcal="weightKcal"></blue-tooth>
</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,
leftInd: 0,
menu: [],
menu2: [],
menu3: [],
myvalue: [],
searchResults: [],
ActiveList: [],
activeType: {},
IsWeight: false,
isShop: false,
isBle: false,
weightKcal: "",
kcal: "",
weight: "",
stopblue: true,
isConnection: 0, //是否连接成功
};
},
computed: {
...mapState(["user", 'isConnected', "isBluetoothTyle", 'foodList']),
menuTop() {
this.menu2 = this.foodList.length ? this.foodList[0].list : []
return this.foodList
},
},
onLoad(options) {
let that = this
that.typename = options.name
that.typeind = options.ind
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()
}
},
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()
},
// 搜索
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 = []
}
},
// 商品选择
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
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
})
})
},
//删除购物车食材
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
that.weightKcal = that.activeType.kcal
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>
.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;
}
.right {
top: 90px !important;
.item {
width: 29%;
border: 1px solid #f7f7f7;
display: flex;
align-items: center;
box-sizing: border-box;
justify-content: space-around;
height: 30px;
border-radius: 5px;
margin: 0 2% 10px;
text {
margin-bottom: 0 !important;
}
}
.icon-xuanzhong {
color: $maincolor;
}
.active0 {
border: 1px solid $maincolor;
}
}
.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;
background-color: $maincolor;
}
.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;
}
</style>