ReedawFoodApp/Food/count/setting.vue

293 lines
6.2 KiB
Vue
Raw Normal View History

2026-03-23 16:23:40 +08:00
<template>
<view class="content">
<!-- -->
<view class="kcal">
<view class="set">
<input type="digit" v-model="weight" placeholder="请输入" :focus="focus" @blur="handleBlur">
<uni-icons v-if="weight!=''" type="close" size="24" class="uni-iocns" color="#999"
@click="handleclear"></uni-icons>
<view class="num">
{{kcal.suggestion_kcal_unit}}
</view>
</view>
<view class="desc">
{{kcal.suggestion_kcal_range_val}}
</view>
</view>
<!-- -->
<view class="kcal">
<view class="text">
营养占比
</view>
2026-03-30 10:02:10 +08:00
<view class="slider" v-if="isShow">
2026-03-23 16:23:40 +08:00
<llt-slider-range :model-value="rangeValue" @change="handleChange" />
</view>
<view class="list">
<view class="item" v-for="(ite,ind) in nutrition.list">
<icon class="iconfont" :class="ite.icon"></icon>
<text>{{ite.name}}</text>
<text>{{ite.proportion}}%</text>
<view class="val">{{ite.val}}{{ite.unit}}</view>
</view>
</view>
</view>
<view class="num">
<view class="item" v-for="(ite,ind) in nutrition.describe">
<text>{{ite}}</text>
</view>
</view>
<view class="subbtn" @click="handleEditKcal">保存</view>
</view>
</template>
<script>
import {
mapState
} from "vuex";
import lltSliderRange from '@/uni_modules/llt-slider-range/components/llt-slider-range/llt-slider-range.vue';
export default {
data() {
return {
weight: "",
kcal: {},
nutrition: {},
focus: false,
carbohydrate_v: 0,
protein_v: 0,
fat_v: 0,
2026-03-30 10:02:10 +08:00
isShow: true,
2026-03-23 16:23:40 +08:00
carbohydrate_p: 0,
protein_p: 0,
fat_p: 0,
rangeValue: [0, 0]
}
},
computed: {
...mapState(["user"]),
info() {
return this.user
}
},
onLoad() {
this.handleList()
},
components: {
lltSliderRange
},
methods: {
handleList() {
let that = this
that.$model.getCountSetKcal({
aud_id: that.user.aud_id
}).then(res => {
if (res.code == 0) {
2026-03-30 10:02:10 +08:00
that.isShow = false
2026-03-23 16:23:40 +08:00
that.kcal = res.data.kcal
that.nutrition = res.data.nutrition
that.weight = res.data.kcal.suggestion_kcal_val
2026-03-30 10:02:10 +08:00
that.$nextTick(() => {
that.isShow = true
that.rangeValue[0] = Number(that.nutrition.list[0].proportion)
2026-03-30 15:02:56 +08:00
that.rangeValue[1] = Number(that.nutrition.list[0].proportion) + Number(that
.nutrition.list[1].proportion)
2026-03-30 10:02:10 +08:00
that.handleProportion()
})
2026-03-23 16:23:40 +08:00
}
})
},
handleChange(val) {
let that = this
that.rangeValue = val
that.weight = that.weight ? that.weight : Number(that.kcal.suggestion_kcal_val)
that.handleProportion()
},
handleProportion() {
let that = this
that.nutrition.list.forEach(ite => {
if (ite.key_v == "carbohydrate") {
ite.proportion = that.rangeValue[0]
ite.val = Number(that.weight * ite.proportion / 100 / 4).toFixed(2)
that.carbohydrate_v = ite.val
that.carbohydrate_p = ite.proportion
}
if (ite.key_v == "protein") {
ite.proportion = that.rangeValue[1] - that.rangeValue[0]
ite.val = Number(that.weight * ite.proportion / 100 / 4).toFixed(2)
that.protein_v = ite.val
that.protein_p = ite.proportion
}
if (ite.key_v == "fat") {
ite.proportion = 100 - that.rangeValue[1]
ite.val = Number(that.weight * ite.proportion / 100 / 9).toFixed(2)
that.fat_v = ite.val
that.fat_p = ite.proportion
}
})
},
handleBlur() {
let that = this
that.weight = that.weight ? that.weight : Number(that.kcal.suggestion_kcal_val)
that.handleProportion()
},
handleEditKcal() {
let that = this
if (that.weight == '' || Number(that.weight) <= 0) {
that.$tools.msg("请输入卡路里")
return
}
that.$model.getCountSetUserKcal({
aud_id: that.user.aud_id,
set_kcal: that.weight,
carbohydrate_v: that.carbohydrate_v,
protein_v: that.protein_v,
fat_v: that.fat_v,
carbohydrate_p: that.carbohydrate_p,
protein_p: that.protein_p,
fat_p: that.fat_p,
}).then(res => {
if (res.code == 0) {
that.$tools.msg("设置成功")
that.$store.dispatch('getUserInfo', {
2026-03-30 10:02:10 +08:00
aud_id: that.user.aud_id
2026-03-23 16:23:40 +08:00
})
2026-03-30 15:02:56 +08:00
that.$store.dispatch("getCountFoodInfo", {
aud_id: that.user.aud_id,
time: that.$tools.getDate("start")
})
2026-03-23 16:23:40 +08:00
setTimeout(function() {
uni.navigateBack()
}, 1000)
}
})
},
handleclear() {
this.focus = true
this.weight = ""
}
}
}
</script>
<style scoped lang="scss">
.content {
padding: 30rpx;
background: #f7f7f7;
}
.kcal {
width: calc(100% - 40rpx);
background: #fff;
margin-bottom: 30rpx;
padding: 20rpx;
border-radius: 10px;
.set {
width: calc(100% - 40rpx);
background: #f7f7f7;
border-radius: 10px;
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 10px;
position: relative;
height: 45px;
input {
width: 100%;
font-size: 16px;
}
.num {
position: absolute;
right: 10px;
}
.uni-iocns {
position: absolute;
right: 50px;
z-index: 99;
}
}
.desc {
font-size: 24rpx;
color: #999;
line-height: 40rpx;
margin-top: 10px;
}
}
.slider {
background: #f7f7f7;
margin-top: 15px;
border-radius: 10px;
padding: -10px 0;
}
.list {
display: flex;
justify-content: space-between;
margin-top: 15px;
.item {
display: flex;
flex-wrap: wrap;
width: 30%;
background-color: #f7f7f7;
justify-content: center;
border-radius: 10px;
icon {
font-size: 40px;
color: $uni-color-warning;
border-radius: 30%;
padding: 5px;
}
text {
font-size: 14px;
font-weight: 500;
color: #666;
display: inline-block;
width: 100%;
text-align: center;
line-height: 20px;
border-bottom: none;
}
.val {
width: 100%;
background: #f7f7f7;
border-radius: 10px;
margin: auto;
text-align: center;
font-weight: bold;
padding: 2px 0;
}
}
}
.num {
display: flex;
font-size: 24rpx;
flex-direction: column;
.item {
width: 100%;
line-height: 24px;
}
}
.subbtn {
color: #fff;
width: 100%;
text-align: center;
border-radius: 20rpx;
height: 35px;
line-height: 35px;
margin: 15px 0;
background-color: #f0ae43;
}
</style>