kitchendDevice/pageTwo/count/everyMeal.vue

446 lines
9.6 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">
<view class="content_box">
<view class="box">
<!-- 类型 -->
<view class="top">
<image :src="bgimage" mode="aspectFill">
<view class="name">{{info.name}}</view>
<view class="time">{{time}}</view>
</image>
</view>
<!-- 成分统计 -->
<view class="everyDay">
<view class="title">
<view><text class="quan"></text>成分统计</view>
</view>
<view class="progress">
<div class="chart-wrap">
<qiun-data-charts type="ring" :opts="opts" canvasId="foodCharts" :chartData="chartData"
:cHeight="280" :cWidth="280" />
</div>
<view class="info" v-if="info.nutrients_four">
<view class="info-item" v-for="(item,index) in info.nutrients_four.slice(1)" :key="index">
<view>
<view class="color" :style="{'background-color':`${item.color}`}"></view>
<view>{{item.name}}</view>
</view>
<view>
<view>{{item.value}}{{item.unit}}<text>|</text>{{item.proportion}}%</view>
</view>
</view>
</view>
</view>
</view>
<!-- 早午晚餐 -->
<view class="foodtools">
<view class="type">
<view class="title">
<view><text class="quan"></text>食物类型</view>
</view>
<view class="list" v-if="info.list.length">
<uni-swipe-action>
<uni-swipe-action-item v-for="(ite,ind) in info.list" :key="ind"
:right-options="actionOptions" @click="delAcitionItem(ite)">
<view class="item" @click="showFoodDetail(ite)">
<image :src="ite.pic_url" mode="aspectFill"></image>
<view class="weight">
<view>{{ite.name}}</view>
<view class="size12 c999">{{ite.weight}}<text>|</text>{{ite.val}}kcal</view>
</view>
</view>
</uni-swipe-action-item>
</uni-swipe-action>
</view>
<view v-else class="nolist">
<image src="/static/none.png"></image>
<view>暂无食物</view>
</view>
</view>
</view>
<!-- 添加食物 -->
<view class="add" @click="handleAddFood()">
<text>+</text>添加食物
</view>
</view>
</view>
<!-- 营养含量分析 -->
<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="opts2" :chartData="chartData2" :cHeight="280"
:cWidth="280" />
</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>
</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 {
opts: {
color: [],
title: {
name: "",
}
},
opts2: {
color: [],
title: {
name: "",
}
},
chartData: {},
chartData2: {},
activeFoodDetail: {},
actionOptions: [{
text: '删除',
style: {
backgroundColor: '#dd524d',
borderRadius: '10rpx'
}
}],
time: "",
bgimage: "",
page: "",
index: "",
info:{}
}
},
components: {
qiunDataCharts
},
computed: {
...mapState(["user", "countFoodInfo", "configInfo"]),
foodItem() {
return this.configInfo.meal_list
},
},
onLoad(options) {
let that = this
that.page = options.page
that.index = options.index
that.bgimage = that.foodItem[options.index].icon_bg
that.handleInfo()
},
watch: {
user() {
this.handleInfo()
},
countFoodInfo() {
this.handleInfo()
}
},
methods: {
handleInfo() {
let that = this
that.time = that.page == "home" ? that.user.food_count.date : that.countFoodInfo.date
that.info = that.page == "home" ? that.user.food_count.list[that.index] : that.countFoodInfo.list[that
.index]
let chart_data = []
that.opts.color = []
for (let i = 1; i < that.info.nutrients_four.length; ++i) {
this.opts.color.push(that.info.nutrients_four[i].color)
chart_data.push({
name: that.info.nutrients_four[i].name,
value: Number(that.info.nutrients_four[i].proportion),
})
}
this.opts.title.name = that.info.val
this.chartData = JSON.parse(JSON.stringify({
series: [{
data: chart_data
}]
}));
},
// 详情
showFoodDetail(item) {
console.log("item", item)
let that = this
let chart_data = []
this.activeFoodDetail = item
this.$refs.showRight.open();
this.opts2.color = []
for (let i = 1; i < item.nutrients_four.length; ++i) {
this.opts2.color.push(item.nutrients_four[i].color)
chart_data.push({
name: item.nutrients_four[i].name,
value: Number(item.nutrients_four[i].proportion),
})
}
this.opts2.title.name = that.activeFoodDetail.val
this.chartData2 = JSON.parse(JSON.stringify({
series: [{
data: chart_data
}]
}));
},
// 添加食物
handleAddFood() {
uni.navigateTo({
url: "/pageTwo/count/search?name=" + this.info.name + "&time=" + this.time
})
},
// 删除食材
delAcitionItem(item) {
let that = this
uni.showModal({
content: `是否删除[${item.name}]`,
success: (res) => {
if (res.confirm) {
this.$model.delCEatAction({
aud_id: that.user.aud_id,
eat_log_id: item.id
}).then(res => {
that.$store.dispatch("getCountFoodInfo", {
aud_id: that.user.aud_id,
time: that.time
})
// 删除最新一天食物
if (that.time == that.user.food_count.date) {
that.$store.dispatch("getUserInfo")
}
})
}
}
})
}
}
}
</script>
<style scoped lang="scss">
.content {
padding: 0 20rpx;
}
.content_box {
width: 100%;
}
.quan {
margin-right: 70rpx;
}
.top {
width: 100%;
height: 280rpx;
display: flex;
position: relative;
flex-direction: column;
align-items: center;
justify-content: center;
background: #dfdfdf;
border-radius: 10px;
margin-top: 15px;
.name {
width: 100%;
text-align: center;
font-size: 25px;
font-weight: bold;
}
view {
z-index: 11;
}
image {
position: absolute;
width: 100%;
height: 100%;
z-index: 9;
border-radius: 10px;
}
}
.everyDay {
background: #fff;
padding: 10px;
border-radius: 10px;
margin-top: 15px;
height: auto;
overflow: hidden;
.progress {
display: flex;
align-items: center;
.chart-wrap {
position: relative;
width: 280rpx;
height: 280rpx;
margin-top: -30rpx;
margin-left: -15px;
}
.info {
display: flex;
flex-direction: column;
justify-content: space-between;
font-size: 24rpx;
width: calc(100% - 270rpx);
height: 200rpx;
.info-item {
display: flex;
align-items: center;
justify-content: space-between;
margin-top: 30rpx;
view {
display: flex;
align-items: center;
}
text {
color: #ccc;
margin: 0px 5px;
}
.color {
width: 10rpx;
height: 10rpx;
margin-right: 10rpx;
border-radius: 3rpx;
}
}
}
}
}
.foodtools {
margin-top: 15px;
.type {
background: #fff;
margin-bottom: 10px;
border-radius: 10px;
padding: 10px 10px 0;
.title {
display: flex;
align-items: center;
justify-content: space-between;
image {
width: 30px;
height: 30px;
}
.text {
width: 50%;
display: flex;
align-items: center;
view {
font-size: 32rpx;
font-weight: bold;
margin: 0 10px;
}
}
.detail {
color: #999;
display: flex;
font-size: 24rpx;
align-items: center;
}
}
.list {
width: 100%;
margin-top: 15px;
.item {
display: flex;
padding: 10px 0;
border-bottom: 1px solid #f7f7f7;
image {
width: 90rpx;
height: 90rpx;
border-radius: 50%;
border: 1px solid #f7f7f7;
}
.weight {
display: flex;
flex-direction: column;
justify-content: space-between;
margin-left: 10px;
text {
margin: 0 10px;
color: #dfdfdf;
}
}
}
}
}
}
.nolist {
image {
width: 120rpx;
height: 120rpx;
}
view {
margin-bottom: 15px;
text-align: center;
width: 100%;
margin-top: 10px;
color: #999;
}
}
.add {
width: 100%;
text-align: center;
font-weight: bold;
margin-top: 10px;
}
</style>