1321 lines
37 KiB
Vue
1321 lines
37 KiB
Vue
<template>
|
||
<view class="content">
|
||
<!-- 搜索 -->
|
||
<search ref="search" :voice="true" @handleSearch="handleSearch" @mic="onShowSearchType(1)"
|
||
@camera="onShowSearchType(2)"></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> -->
|
||
<food-item :foodList="menu3" @scroll="onScrollBottom" @select="handleDetail"></food-item>
|
||
<view v-if="!menu3.length" class="nolist">
|
||
<icon class="iconfont icon-wancan"></icon>
|
||
<text>还没有数据哦!</text>
|
||
</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>
|
||
<uni-drawer ref="showRight" mode="right" width="300" @change="FoodDetailChange">
|
||
<scroll-view style="height: 100%;" scroll-y="true">
|
||
<view class="foodDetail">
|
||
<view class="foodInfo">
|
||
<image :src="activeFoodDetail.pic_url" mode="aspectFill"></image>
|
||
<view class="info">
|
||
<view class="name">{{activeFoodDetail.name}}</view>
|
||
<view class="kcal">{{Number(activeType.kcal*activeType.weight/100).toFixed(1)}}千卡</view>
|
||
</view>
|
||
</view>
|
||
<view class="foodContent">
|
||
<view class="title">热量和营养</view>
|
||
<view class="progress">
|
||
<div class="chart-wrap">
|
||
<qiun-data-charts type="ring" :opts="opts" :canvas2d="true" canvasId="foodCharts" :chartData="chartData" :cHeight="250"
|
||
:cWidth="250" />
|
||
<view class="uchart-kcal">{{Math.floor(activeType.kcal*activeType.weight/100)}}</view>
|
||
</div>
|
||
<view class="info" v-if="activeType.nutrients_four">
|
||
<view class="info-item" v-for="(item,index) in activeType.nutrients_four.slice(1)" :key="index">
|
||
<view class="color" :style="{'background-color':`${item.color}`}"></view>
|
||
<view>{{item.name}}:{{item.proportion}}%</view>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
<view class="tips">
|
||
<text>营养素</text>
|
||
<text>{{activeType.weight}}克含量</text>
|
||
</view>
|
||
<view class="foodDetailList">
|
||
<view class="foodDetailItem" v-for="(item,index) in activeFoodDetail.nutrients_list" :key="index">
|
||
<view class="name">{{item.name_ch}}</view>
|
||
<view class="value">{{Number(item.value*activeType.weight/100).toFixed(2)}}{{item.unit}}</view>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
</scroll-view>
|
||
</uni-drawer>
|
||
<!-- 称重区 -->
|
||
<view class="wrapper" v-if="IsWeight && !IsFoodDetail">
|
||
<view class="bg" @click='IsWeight=false'>
|
||
<view class="box" @click.stop>
|
||
<view class="title">
|
||
<view class="cancel">
|
||
<icon class="iconfont icon-error" @click="Cancelword()"></icon>
|
||
</view>
|
||
</view>
|
||
<view class="foodItem" @click="showFoodDetail(activeType)">
|
||
<view class="left">
|
||
<image :src="activeType.pic_url" mode="aspectFill"></image>
|
||
<view class="info">
|
||
<view class="name">{{activeType.name}}</view>
|
||
<view class="kcal">{{activeType.kcal}}千卡/100克</view>
|
||
</view>
|
||
</view>
|
||
<view class="more">查看</view>
|
||
</view>
|
||
<view class="foodInfo">
|
||
<view class="foodInfoItem" v-for="(item,index) in activeType.nutrients_four" :key="index">
|
||
<view class="name">
|
||
<view class="color" :style="{'background-color':item.color}" v-if="item.color != ''"></view>
|
||
<text>{{item.name}}({{unitConversion(item.unit)}})</text>
|
||
</view>
|
||
<view class="value">{{ Number(activeType.weight/100 * item.value).toFixed(1) }}</view>
|
||
</view>
|
||
</view>
|
||
<view class="weight" @click="handleWeight()">
|
||
<image class="chengIcon" src="../../static/chengIcon.png" mode="widthFix"></image>
|
||
</view>
|
||
<!-- <view class="name">{{activeType.name}}</view> -->
|
||
<view class="val">
|
||
<text>{{activeType.weight?Number(activeType.weight).toFixed(1):'0'}}</text>克
|
||
</view>
|
||
<view class="mybrankmask" v-if="wordType == 1">
|
||
<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>
|
||
<!-- <image class="rulerIcon" src="../../static/ruler.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 class="rulerWrap" v-else>
|
||
<ruler ref="ruler" :min="0" :max="1000" :disable="false" :multiple="1" :point="0" :defaultValue="activeType.weight"
|
||
@change="rulerChange"></ruler>
|
||
<view class="rulerBtn">
|
||
<image src="../../static/keybord.png" @click="Changeword()"></image>
|
||
<view class="confirm" @click="Next()">保存</view>
|
||
</view>
|
||
</view> -->
|
||
</view>
|
||
</view>
|
||
</view>
|
||
<!--蓝牙连接区 -->
|
||
<view id="wrapper" class="wrapper" v-show="isBle && !IsFoodDetail">
|
||
<view class="bg" @click='isBle=false'>
|
||
<view class="box" @click.stop>
|
||
<view class="title">
|
||
<icon class="iconfont icon-error" @click='isBle=false'></icon>
|
||
</view>
|
||
<view class="foodItem" @click="showFoodDetail(activeType)">
|
||
<view class="left">
|
||
<image :src="activeType.pic_url" mode="aspectFill"></image>
|
||
<view class="info">
|
||
<view class="name">{{activeType.name}}</view>
|
||
<view class="kcal">{{activeType.kcal}}千卡/100克</view>
|
||
</view>
|
||
</view>
|
||
<view class="more">查看</view>
|
||
</view>
|
||
<view class="foodInfo">
|
||
<view class="foodInfoItem" v-for="(item,index) in activeType.nutrients_four" :key="index">
|
||
<view class="name">
|
||
<view class="color" :style="{'background-color':item.color}" v-if="item.color != ''"></view>
|
||
<text>{{item.name}}({{unitConversion(item.unit)}})</text>
|
||
</view>
|
||
<view class="value">{{ Number(activeType.weight/100 * item.value).toFixed(1) }}</view>
|
||
</view>
|
||
</view>
|
||
<view class="weight" @click="handleMannulWeight()">
|
||
<image class="keybordIcon" src="../../static/keybordIcon.png" mode="widthFix"></image>
|
||
</view>
|
||
<view class="blue-tooth">
|
||
<blue-tooth @handleBle="handleBle" :weightType="'2'" :weightKcal="weightKcal" @realTimeWeight="realTimeWeight"></blue-tooth>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
<view class="auto-search-dialog" v-if="showAutoSearchDlg">
|
||
<view class="auto-search-inner">
|
||
<text>{{autoSearchContent != '' ? `识别到你描述的食材为“${autoSearchContent}”,是否查找食材“${autoSearchContent}”` : "长安麦克风图标开始说话,松开后结束"}}</text>
|
||
<view class="mic-icon" :style="{'border-color':mic_touch ? '#18bc37' : '#777777'}"
|
||
@touchstart="onVoiceTouchStart" @touchend="onVoiceTouchEnd"
|
||
v-if=" autoSearchType == 1 && autoSearchContent == ''">
|
||
<uni-icons type="mic-filled" size="80" :color="mic_touch ? '#18bc37' : '#777777'"></uni-icons>
|
||
</view>
|
||
<view class="btn-wrap" v-else>
|
||
<view class="retry" @click="retrySearch">重试</view>
|
||
<view class="confirm" @click="handleVoiceSearch(autoSearchContent)">确定</view>
|
||
</view>
|
||
<uni-icons class="close" type="close" color="#ffffff" size="45" @click="showAutoSearchDlg=false"></uni-icons>
|
||
</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_food.vue"
|
||
import FoodItem from "../../components/food_item.vue"
|
||
// import ruler from "../../components/select-ruler/select-ruler.vue"
|
||
import qiunDataCharts from '@/uni_modules/qiun-data-charts/components/qiun-data-charts.vue';
|
||
const plugin = requirePlugin("WechatSI")
|
||
export default {
|
||
components: {
|
||
search,
|
||
blueTooth,
|
||
FoodItem,
|
||
qiunDataCharts,
|
||
// ruler
|
||
},
|
||
data() {
|
||
return {
|
||
typename: "",
|
||
typeind: 0,
|
||
index: 0,
|
||
leftInd: 0,
|
||
menu: [],
|
||
menu2: [],
|
||
menu3: [],
|
||
myvalue: [],
|
||
searchResults: [],
|
||
ActiveList: [],
|
||
activeType: {},
|
||
IsWeight: false,
|
||
isShop: false,
|
||
isBle: false,
|
||
IsFoodDetail: false,
|
||
weightKcal: "",
|
||
kcal: "",
|
||
weight: "",
|
||
stopblue: true,
|
||
page: 1,
|
||
loading: false,
|
||
autoSearchType: 1, //搜索类型,1:语音识别 2:图像识别
|
||
voiceManager: null,
|
||
autoSearchContent: '',
|
||
isConnection: 0, //是否连接成功
|
||
showAutoSearchDlg: false,
|
||
mic_touch: false,
|
||
activeFoodDetail: {},
|
||
wordType: 1,
|
||
chartData: {},
|
||
opts: {
|
||
dataLabel: false,
|
||
color: ["#5180D8","#ED7886","#FFB169"],
|
||
background: "transparent",
|
||
canvas: {
|
||
background: "transparent"
|
||
},
|
||
legend: {
|
||
show: false // 这个设置将隐藏图例
|
||
},
|
||
title: {
|
||
name: "",
|
||
fontSize: 20,
|
||
offsetY: -3,
|
||
color: "#333333"
|
||
},
|
||
subtitle: {
|
||
name: "千卡",
|
||
fontSize: 14,
|
||
offsetY: 12,
|
||
color: "#888888"
|
||
},
|
||
extra: {
|
||
ring: {
|
||
ringWidth: 10,
|
||
labelWidth: 0,
|
||
border: false,
|
||
// customRadius: 50
|
||
}
|
||
}
|
||
},
|
||
};
|
||
},
|
||
watch: {
|
||
activeType: {
|
||
handler(newVal, oldVal) {
|
||
console.log(newVal)
|
||
},
|
||
deep: true
|
||
}
|
||
},
|
||
computed: {
|
||
...mapState(["user", 'isConnected', "isBluetoothTyle", 'foodList']),
|
||
menuTop() {
|
||
this.menu2 = this.foodList.length ? this.foodList[0].list : []
|
||
return [...this.foodList, {
|
||
id: 4,
|
||
list: [],
|
||
name: '搜索'
|
||
}]
|
||
},
|
||
getKcal() {
|
||
if(this.activeFoodDetail) {
|
||
return this.activeFoodDetail.kcal
|
||
}
|
||
return 0
|
||
}
|
||
},
|
||
onLoad(options) {
|
||
let that = this
|
||
that.typename = options.name
|
||
that.typeind = options.ind
|
||
that.handleHomeInfo()
|
||
},
|
||
mounted() {
|
||
let that = this
|
||
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)
|
||
}
|
||
that.voiceManager.stop()
|
||
},
|
||
methods: {
|
||
showFoodDetail(item) {
|
||
this.activeFoodDetail = item
|
||
this.$refs.showRight.open();
|
||
this.IsFoodDetail = true
|
||
let chart_data = []
|
||
this.opts.color = []
|
||
|
||
// if(this.activeType.weight == '') {
|
||
// this.opts.title.name = '0'
|
||
// }else {
|
||
// this.opts.title.name = Math.floor(item.kcal * this.activeType.weight/100)
|
||
// }
|
||
|
||
for (let i = 1; i < item.nutrients_four.length; ++i) {
|
||
this.opts.color.push(item.nutrients_four[i].color)
|
||
chart_data.push({
|
||
name: item.nutrients_four[i].name,
|
||
value: Number(item.nutrients_four[i].proportion),
|
||
})
|
||
}
|
||
|
||
this.chartData = JSON.parse(JSON.stringify({
|
||
series: [{
|
||
data: chart_data
|
||
}]
|
||
}));
|
||
},
|
||
getKcal() {
|
||
this.opts.title.name = this.activeFoodDetail.nutrients_four[0].value * this.activeType.weight
|
||
},
|
||
FoodDetailChange(show) {
|
||
this.IsFoodDetail = show
|
||
},
|
||
handleHomeInfo() {
|
||
let that = this
|
||
that.loading = true
|
||
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.loading = false
|
||
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()
|
||
},
|
||
onScrollBottom() {
|
||
let that = this
|
||
if (!this.lastPage || this.page >= this.lastPage) {
|
||
uni.showToast({
|
||
title: '没有更多数据!',
|
||
icon: 'none'
|
||
})
|
||
return
|
||
}
|
||
this.page++
|
||
if (that.menu2.length) {
|
||
that.handleHomeInfo()
|
||
}
|
||
},
|
||
// 搜索
|
||
handleSearch(name) {
|
||
let that = this
|
||
let list = []
|
||
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
|
||
})
|
||
},
|
||
handleVoiceSearch() {
|
||
let that = this
|
||
if (that.autoSearchContent != '') {
|
||
that.$refs.search.searchByName(that.autoSearchContent)
|
||
that.showAutoSearchDlg = false
|
||
that.autoSearchContent = ''
|
||
}
|
||
},
|
||
// 商品选择
|
||
handleDetail(ite) {
|
||
var that = this;
|
||
that.myvalue = []
|
||
that.activeType = ite
|
||
that.activeType.weight = 0
|
||
// that.IsWeight = true
|
||
that.weightKcal = that.activeType.kcal
|
||
that.isShop = false
|
||
that.isBle = true
|
||
console.log("选中的商品", ite)
|
||
},
|
||
// 购物车提交
|
||
handlesubbtn() {
|
||
let that = this
|
||
|
||
if (that.ActiveList.length <= 0) return
|
||
|
||
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("取消")
|
||
},
|
||
//切换键盘
|
||
Changeword() {
|
||
this.wordType = this.wordType == 1 ? 2 : 1
|
||
},
|
||
// 键盘清空
|
||
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)
|
||
},
|
||
rulerChange(val) {
|
||
this.activeType = Object.assign({}, this.activeType, { weight: val })
|
||
},
|
||
// 称重
|
||
handleWeight() {
|
||
let that = this
|
||
that.weightKcal = that.activeType.kcal
|
||
that.isBle = true
|
||
that.IsWeight = false
|
||
},
|
||
// 手动称重
|
||
handleMannulWeight() {
|
||
let that = this
|
||
that.isBle = false
|
||
that.IsWeight = true
|
||
},
|
||
//称重返回
|
||
handleBle(weight, unit, kcal) {
|
||
let that = this
|
||
that.isBle = false
|
||
that.activeType.weight = weight
|
||
that.activeType.unit = unit
|
||
that.activeType.kcal = kcal
|
||
that.Next()
|
||
console.log("返回", that.activeType, weight, unit, kcal)
|
||
},
|
||
//实时重量
|
||
realTimeWeight(weight,unit) {
|
||
if(!this.IsWeight) {
|
||
this.activeType = Object.assign({}, this.activeType, { weight: this.convertToGrams(weight,unit) })
|
||
}
|
||
},
|
||
onShowSearchType(type) {
|
||
let that = this
|
||
this.autoSearchType = type
|
||
|
||
if (type == 1) {
|
||
that.showAutoSearchDlg = true
|
||
} else if (type == 2) {
|
||
that.selectPhoto()
|
||
}
|
||
},
|
||
retrySearch() {
|
||
let that = this
|
||
that.autoSearchContent = ''
|
||
if (that.autoSearchType == 2) {
|
||
that.showAutoSearchDlg = false
|
||
that.selectPhoto()
|
||
}
|
||
},
|
||
selectPhoto() {
|
||
let that = this
|
||
uni.chooseMedia({
|
||
count: 1,
|
||
mediaType: ['image'],
|
||
sourceType: ['album', 'camera'],
|
||
sizeType: ['compressed'],
|
||
camera: 'back',
|
||
success(res) {
|
||
const tempFilePath = res.tempFiles[0].tempFilePath
|
||
uni.getFileSystemManager().readFile({
|
||
filePath: tempFilePath,
|
||
encoding: 'base64',
|
||
success: (res) => {
|
||
const base64 = 'data:image/jpeg;base64,' + res.data
|
||
|
||
uni.showLoading({
|
||
title: '图片识别中...',
|
||
mask: true
|
||
})
|
||
|
||
that.$model.getPhotoSearch({
|
||
img_str: base64,
|
||
}).then(res => {
|
||
uni.hideLoading()
|
||
if (res.code != 0) return
|
||
that.autoSearchContent = res.data.name
|
||
that.showAutoSearchDlg = true
|
||
})
|
||
},
|
||
fail: (err) => {
|
||
console.error('读取文件失败:', err)
|
||
}
|
||
})
|
||
},
|
||
fail(err) {
|
||
console.error('拍照失败:', err)
|
||
}
|
||
})
|
||
},
|
||
onVoiceTouchStart() {
|
||
let that = this
|
||
that.mic_touch = true
|
||
that.voiceManager.start({
|
||
duration: 60000,
|
||
lang: "zh_CN"
|
||
})
|
||
},
|
||
onVoiceTouchEnd() {
|
||
let that = this
|
||
that.mic_touch = false
|
||
that.voiceManager.stop()
|
||
},
|
||
unitConversion(unit) {
|
||
if (unit == 'kcal') {
|
||
return '千卡'
|
||
} else if (unit == 'g') {
|
||
return '克'
|
||
}
|
||
return unit
|
||
},
|
||
convertToGrams(value, fromUnit) {
|
||
const conversionFactors = {
|
||
'lb': 453.59237, // 1磅 = 453.59237克
|
||
'oz': 28.349523125, // 1盎司 = 28.349523125克
|
||
'kg': 1000, // 1公斤 = 1000克
|
||
'g': 1
|
||
};
|
||
|
||
if (!conversionFactors.hasOwnProperty(fromUnit)) {
|
||
return ''
|
||
}
|
||
|
||
return value * conversionFactors[fromUnit];
|
||
}
|
||
}
|
||
}
|
||
</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;
|
||
|
||
.list {
|
||
display: block !important;
|
||
column-count: 3;
|
||
/* 分成两列 */
|
||
column-gap: 10px;
|
||
/* 列间距 */
|
||
}
|
||
|
||
.item {
|
||
break-inside: avoid;
|
||
/* 防止元素被分割到不同列 */
|
||
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;
|
||
box-shadow: 0 0 10rpx #e1e1e1;
|
||
|
||
text {
|
||
margin-bottom: 0 !important;
|
||
padding: 10rpx;
|
||
}
|
||
}
|
||
|
||
.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 - 150px);
|
||
}
|
||
|
||
.right {
|
||
bottom: 55px;
|
||
height: calc(100vh - 150px);
|
||
|
||
}
|
||
|
||
}
|
||
|
||
.activeList {
|
||
z-index: 12;
|
||
bottom: 50px;
|
||
|
||
.title {
|
||
font-weight: bold;
|
||
margin: 5px 0;
|
||
}
|
||
|
||
.list {
|
||
padding-bottom: 55px;
|
||
|
||
.name {
|
||
margin-right: 5px;
|
||
}
|
||
|
||
|
||
}
|
||
}
|
||
|
||
.voice-photo-wrap {
|
||
display: flex;
|
||
flex-direction: column;
|
||
justify-content: space-between;
|
||
position: fixed;
|
||
bottom: 200rpx;
|
||
right: 0;
|
||
width: 70rpx;
|
||
height: 160rpx;
|
||
|
||
.voice {
|
||
border-radius: 35rpx;
|
||
background-color: #70a1ff;
|
||
|
||
.voice-icon {
|
||
width: 70rpx;
|
||
height: 70rpx;
|
||
background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAMAAABHPGVmAAAAY1BMVEUAAAD+/v7+/v7////////+/v7////////+/v7////+/v7////+/v7////+/v7+/v7////+/v7////+/v7+/v7////+/v7+/v7////+/v7+/v7////+/v7+/v7+/v7///////8gTHxJAAAAIHRSTlMAkL8QIPcwoLAI32DXUO9IKMd4p5iIaOcYt1hAOM9wgPxxuZIAAAMsSURBVGje7djpcqQgEADg9kDF0fF2PMd+/6dcYRajwTERsTab8vsTClPVabqJCFwuP0TVpIaXGWlTwUms0iQomCmFEzzvuHB/ag/j+CgJHNCqEWn0tevWAfmbTAQa3ZBLykqUJ0EuBW0iZPxmPhe+1k9bLvGdp2EtZ62azZIY9OBL48rzLi8S1VeQBGSU51KCBtRn9bBghf1gj3SkEvI/dyPJEI7L2LaDNwJercMoa60B3ijYljy+Xh2OnM2nnZaSEHiL5dnAUU+pJFJRnqBAWnVze6MacJSxHcTUFiQIRw6FpZbN9pqCCJm0fxjNQdCez9t4ShBizectckaQxw0Wygef/r+66wryI4JYqfsSsMYaf+aRdFAyxmnWYr37ktLdJxTJ7fM7QFLvTARlOSzkKLOOBZEzafQEMb2Rz2rCBqV0VMnGWfZm9NljUzGIs6e7nCvI7wtC/FEfwUKUsFlyOMjWm5ES5DQHwRhmYtQfRP4OqjUH6W+jEJZoyGYDbUG8s7ur+LqFCzbo9gcBHIV7TvURjmAfIj4Um+3vEyK+T0r+e/v4YhlaqXmlRm7FsvqwjylehRbZukIZpr8/57XbQXTutB96ulGSbBoZKtcQ9jQqYVWJoiSxGO1RTatkvb92oP70KN3dwSJ98yOpbC1K/XG+MHmn73WbuooGbDjQ9a+KQHQZT1xlvTw+bMlaLtRls8QBxmNDG3bLxWWDuB1MWphpg9lhrEPFO5aYfPx7L5CrQ5FNVCNXzA61NijIZ+tcivvTOi+GzCTLQ+XzdYpVYZPZTWZ7R8kjEvegoiIKbvObTKsguEAGa34P+gRFHo78WPRb4c+yMCqRcCBuEtRYwd9VEZw0z5LEM0obhI7nEVigzPbxi6V4vvohhgPiBzLem6ra3iuGA4fYJnL5SpjKQK634SCaIUfckC7mo5wgl1lw3CB69+6lTVdRGndhapKpk0ELOyO4QlRLlzbBVWYLOjliJ873owPadYPXi3ULvKKD07T8oEXhVPbKm+MKcgW5gvyKIHZqfOby16Q0PcSgqLrjt/kVqIlwh1A1E4LfRpTrFHnmN7kRXC7/xB8ZerD103/W/wAAAABJRU5ErkJggg==);
|
||
background-size: cover;
|
||
}
|
||
}
|
||
|
||
.photo {
|
||
border-radius: 35rpx;
|
||
background-color: #ffbe76;
|
||
|
||
.photo-icon {
|
||
width: 70rpx;
|
||
height: 70rpx;
|
||
background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAMAAABHPGVmAAAAXVBMVEUAAAD////////////+/v7////////+/v7+/v7////////////////+/v7+/v7+/v7////+/v7+/v7+/v7+/v7////+/v7+/v7+/v7+/v7+/v7+/v7////+/v7///9dayJ/AAAAHnRSTlMAoDBf71BA3/eACCWI18+/eDjHso8Q56dYl2hHGG/EjhawAAABlUlEQVRo3u2W23KDIBBAEUERvF8ac+P/P7MVWiYDmk7o8tDMnrddlxydNe4SBEEQBEGQpFTZIfV2nbvwEi8R+hCxbDfhwizaUegnFECS/pmkApJ0zyQTgMS1RJQBbMt/fBXcXaqOdQx6wz/uHoCSl1mKgNo12INbexEgf5FQfcDOQakPoJGSca+4BZbMe8VnYAnfK+bAErVXfPuT5Mx99quv3GN+QZKTSHKUvKvkNtBbWsl6YuazP63JJNdSOxqeRjIHcxdekmmPE7yk1wE1tGT46UW1rlWrDWIAlnT2Z+0FmQsTdrCSwTrc6cJaKJzEdaQnjrvtCqikMyuWJA7JzOQHlZTBOzsZLahEBMvEbJoEKvkIFt0zvKTZsu1jZjQZUMnp+w12KLvEg0q4/+ebTOICKlmYvXNpQ5mZkC2gElI9jBHJR/e1B5XIUltYOzJtKRdgCVFMezAKP7SupecYUoxf1Tw6WpVmkZAX9zBNnm4lkqrPpi7r6TtskChByX+QsFjEC5J4UAIvURkAiiAIgiAIggDxCa/TqV5BIswVAAAAAElFTkSuQmCC);
|
||
background-size: cover;
|
||
}
|
||
}
|
||
}
|
||
|
||
.auto-search-dialog {
|
||
display: flex;
|
||
justify-content: center;
|
||
align-items: center;
|
||
position: fixed;
|
||
left: 0;
|
||
top: 0;
|
||
width: 100%;
|
||
height: 100%;
|
||
background-color: rgba(0, 0, 0, 0.5);
|
||
z-index: 999;
|
||
|
||
.auto-search-inner {
|
||
display: flex;
|
||
flex-direction: column;
|
||
justify-content: space-between;
|
||
align-items: center;
|
||
position: relative;
|
||
width: 70%;
|
||
height: 350rpx;
|
||
padding: 80rpx 0;
|
||
background-color: #fff;
|
||
border-radius: 20rpx;
|
||
box-shadow: 0 0 20rpx #ccc;
|
||
|
||
.close {
|
||
position: absolute;
|
||
left: 0;
|
||
right: 0;
|
||
bottom: -140rpx;
|
||
width: 90rpx;
|
||
margin: 0 auto;
|
||
}
|
||
}
|
||
|
||
text {
|
||
font-size: 32rpx;
|
||
width: 80%;
|
||
}
|
||
|
||
.mic-icon {
|
||
display: flex;
|
||
justify-content: center;
|
||
align-items: center;
|
||
width: 150rpx;
|
||
height: 150rpx;
|
||
border-radius: 50%;
|
||
border: 8rpx solid #777777;
|
||
}
|
||
|
||
.btn-wrap {
|
||
display: flex;
|
||
justify-content: space-around;
|
||
width: 90%;
|
||
|
||
.retry,
|
||
.confirm {
|
||
width: 190rpx;
|
||
height: 60rpx;
|
||
line-height: 60rpx;
|
||
text-align: center;
|
||
font-size: 28rpx;
|
||
border: 2rpx solid #777;
|
||
border-radius: 15rpx;
|
||
}
|
||
}
|
||
}
|
||
|
||
.foodDetail {
|
||
background-color: #F7F7F7;
|
||
padding: 20rpx;
|
||
box-sizing: border-box;
|
||
|
||
.foodInfo {
|
||
display: flex;
|
||
width: 100%;
|
||
padding: 30rpx;
|
||
border-radius: 20rpx;
|
||
box-sizing: border-box;
|
||
background-color: #fff;
|
||
box-sizing: 0 0 20rpx #f1f1f1;
|
||
|
||
image {
|
||
width: 90rpx;
|
||
height: 90rpx;
|
||
border-radius: 15rpx;
|
||
}
|
||
|
||
.info {
|
||
display: flex;
|
||
flex-direction: column;
|
||
justify-content: center;
|
||
margin-left: 30rpx;
|
||
|
||
.name {
|
||
font-size: 28rpx;
|
||
font-weight: 700;
|
||
margin-bottom: 10rpx;
|
||
}
|
||
|
||
.kcal {
|
||
font-size: 24rpx;
|
||
color: #666;
|
||
}
|
||
}
|
||
}
|
||
|
||
.foodContent {
|
||
width: 100%;
|
||
padding: 30rpx;
|
||
margin-top: 16rpx;
|
||
box-sizing: border-box;
|
||
border-radius: 20rpx;
|
||
box-sizing: border-box;
|
||
background-color: #fff;
|
||
box-sizing: 0 0 20rpx #f1f1f1;
|
||
|
||
.title {
|
||
font-size: 28rpx;
|
||
font-weight: 600;
|
||
}
|
||
|
||
.progress {
|
||
display: flex;
|
||
align-items: center;
|
||
|
||
.chart-wrap {
|
||
position: relative;
|
||
width: 250rpx;
|
||
height: 250rpx;
|
||
margin-top: -30rpx;
|
||
.uchart-kcal {
|
||
position: absolute;
|
||
left: 60rpx;
|
||
top: 120rpx;
|
||
width: 130rpx;
|
||
font-size: 40rpx;
|
||
text-align: center;
|
||
z-index: 9;
|
||
}
|
||
}
|
||
|
||
.info {
|
||
display: flex;
|
||
flex-direction: column;
|
||
justify-content: center;
|
||
font-size: 24rpx;
|
||
|
||
.info-item {
|
||
display: flex;
|
||
align-items: center;
|
||
margin-top: 20rpx;
|
||
|
||
.color {
|
||
width: 6rpx;
|
||
height: 20rpx;
|
||
margin-right: 10rpx;
|
||
border-radius: 3rpx;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
.tips {
|
||
display: flex;
|
||
justify-content: space-between;
|
||
border-bottom: 1px solid #f1f1f1;
|
||
padding: 16rpx 0;
|
||
font-size: 24rpx;
|
||
margin-top: 10rpx;
|
||
}
|
||
|
||
.foodDetailList {
|
||
margin-top: 10rpx;
|
||
|
||
.foodDetailItem {
|
||
display: flex;
|
||
justify-content: space-between;
|
||
padding: 20rpx 0;
|
||
box-sizing: border-box;
|
||
|
||
.name {
|
||
font-size: 24rpx;
|
||
color: #777;
|
||
}
|
||
|
||
.val {
|
||
font-size: 24rpx;
|
||
font-weight: 700;
|
||
color: #333;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
.icon-error {
|
||
position: absolute;
|
||
right: 10rpx;
|
||
top: -35rpx;
|
||
font-size: 45px;
|
||
background: #fff;
|
||
border-radius: 50%;
|
||
width: 45px;
|
||
height: 45px;
|
||
}
|
||
|
||
.wrapper {
|
||
.box {
|
||
height: 800rpx !important;
|
||
padding: 15px !important;
|
||
|
||
.weight {
|
||
position: absolute;
|
||
right: 10rpx;
|
||
top: 260rpx;
|
||
padding: 10rpx;
|
||
z-index: 99;
|
||
}
|
||
|
||
.mybrankmask .rulerIcon {
|
||
width: 60rpx !important;
|
||
height: 60rpx !important;
|
||
}
|
||
|
||
.rulerWrap {
|
||
margin-top: 50rpx;
|
||
.rulerBtn {
|
||
display: flex;
|
||
justify-content: center;
|
||
align-items: center;
|
||
margin-top: 50rpx;
|
||
image {
|
||
width: 50rpx;
|
||
height: 50rpx;
|
||
}
|
||
.confirm {
|
||
width: 60%;
|
||
height: 60rpx;
|
||
line-height: 60rpx;
|
||
text-align: center;
|
||
font-size: 32rpx;
|
||
color: #fff;
|
||
border-radius: 30rpx;
|
||
background-color: #ffbe76;
|
||
margin-left: 50rpx;
|
||
}
|
||
}
|
||
}
|
||
|
||
.val {
|
||
margin: 25px 0 !important;
|
||
font-size: 20px;
|
||
|
||
text {
|
||
font-size: 40px !important;
|
||
width: 140px !important;
|
||
}
|
||
}
|
||
|
||
.keybordIcon {
|
||
width: 50rpx;
|
||
height: 43rpx;
|
||
}
|
||
|
||
.chengIcon {
|
||
width: 50rpx;
|
||
height: 50rpx;
|
||
}
|
||
}
|
||
|
||
.foodItem {
|
||
display: flex;
|
||
justify-content: space-between;
|
||
align-items: center;
|
||
margin-top: 10rpx;
|
||
|
||
.more {
|
||
padding: 8rpx 15rpx;
|
||
border-radius: 12rpx;
|
||
color: #fff;
|
||
background-color: #f0ae43;
|
||
}
|
||
|
||
image {
|
||
width: 90rpx;
|
||
height: 90rpx;
|
||
border-radius: 15rpx;
|
||
}
|
||
|
||
.left {
|
||
display: flex;
|
||
align-items: center;
|
||
|
||
.info {
|
||
display: flex;
|
||
flex-direction: column;
|
||
justify-content: center;
|
||
margin-left: 30rpx;
|
||
|
||
.name {
|
||
font-size: 26rpx;
|
||
color: #333;
|
||
text-align: left;
|
||
margin-bottom: 10rpx;
|
||
}
|
||
|
||
.kcal {
|
||
font-size: 24rpx;
|
||
color: #666;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
.foodInfo {
|
||
display: flex;
|
||
justify-content: space-around;
|
||
margin-top: 30rpx;
|
||
padding: 0 20rpx;
|
||
box-sizing: border-box;
|
||
|
||
.foodInfoItem {
|
||
display: flex;
|
||
flex-direction: column;
|
||
align-items: center;
|
||
|
||
.name {
|
||
display: flex;
|
||
align-items: center;
|
||
font-size: 24rpx;
|
||
color: #8F8F8F;
|
||
|
||
.color {
|
||
width: 6rpx;
|
||
height: 20rpx;
|
||
margin-right: 10rpx;
|
||
border-radius: 3rpx;
|
||
}
|
||
}
|
||
|
||
.value {
|
||
font-size: 28rpx;
|
||
margin-top: 10rpx;
|
||
}
|
||
}
|
||
}
|
||
|
||
.blue-tooth {
|
||
margin-top: 80rpx;
|
||
}
|
||
}
|
||
</style> |