kitchendDevice/pageTwo/count/setting.vue

288 lines
6.1 KiB
Vue
Raw Normal View History

2023-09-08 15:17:21 +08:00
<template>
<view class="content">
<!-- -->
2025-11-25 14:21:22 +08:00
<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>
2023-09-08 15:17:21 +08:00
</view>
2025-11-25 14:21:22 +08:00
<view class="desc">
{{kcal.suggestion_kcal_range_val}}
2023-09-08 15:17:21 +08:00
</view>
</view>
<!-- -->
<view class="kcal">
<view class="text">
2025-11-25 14:21:22 +08:00
营养占比
2023-09-08 15:17:21 +08:00
</view>
2025-11-25 14:21:22 +08:00
<view class="slider">
<llt-slider-range :model-value="rangeValue" @change="handleChange" />
</view>
<view class="list">
2025-03-25 10:17:30 +08:00
<view class="item" v-for="(ite,ind) in nutrition.list">
<icon class="iconfont" :class="ite.icon"></icon>
<text>{{ite.name}}</text>
2025-11-25 14:21:22 +08:00
<text>{{ite.proportion}}%</text>
2025-03-25 10:17:30 +08:00
<view class="val">{{ite.val}}{{ite.unit}}</view>
2023-09-08 15:17:21 +08:00
</view>
</view>
2025-11-25 14:21:22 +08:00
</view>
<view class="num">
<view class="item" v-for="(ite,ind) in nutrition.describe">
<text>{{ite}}</text>
2023-09-08 15:17:21 +08:00
</view>
</view>
2025-11-25 14:21:22 +08:00
<view class="subbtn" @click="handleEditKcal">保存</view>
2023-09-08 15:17:21 +08:00
</view>
</template>
<script>
import {
mapState
} from "vuex";
2025-11-25 14:21:22 +08:00
import lltSliderRange from '@/uni_modules/llt-slider-range/components/llt-slider-range/llt-slider-range.vue';
2023-09-08 15:17:21 +08:00
export default {
data() {
return {
2025-11-25 14:21:22 +08:00
weight: "",
2025-03-25 10:17:30 +08:00
kcal: {},
nutrition: {},
2025-11-25 14:21:22 +08:00
focus: false,
carbohydrate_v: 0,
protein_v: 0,
fat_v: 0,
carbohydrate_p: 0,
protein_p: 0,
fat_p: 0,
rangeValue: [0, 0]
2023-09-08 15:17:21 +08:00
}
},
computed: {
2025-04-02 09:49:39 +08:00
...mapState(["user"]),
userInfo() {
return this.user
}
2023-09-08 15:17:21 +08:00
},
2025-03-25 10:17:30 +08:00
onLoad() {
this.handleList()
},
2025-11-25 14:21:22 +08:00
components: {
lltSliderRange
},
watch: {},
2023-09-08 15:17:21 +08:00
methods: {
2025-03-25 10:17:30 +08:00
handleList() {
let that = this
that.$model.getCountSetKcal({
2025-04-02 09:49:39 +08:00
aud_id: that.userInfo.aud_id
2025-03-25 10:17:30 +08:00
}).then(res => {
if (res.code == 0) {
that.kcal = res.data.kcal
that.nutrition = res.data.nutrition
2025-11-25 14:21:22 +08:00
that.weight = res.data.kcal.suggestion_kcal_val
that.rangeValue[0] = Number(that.nutrition.list[0].proportion)
that.rangeValue[1] = Number(that.nutrition.list[0].proportion) + Number(that.nutrition.list[1].proportion)
console.log("that.rangeValue", that.rangeValue)
that.handleProportion()
2025-03-25 10:17:30 +08:00
}
})
},
2023-09-08 15:17:21 +08:00
handleEditUser() {
uni.navigateTo({
2025-04-02 09:49:39 +08:00
url: "/pageTwo/me/userEdit?familayData=" + JSON.stringify(this.userInfo)
2023-09-08 15:17:21 +08:00
})
},
2025-11-25 14:21:22 +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.name.indexOf('碳水') != -1) {
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.name.indexOf('蛋白') != -1) {
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.name.indexOf('脂肪') != -1) {
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()
},
2023-09-08 15:17:21 +08:00
handleEditKcal() {
2025-11-25 14:21:22 +08:00
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("设置成功")
2025-11-29 10:02:33 +08:00
that.$store.dispatch("getUserInfo")
2025-11-25 14:21:22 +08:00
setTimeout(function() {
uni.switchTab({
url: '/pages/count/count'
})
}, 1000)
}
2023-09-08 15:17:21 +08:00
})
2025-11-25 14:21:22 +08:00
},
handleclear() {
this.focus = true
this.weight = ""
2023-09-08 15:17:21 +08:00
}
}
}
</script>
<style scoped lang="scss">
.content {
2025-11-25 14:21:22 +08:00
padding: 0 30rpx;
2023-09-08 15:17:21 +08:00
}
2025-11-25 14:21:22 +08:00
.kcal {
width: calc(100% - 40rpx);
2023-09-08 15:17:21 +08:00
background: #fff;
2025-11-25 14:21:22 +08:00
margin: 20rpx 0;
padding: 20rpx;
2023-09-08 15:17:21 +08:00
border-radius: 10px;
2025-11-25 14:21:22 +08:00
.set {
width: calc(100% - 40rpx);
background: #f7f7f7;
border-radius: 10px;
2023-09-08 15:17:21 +08:00
display: flex;
align-items: center;
2025-11-25 14:21:22 +08:00
justify-content: space-between;
padding: 0 10px;
position: relative;
height: 45px;
2023-09-08 15:17:21 +08:00
2025-11-25 14:21:22 +08:00
input {
width: 100%;
font-size: 16px;
2023-09-08 15:17:21 +08:00
}
2025-11-25 14:21:22 +08:00
.num {
position: absolute;
right: 10px;
2023-09-08 15:17:21 +08:00
}
2025-11-25 14:21:22 +08:00
.uni-iocns {
position: absolute;
right: 50px;
z-index: 99;
2023-09-08 15:17:21 +08:00
}
}
2025-11-25 14:21:22 +08:00
.desc {
font-size: 24rpx;
color: #999;
line-height: 40rpx;
margin-top: 10px;
2023-09-08 15:17:21 +08:00
}
}
2025-11-25 14:21:22 +08:00
.slider {
background: #f7f7f7;
margin-top: 15px;
2023-09-08 15:17:21 +08:00
border-radius: 10px;
2025-11-25 14:21:22 +08:00
padding: -10px 0;
}
2023-09-08 15:17:21 +08:00
2025-11-25 14:21:22 +08:00
.list {
display: flex;
justify-content: space-between;
margin-top: 15px;
2023-09-08 15:17:21 +08:00
2025-11-25 14:21:22 +08:00
.item {
2023-09-08 15:17:21 +08:00
display: flex;
2025-11-25 14:21:22 +08:00
flex-wrap: wrap;
width: 30%;
background-color: #f7f7f7;
2023-09-08 15:17:21 +08:00
justify-content: center;
2025-11-25 14:21:22 +08:00
border-radius: 10px;
2023-09-08 15:17:21 +08:00
2025-11-25 14:21:22 +08:00
icon {
font-size: 40px;
color: $uni-color-warning;
border-radius: 30%;
padding: 5px;
2023-09-08 15:17:21 +08:00
}
2025-11-25 14:21:22 +08:00
text {
font-size: 14px;
font-weight: 500;
color: #666;
display: inline-block;
width: 100%;
text-align: center;
line-height: 20px;
border-bottom: none;
}
2023-09-08 15:17:21 +08:00
2025-11-25 14:21:22 +08:00
.val {
width: 100%;
background: #f7f7f7;
border-radius: 10px;
margin: auto;
text-align: center;
font-weight: bold;
padding: 2px 0;
2023-09-08 15:17:21 +08:00
}
}
2025-11-25 14:21:22 +08:00
}
2023-09-08 15:17:21 +08:00
2025-11-25 14:21:22 +08:00
.num {
display: flex;
font-size: 24rpx;
flex-direction: column;
.item {
width: 100%;
2023-09-08 15:17:21 +08:00
}
}
2025-11-25 14:21:22 +08:00
.subbtn {
color: #fff;
width: 100%;
text-align: center;
border-radius: 20rpx;
height: 35px;
line-height: 35px;
margin: 15px 0;
background-color: #f0ae43;
}
2025-03-25 10:17:30 +08:00
</style>