kitchendDevice/pages/count/count.vue

791 lines
16 KiB
Vue
Raw Normal View History

2023-09-08 15:17:21 +08:00
<template>
<view class="content">
2025-04-02 09:49:39 +08:00
<view v-if="!token" class="list2" @click="handleLogin()">
<view class="nolist">
<icon class="iconfont icon-zanwushuju"></icon>
<text>登录后查看更多哦</text>
2023-09-08 15:17:21 +08:00
</view>
2025-04-02 09:49:39 +08:00
<view class="btn">登录</view>
</view>
<view v-else class="content_box">
2025-11-08 16:50:26 +08:00
<view class="set" @click="handleSet">
<view class="date">{{foodInfo.date}}</view>
<view class="icon">
<icon class="iconfont icon-shezhi1"></icon>
2023-09-08 15:17:21 +08:00
</view>
2025-11-08 16:50:26 +08:00
</view>
<view class="box" v-if="userinfo">
2025-11-08 17:31:03 +08:00
<view class="kcal2">
2025-04-02 09:49:39 +08:00
<view class="top">
<view class="left ">
<view class="center">
2025-11-08 16:50:26 +08:00
可以吃
<text>{{foodInfo.remaining_kcal}}</text>
2025-09-17 14:55:24 +08:00
<view class="unit">Kcal</view>
2025-04-02 09:49:39 +08:00
</view>
2023-09-08 15:17:21 +08:00
</view>
2025-04-02 09:49:39 +08:00
<view class="right">
2025-11-08 16:50:26 +08:00
<view class="item border-bottom">
<text class="name">已摄入</text>
<text class="bold">
{{foodInfo.today_intake.kcal}}千卡
</text>
2025-04-02 09:49:39 +08:00
</view>
2025-11-08 16:50:26 +08:00
<view class="item">
<text class="name">碳水</text>
<text class="bold">
{{foodInfo.today_intake.carbohydrate}}/{{foodInfo.suggestion.carbohydrate}}
</text>
2025-04-02 09:49:39 +08:00
</view>
2025-11-08 16:50:26 +08:00
<view class="item">
<text class="name">脂肪</text>
<text class="bold">
{{foodInfo.today_intake.fat}}/{{foodInfo.suggestion.fat}}
</text>
</view>
<view class="item">
<text class="name">蛋白</text>
<text class="bold">
{{foodInfo.today_intake.protein}}/{{foodInfo.suggestion.protein}}
</text>
2025-04-02 09:49:39 +08:00
</view>
2023-09-08 15:17:21 +08:00
</view>
</view>
</view>
2025-04-02 09:49:39 +08:00
<!-- -->
2025-11-08 16:50:26 +08:00
<view class="tools">
2025-04-02 09:49:39 +08:00
<view class="type" @click="handleAddFood(0,'早餐')">
2025-11-08 16:50:26 +08:00
<image src="/static/zao.png"></image>
2025-04-02 09:49:39 +08:00
<view class="text">
<icon class="iconfont icon-add"></icon>早餐
</view>
2023-09-08 15:17:21 +08:00
</view>
2025-04-02 09:49:39 +08:00
<view class="type" @click="handleAddFood(1,'午餐')">
2025-11-08 16:50:26 +08:00
<image src="/static/wu.png"></image>
2025-04-02 09:49:39 +08:00
<view class="text">
<icon class="iconfont icon-add"></icon>午餐
</view>
2023-09-08 15:17:21 +08:00
</view>
2025-04-02 09:49:39 +08:00
<view class="type" @click="handleAddFood(2,'晚餐')">
2025-11-08 16:50:26 +08:00
<image src="/static/wan.png"></image>
2025-04-02 09:49:39 +08:00
<view class="text">
<icon class="iconfont icon-add"></icon>晚餐
</view>
2023-09-08 15:17:21 +08:00
</view>
2025-04-02 09:49:39 +08:00
<view class="type" @click="isShow = true">
2025-11-08 16:50:26 +08:00
<image src="/static/jia.png"></image>
2025-04-02 09:49:39 +08:00
<view class="text">
<icon class="iconfont icon-add"></icon>加餐
</view>
2023-09-08 15:17:21 +08:00
</view>
</view>
2025-04-02 09:49:39 +08:00
<!-- -->
2025-11-08 16:50:26 +08:00
<view class="tabbar-box">
<view class="tabbar">
<view @click="index=0" :class="[index==0?'active':'']">饮食记录</view>
<view @click="index=1" :class="[index==1?'active':'']">历史记录</view>
</view>
<view class="list" v-if="foodInfo.list.length">
<view class="listbox" v-for="(ite,ind) in foodInfo.list" :key="ind">
<view class="left">
<view class="title">{{ite.name}}</view>
<view class="kcalval">
<text>{{ite.val}}</text>{{ite.unit}}
</view>
</view>
<view class="right">
<uni-swipe-action>
<uni-swipe-action-item v-for="(it,id) in ite.list" :key="id"
:right-options="actionOptions" @click="delAcitionItem(it)">
<view class="item" @click="showFoodDetail(it)">
<image :src="it.pic_url" mode="aspectFill"></image>
<text>{{it.name}}</text>
<text>{{it.weight}}</text>
<text>{{it.val}}千卡</text>
</view>
</uni-swipe-action-item>
</uni-swipe-action>
2025-04-02 09:49:39 +08:00
</view>
2023-09-08 15:17:21 +08:00
</view>
</view>
2025-11-08 16:50:26 +08:00
<view v-else class="nolist list">
<image src="/static/none.png"></image>
<text>暂无打卡记录</text>
<text>点击上方按钮打卡吧</text>
</view>
2025-04-02 09:49:39 +08:00
</view>
2023-09-08 15:17:21 +08:00
</view>
2025-04-02 09:49:39 +08:00
<view v-else class="list2" @click="handleEditUser()">
<view class="nolist">
2025-11-08 16:50:26 +08:00
<image src="/static/none.png"></image>
2025-04-02 09:49:39 +08:00
<text>完善资料后记录更准确哦</text>
</view>
<view class="btn">完善资料</view>
2023-09-08 15:17:21 +08:00
</view>
</view>
<!-- 加餐 -->
<view class="wrapper activeList" v-if="isShow">
<view class="bg" @click='isShow=false'>
<view class="addfood" @click.stop>
<icon class="iconfont icon-error" @click='isShow=false'></icon>
<view class="list">
<view class="item" v-for="(ite,ind) in addfoodList" :key="ind"
@click="handleAddFood(ite.id,ite.name)">
<text class="name">{{ite.name}}</text>
</view>
</view>
</view>
</view>
</view>
2025-09-17 14:55:24 +08:00
<!-- 营养含量分析 -->
<uni-drawer ref="showRight" mode="right" width="300">
<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">{{activeFoodDetail.val}}千卡</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="chartData2" :cHeight="250" :cWidth="250" />
<view class="uchart-kcal">{{activeFoodDetail.val}}</view>
</div>
<view class="info" v-if="activeFoodDetail.nutrients_four">
<view class="info-item" v-for="(item,index) in activeFoodDetail.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>{{activeFoodDetail.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">{{item.value}}{{item.unit}}
</view>
</view>
</view>
</view>
</view>
</scroll-view>
</uni-drawer>
2023-09-08 15:17:21 +08:00
</view>
</template>
<script>
import {
mapState
} from "vuex";
let next = 0
import qiunDataCharts from '@/uni_modules/qiun-data-charts/components/qiun-data-charts.vue';
export default {
data() {
return {
2025-04-02 09:49:39 +08:00
token: "",
2025-11-08 16:50:26 +08:00
index: 0,
2025-09-17 14:55:24 +08:00
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
}
}
},
2023-09-08 15:17:21 +08:00
isShow: false,
2025-09-17 14:55:24 +08:00
chartData2: {},
2023-09-08 15:17:21 +08:00
addfoodList: [{
name: "早加餐",
id: 3,
},
{
name: "午加餐",
id: 4,
}, {
name: "晚加餐",
id: 5,
}
],
markDays: {
2025-03-25 10:17:30 +08:00
warning: [],
success: [],
error: [],
2023-09-08 15:17:21 +08:00
},
2025-03-25 10:17:30 +08:00
startDay: "",
2025-09-17 14:55:24 +08:00
activeFoodDetail: {},
actionOptions: [{
text: '删除',
style: {
backgroundColor: '#dd524d',
borderRadius: '10rpx'
}
}]
2023-09-08 15:17:21 +08:00
}
},
components: {
qiunDataCharts
},
computed: {
2025-11-08 16:50:26 +08:00
...mapState(["user", "countFoodInfo"]),
2025-03-25 10:17:30 +08:00
userinfo() {
2025-11-08 16:50:26 +08:00
return this.user.aud_id
},
foodInfo() {
return this.countFoodInfo
2025-03-25 10:17:30 +08:00
}
2023-09-08 15:17:21 +08:00
},
2025-11-08 16:50:26 +08:00
onLoad() {
2023-09-08 15:17:21 +08:00
let that = this
2025-04-02 09:49:39 +08:00
that.token = uni.getStorageSync('token')
2025-03-25 10:17:30 +08:00
// 指定日期
if (uni.getStorageSync("startDay")) {
that.startDay = uni.getStorageSync("startDay");
2023-09-08 15:17:21 +08:00
uni.removeStorageSync('startDay');
2025-03-25 10:17:30 +08:00
} else {
2023-09-08 15:17:21 +08:00
that.startDay = this.$tools.getDate("start")
}
2025-11-08 16:50:26 +08:00
that.$store.dispatch("getCountFoodInfo", {
aud_id: that.user.aud_id,
time: that.$tools.getDate("start")
})
2023-09-08 15:17:21 +08:00
},
methods: {
2025-11-08 16:50:26 +08:00
// 详情
2025-09-17 14:55:24 +08:00
showFoodDetail(item) {
console.log("item", item)
2025-11-08 16:50:26 +08:00
let chart_data = []
2025-09-17 14:55:24 +08:00
this.activeFoodDetail = item
this.$refs.showRight.open();
this.opts.color = []
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.chartData2 = JSON.parse(JSON.stringify({
series: [{
data: chart_data
}]
}));
},
2025-11-08 16:50:26 +08:00
2023-09-08 15:17:21 +08:00
// 添加的食材
getAddFood(list) {
let that = this
that.list.push(list)
console.log("list", that.list, that.list.sort())
},
// 设置
handleSet() {
uni.navigateTo({
url: "/pageTwo/count/setting"
})
},
// 完善资料
handleEditUser() {
uni.navigateTo({
url: "/pageTwo/me/userEdit?type=add"
})
},
// 添加食物
handleAddFood(ind, name) {
this.isShow = false
uni.navigateTo({
2025-11-08 16:50:26 +08:00
url: "/pageTwo/count/search?name=" + name + '&ind=' + ind
2023-09-08 15:17:21 +08:00
})
2025-04-02 09:49:39 +08:00
},
// 去登录
handleLogin() {
uni.reLaunch({
url: "/pageTwo/login/login"
})
2025-09-04 17:33:41 +08:00
},
2025-09-17 14:55:24 +08:00
delAcitionItem(item) {
uni.showModal({
content: `是否删除[${item.name}]`,
success: (res) => {
if (res.confirm) {
this.$model.delCEatAction({
aud_id: this.user.aud_id,
eat_log_id: item.id
}).then(res => {
this.handleCountFoodInfo()
})
}
}
})
}
2023-09-08 15:17:21 +08:00
}
}
</script>
<style scoped lang="scss">
.content {
2025-11-08 16:50:26 +08:00
padding: 0 10px;
background-color: #fff;
2023-09-08 15:17:21 +08:00
}
2025-09-17 14:55:24 +08:00
.content_box {
2025-04-02 09:49:39 +08:00
width: 100%;
}
2023-09-08 15:17:21 +08:00
.box {
width: 100%;
}
2025-11-08 16:50:26 +08:00
.set {
display: flex;
align-items: center;
justify-content: space-between;
margin-top: 10px;
font-size: 16px;
font-weight: bold;
.icon {
background: #d1f2ed;
border-radius: 50%;
font-size: 28px;
color: #66cccc;
text-align: center;
padding: 5px;
}
2023-09-08 15:17:21 +08:00
}
2025-11-08 17:31:03 +08:00
.kcal2 {
2023-09-08 15:17:21 +08:00
width: calc(100% - 20px);
margin-bottom: 15px;
background: #fff;
2025-11-08 16:50:26 +08:00
border-radius: 10px;
2023-09-08 15:17:21 +08:00
padding: 10px;
position: relative;
2025-11-08 16:50:26 +08:00
margin-top: 15px;
background: #f3fffd;
box-shadow: 0px 1px 5px 2px #dfe2e1fc;
2023-09-08 15:17:21 +08:00
2025-11-08 16:50:26 +08:00
.left {
width: 300rpx;
height: 300rpx;
2023-09-08 15:17:21 +08:00
position: relative;
2025-11-08 16:50:26 +08:00
border-radius: 50%;
background: #d1f2ed;
border: 5px solid #66cccc;
display: flex;
justify-content: center;
align-items: center;
2023-09-08 15:17:21 +08:00
2025-11-08 16:50:26 +08:00
.center {
2023-09-08 15:17:21 +08:00
position: absolute;
2025-11-08 16:50:26 +08:00
text-align: center;
width: 260rpx;
height: 260rpx;
2023-09-08 15:17:21 +08:00
display: flex;
flex-wrap: wrap;
flex-direction: column;
2025-11-08 16:50:26 +08:00
align-items: center;
justify-content: center;
background: #fff;
border-radius: 50%;
2023-09-08 15:17:21 +08:00
2025-11-08 16:50:26 +08:00
text {
2023-09-08 15:17:21 +08:00
display: inline-block;
2025-09-17 14:55:24 +08:00
font-size: 22px;
font-weight: bold;
2025-11-08 16:50:26 +08:00
margin: 10px 0;
2025-09-17 14:55:24 +08:00
}
2025-11-08 16:50:26 +08:00
2023-09-08 15:17:21 +08:00
}
}
2025-11-08 16:50:26 +08:00
.right {
position: absolute;
left: 50%;
bottom: 0;
top: 0px;
right: 0;
2023-09-08 15:17:21 +08:00
display: flex;
2025-11-08 16:50:26 +08:00
flex-wrap: wrap;
padding: 0 10px;
border-radius: 0 10px 10px 0;
justify-content: center;
flex-direction: column;
background: #d1f2ed;
2023-09-08 15:17:21 +08:00
.item {
2025-09-17 14:55:24 +08:00
display: flex;
2025-11-08 16:50:26 +08:00
justify-content: space-between;
height: 35px;
line-height: 35px;
}
2023-09-08 15:17:21 +08:00
2025-11-08 16:50:26 +08:00
.border-bottom {
border-bottom: 1px solid #dfdfdf;
2023-09-08 15:17:21 +08:00
}
}
}
2025-11-08 16:50:26 +08:00
.tools {
2023-09-08 15:17:21 +08:00
width: 100%;
background: #fff;
border-radius: 10px;
padding: 10px 0;
display: flex;
margin-bottom: 15px;
justify-content: space-between;
2025-11-08 16:50:26 +08:00
box-shadow: 0px 1px 5px 2px #dfe2e1fc;
2023-09-08 15:17:21 +08:00
.type {
width: 20%;
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: center;
2025-11-08 16:50:26 +08:00
image {
width: 45px;
height: 45px;
2023-09-08 15:17:21 +08:00
}
.text {
width: 100%;
text-align: center;
display: flex;
justify-content: center;
2025-11-08 16:50:26 +08:00
font-weight: bold;
2023-09-08 15:17:21 +08:00
icon {
font-size: 14px;
}
}
}
}
2025-11-08 16:50:26 +08:00
.tabbar-box {
background: #f3fffd;
border-radius: 10px;
box-shadow: 0px 1px 5px 2px #dfe2e1fc;
.tabbar {
height: 45px;
width: 100%;
display: flex;
justify-content: space-between;
view {
width: 50%;
line-height: 45px;
text-align: center;
}
.active {
border-radius: 10px;
color: $maincolor;
background: #fff;
}
}
}
2023-09-08 15:17:21 +08:00
.list {
width: 100%;
padding-bottom: 50px;
.listbox {
2025-11-08 17:31:03 +08:00
width: calc(100% - 40px);
2023-09-08 15:17:21 +08:00
padding: 10px;
border-radius: 10px;
background-color: #fff;
2025-11-08 17:31:03 +08:00
margin: 15px 10px;
2023-09-08 15:17:21 +08:00
}
.left {
width: 100%;
margin-bottom: 10px;
display: flex;
align-items: center;
.title {
font-size: 16px;
font-weight: bold;
}
text {
font-weight: bold;
margin-right: 5px;
margin-left: 15px;
}
}
.right {
2025-03-25 10:17:30 +08:00
width: 100%;
2023-09-08 15:17:21 +08:00
.item {
2025-09-04 17:33:41 +08:00
height: 40px;
line-height: 40px;
2023-09-08 15:17:21 +08:00
border-bottom: 1px solid #f7f7f7;
display: flex;
justify-content: space-between;
2025-09-17 14:55:24 +08:00
align-items: center;
image {
width: 60rpx;
height: 60rpx;
border-radius: 12rpx;
margin-right: 10rpx;
}
2023-09-08 15:17:21 +08:00
:nth-child(2) {
2025-09-04 17:33:41 +08:00
width: 40%;
2025-09-17 14:55:24 +08:00
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
2025-03-25 10:17:30 +08:00
}
:nth-child(3) {
2025-09-04 17:33:41 +08:00
width: 20%;
text-align: right;
}
:nth-child(4) {
width: 26%;
2025-09-17 14:55:24 +08:00
margin-right: 6rpx;
2025-03-25 10:17:30 +08:00
text-align: right;
2023-09-08 15:17:21 +08:00
}
}
}
}
.nolist {
font-size: 12px;
color: #999;
padding: 30px 10px;
text-align: center;
width: auto;
2025-11-08 16:50:26 +08:00
image {
width: 50px;
height: 50px;
2023-09-08 15:17:21 +08:00
color: #999;
display: flex;
justify-content: center;
margin-bottom: 10px;
}
}
2025-11-08 16:50:26 +08:00
2023-09-08 15:17:21 +08:00
.list2 {
margin-top: 45%;
.btn {
color: #fff;
height: 32px;
line-height: 32px;
}
}
.addfood {
background-color: #fff;
position: absolute;
left: 0;
right: 0;
bottom: 0;
padding: 10px 10px 0 10px;
border-radius: 10px 10px 0 0;
.iconfont {
position: absolute;
right: 7px;
top: -10px;
background: #f7f7f7;
border-radius: 50%;
font-size: 30px;
}
.list {
padding-bottom: 0px;
.item {
height: 40px;
line-height: 40px;
border-bottom: none;
}
.name {
width: 100%;
text-align: center;
}
:nth-child(2).item {
border-bottom: 1px solid #dfdfdf;
border-top: 1px solid #dfdfdf;
}
}
}
2025-09-17 14:55:24 +08:00
.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 {
width: 100% !important;
font-size: 24rpx;
color: #666;
padding: 0 !important;
margin: 0 !important;
}
}
}
.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;
}
}
}
}
}
2025-03-25 10:17:30 +08:00
</style>