外食计算器优化,营养成分以及热量比例数据计算
This commit is contained in:
@ -1,13 +1,18 @@
|
||||
<template>
|
||||
<!-- 计算食材热量对话框 -->
|
||||
<el-dialog :title="title" :visible.sync="open" width="750px" append-to-body>
|
||||
<el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body>
|
||||
<el-form ref="form" :model="form" label-position="top" :rules="rules" label-width="100px">
|
||||
|
||||
<el-form-item v-for="(item,index) in foodHeatList" label="" class="margin-left">
|
||||
<div>
|
||||
<span>食材名称:</span><el-input style="width:30%" placeholder="" :readonly="true" :value="item.ingredient"/>
|
||||
<span style="margin-left: 10px">份量:</span><el-input style="width:25%" placeholder="" :readonly="true" :value="getNumberString(item)"/>
|
||||
<span style="margin-left: 10px">热量:</span><el-input style="width:15%" type="number" placeholder="" v-model="item.heatValue"/><span>千卡</span>
|
||||
<span>食材名称:</span><el-input style="width:20%" placeholder="" :readonly="true" :value="item.ingredient"/>
|
||||
<span style="margin-left: 10px">份量:</span><el-input style="width:20%" placeholder="" :readonly="true" :value="getNumberString(item)"/>
|
||||
<!--<span style="margin-left: 10px">热量:</span><el-input style="width:15%" type="number" placeholder="" v-model="item.heatValue"/><span>千卡</span>-->
|
||||
<span style="margin-left: 10px">蛋白质/脂肪/碳水:</span>
|
||||
<el-input style="width:10%" placeholder="" v-model="item.proteinQuality"/>
|
||||
<el-input style="width:10%;margin-left: 5px" placeholder="" v-model="item.fatQuality"/>
|
||||
<el-input style="width:10%;margin-left: 5px" placeholder="" v-model="item.carbonWaterQuality"/>
|
||||
<span style="margin-left: 5px">克</span>
|
||||
</div>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
@ -29,6 +34,7 @@
|
||||
},
|
||||
props: {},
|
||||
data() {
|
||||
|
||||
return {
|
||||
// 弹出层标题
|
||||
title: "",
|
||||
@ -62,7 +68,7 @@
|
||||
getFoodHeatStatistics(id).then((response) => {
|
||||
//let contractDetail = response.data;
|
||||
this.heatData = response.data;
|
||||
this.foodHeatList = response.data.foodHeatStatisticsList != null ? response.data.foodHeatStatisticsList : [];
|
||||
this.foodHeatList = response.data.foodHeatStatisticsList != null ? response.data.foodHeatStatisticsList : [];
|
||||
});
|
||||
},
|
||||
getNumberString(foodData){
|
||||
@ -87,23 +93,34 @@
|
||||
},
|
||||
/** 提交按钮 */
|
||||
submitForm() {
|
||||
var reg = /^([1-9]\d*|[0]{1,1})$/;
|
||||
if(this.foodHeatList.length == 0){
|
||||
return;
|
||||
}
|
||||
let obj = {};
|
||||
obj.foodHeatIdList = [];
|
||||
obj.foodHeatList = [];
|
||||
obj.id = this.heatData.id;
|
||||
obj.customerId = this.heatData.customerId;
|
||||
obj.maxHeatValue = this.heatData.maxHeatValue;
|
||||
obj.foodHeatIdList = [];
|
||||
obj.proteinQualityList = [];
|
||||
obj.fatQualityList = [];
|
||||
obj.carbonWaterQualityList = [];
|
||||
let verifyFlag = true;
|
||||
this.foodHeatList.forEach((item,index) => {
|
||||
obj.foodHeatIdList.push(item.id);
|
||||
if(!/^[1-9]\d*$/.test(item.heatValue)){
|
||||
obj.foodHeatList.push(0);
|
||||
if(!reg.test(item.proteinQuality) || !reg.test(item.fatQuality) || !reg.test(item.carbonWaterQuality)){
|
||||
verifyFlag = false;
|
||||
}else{
|
||||
obj.foodHeatList.push(item.heatValue);
|
||||
obj.proteinQualityList.push(item.proteinQuality);
|
||||
obj.fatQualityList.push(item.fatQuality);
|
||||
obj.carbonWaterQualityList.push(item.carbonWaterQuality);
|
||||
}
|
||||
});
|
||||
console.log(obj.foodHeatIdList.length);
|
||||
if(!verifyFlag){
|
||||
this.$message({message: "填写的数值格式错误", type: "warning"});
|
||||
return;
|
||||
}
|
||||
//console.log(obj.foodHeatIdList.length);
|
||||
addFoodHeatData(obj).then(response => {
|
||||
if (response.code === 200) {
|
||||
this.msgSuccess("提交成功");
|
||||
|
@ -27,7 +27,7 @@
|
||||
</el-table-column>
|
||||
<el-table-column label="质量(克)" align="center" prop="quantity" />-->
|
||||
|
||||
<el-table-column label="最大摄入量" align="center" prop="maxHeatValue" />
|
||||
<el-table-column label="可摄入量" align="center" prop="maxHeatValue" />
|
||||
<el-table-column label="食材热量" align="center" prop="heatValue" />
|
||||
<el-table-column label="热量缺口" align="center" prop="heatGap" />
|
||||
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
|
||||
|
@ -35,6 +35,16 @@
|
||||
</el-tag>
|
||||
</el-form-item>
|
||||
<div>
|
||||
<el-form-item label="日期" prop="edibleDate">
|
||||
<el-date-picker
|
||||
v-model="form.edibleDate"
|
||||
type="date"
|
||||
format="yyyy-MM-dd"
|
||||
value-format="yyyy-MM-dd"
|
||||
:picker-options="pickerOptions"
|
||||
placeholder="选择日期">
|
||||
</el-date-picker>
|
||||
</el-form-item>
|
||||
<el-form-item label="食材名称" prop="ingredient">
|
||||
<el-input v-model="form.ingredient" placeholder="请输入食材名称" maxlength="20"/>
|
||||
</el-form-item>
|
||||
@ -64,6 +74,8 @@
|
||||
</template>
|
||||
<script>
|
||||
import { getDictData,getCustomerBaseMessage,addFoodHeatStatistics } from "@/api/custom/customerInvestigation";
|
||||
import dayjs from "dayjs";
|
||||
const nowDate = dayjs().format("YYYY-MM-DD");
|
||||
const logo = require("@/assets/logo/st_logo.png");
|
||||
export default {
|
||||
name: "index",
|
||||
@ -93,6 +105,7 @@
|
||||
phone: null
|
||||
},
|
||||
form: {
|
||||
edibleDate: nowDate,
|
||||
ingredient: null,
|
||||
number: null,
|
||||
unit: null,
|
||||
@ -100,9 +113,7 @@
|
||||
},
|
||||
rules: {
|
||||
ingredient: [{ required: true, trigger: "blur", message: "请输入食材名称" }],
|
||||
/*numberUnit: [
|
||||
{ required: false, trigger: "blur", validator: checkNumberUnit }
|
||||
],*/
|
||||
edibleDate: [{ required: true, trigger: "blur", message: "请选择日期" }]
|
||||
},
|
||||
ingredientTagArray:[
|
||||
|
||||
@ -111,7 +122,12 @@
|
||||
|
||||
],
|
||||
//通俗计量单位
|
||||
cusUnitOptions:[]
|
||||
cusUnitOptions:[],
|
||||
pickerOptions: {
|
||||
disabledDate(time) {
|
||||
return time.getTime() > Date.now();
|
||||
},
|
||||
},
|
||||
};
|
||||
},
|
||||
components: {
|
||||
@ -158,8 +174,9 @@
|
||||
});
|
||||
},
|
||||
verify(){
|
||||
var reg = /^([1-9]\d*|[0]{1,1})$/;
|
||||
if(this.form.number != null && this.form.number != ""){
|
||||
if(!/^[1-9]\d*$/.test(this.form.number+"")){
|
||||
if(!reg.test(this.form.number+"")){
|
||||
this.$message({message: "通俗计量的数量格式错误", type: "warning"});
|
||||
return false;
|
||||
}
|
||||
@ -168,7 +185,7 @@
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if(this.form.quantity != null && this.form.quantity != "" && !/^[1-9]\d*$/.test(this.form.quantity)){
|
||||
if(this.form.quantity != null && this.form.quantity != "" && !reg.test(this.form.quantity)){
|
||||
this.$message({message: "重量格式错误", type: "warning"});
|
||||
return false;
|
||||
}
|
||||
@ -180,6 +197,7 @@
|
||||
},
|
||||
reset(){
|
||||
this.form = {
|
||||
edibleDate: nowDate,
|
||||
ingredient: null,
|
||||
number: null,
|
||||
unit: null,
|
||||
@ -192,13 +210,15 @@
|
||||
submit(){
|
||||
if (this.submitFlag) {
|
||||
this.$message({
|
||||
message: "请勿频繁提交,1分钟后重试",
|
||||
message: "请勿频繁提交,一分钟后重试",
|
||||
type: "warning",
|
||||
});
|
||||
return;
|
||||
}
|
||||
this.timer = setTimeout(this.againSumbit,1000*60);
|
||||
if(this.form.ingredient && this.verify() && this.ingredientTagArray.indexOf(this.form.ingredient.trim()) == -1){
|
||||
if(this.form.ingredient && this.ingredientTagArray.indexOf(this.form.ingredient.trim()) == -1){
|
||||
if(!this.verify()){
|
||||
return;
|
||||
}
|
||||
this.ingredientArray.push(this.form);
|
||||
this.ingredientTagArray.push(this.form.ingredient);
|
||||
this.reset();
|
||||
@ -207,6 +227,7 @@
|
||||
this.$message({message: "还未添加食材数据,无法提交", type: "warning"});
|
||||
return;
|
||||
}
|
||||
this.timer = setTimeout(this.againSumbit,1000*60);
|
||||
let submitObject = {};
|
||||
submitObject.ingredientArray = JSON.stringify(this.ingredientArray);
|
||||
submitObject.customerEncId = this.customer.customerEncId;
|
||||
|
Reference in New Issue
Block a user