外食计算器功能优化修改
This commit is contained in:
@ -51,3 +51,13 @@ export function exportFoodHeatStatistics(query) {
|
||||
params: query
|
||||
})
|
||||
}
|
||||
|
||||
// 新增外食热量统计
|
||||
export function addFoodHeatData(data) {
|
||||
return request({
|
||||
url: '/custom/foodHeatStatistics/addFoodHeatData',
|
||||
method: 'post',
|
||||
data: data
|
||||
})
|
||||
}
|
||||
|
||||
|
117
stdiet-ui/src/components/HeatStatisticsCalculate/index.vue
Normal file
117
stdiet-ui/src/components/HeatStatisticsCalculate/index.vue
Normal file
@ -0,0 +1,117 @@
|
||||
<template>
|
||||
<!-- 计算食材热量对话框 -->
|
||||
<el-dialog :title="title" :visible.sync="open" width="750px" 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>
|
||||
</div>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<div slot="footer" class="dialog-footer">
|
||||
<el-button type="primary" @click="submitForm">确 定</el-button>
|
||||
<el-button @click="cancel">取 消</el-button>
|
||||
</div>
|
||||
</el-dialog>
|
||||
</template>
|
||||
<script>
|
||||
|
||||
import { getFoodHeatStatistics,addFoodHeatData } from "@/api/custom/foodHeatStatistics";
|
||||
import {getOptions} from "@/api/custom/order";
|
||||
|
||||
export default {
|
||||
name: "index",
|
||||
components: {
|
||||
|
||||
},
|
||||
props: {},
|
||||
data() {
|
||||
return {
|
||||
// 弹出层标题
|
||||
title: "",
|
||||
// 是否显示弹出层
|
||||
open: false,
|
||||
callback: undefined,
|
||||
// 表单参数
|
||||
form: {},
|
||||
// 表单校验
|
||||
rules: {
|
||||
projectId:[
|
||||
{required: true, message: "请选择调理项目", trigger: "blur"}
|
||||
]
|
||||
},
|
||||
heatData: null,
|
||||
foodHeatList: []
|
||||
};
|
||||
},
|
||||
created() {
|
||||
|
||||
},
|
||||
methods: {
|
||||
showDialog(data, callback) {
|
||||
this.callback = callback;
|
||||
this.reset(data);
|
||||
this.title = "计算"+`「${data.edibleDate}」食材热量`;
|
||||
this.open = true;
|
||||
this.getFoodHeatList(data.id);
|
||||
},
|
||||
getFoodHeatList(id){
|
||||
getFoodHeatStatistics(id).then((response) => {
|
||||
//let contractDetail = response.data;
|
||||
this.heatData = response.data;
|
||||
this.foodHeatList = response.data.foodHeatStatisticsList != null ? response.data.foodHeatStatisticsList : [];
|
||||
});
|
||||
},
|
||||
getNumberString(foodData){
|
||||
let numberString = "";
|
||||
if(foodData.number){
|
||||
numberString += foodData.number + foodData.unitName;
|
||||
}
|
||||
if(foodData.quantity){
|
||||
numberString += (numberString != "" ? "/" : "" ) + foodData.quantity + "克";
|
||||
}
|
||||
return numberString;
|
||||
},
|
||||
// 表单重置
|
||||
reset(obj) {
|
||||
this.heatData = null;
|
||||
this.foodHeatList = [];
|
||||
this.resetForm("form");
|
||||
},
|
||||
// 取消按钮
|
||||
cancel() {
|
||||
this.open = false;
|
||||
},
|
||||
/** 提交按钮 */
|
||||
submitForm() {
|
||||
if(this.foodHeatList.length == 0){
|
||||
return;
|
||||
}
|
||||
let obj = {};
|
||||
obj.foodHeatIdList = [];
|
||||
obj.foodHeatList = [];
|
||||
obj.id = this.heatData.id;
|
||||
obj.customerId = this.heatData.customerId;
|
||||
this.foodHeatList.forEach((item,index) => {
|
||||
obj.foodHeatIdList.push(item.id);
|
||||
if(!/^[1-9]\d*$/.test(item.heatValue)){
|
||||
obj.foodHeatList.push(0);
|
||||
}else{
|
||||
obj.foodHeatList.push(item.heatValue);
|
||||
}
|
||||
});
|
||||
console.log(obj.foodHeatIdList.length);
|
||||
addFoodHeatData(obj).then(response => {
|
||||
if (response.code === 200) {
|
||||
this.msgSuccess("提交成功");
|
||||
this.open = false;
|
||||
this.callback && this.callback();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
@ -19,16 +19,16 @@
|
||||
<span>{{ parseTime(scope.row.edibleDate, '{y}-{m}-{d}') }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="食材" align="center" prop="ingredient" />
|
||||
<el-table-column label="通俗质量" align="center" prop="unitName">
|
||||
<!-- <el-table-column label="食材" align="center" prop="ingredient" />
|
||||
<el-table-column label="通俗计量" align="center" prop="unitName">
|
||||
<template slot-scope="scope">
|
||||
{{ scope.row.number + "" + scope.row.unitName }}
|
||||
{{ scope.row.number ? (scope.row.number + "" + (scope.row.unitName != null ? scope.row.unitName : "")) : "" }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="质量(克)" align="center" prop="quantity" />
|
||||
<el-table-column label="质量(克)" align="center" prop="quantity" />-->
|
||||
|
||||
<!--<el-table-column label="类型,0早 1中 2晚" align="center" prop="edibleType" />-->
|
||||
<el-table-column label="热量数值" align="center" prop="heatValue" />
|
||||
<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">
|
||||
<template slot-scope="scope">
|
||||
@ -39,6 +39,12 @@
|
||||
@click="handleUpdate(scope.row)"
|
||||
v-hasPermi="['custom:foodHeatStatistics:edit']"
|
||||
>修改</el-button>-->
|
||||
<el-button
|
||||
size="mini"
|
||||
type="text"
|
||||
icon="el-icon-edit"
|
||||
@click="handleCalculate(scope.row)"
|
||||
>计算</el-button>
|
||||
<el-button
|
||||
size="mini"
|
||||
type="text"
|
||||
@ -58,6 +64,8 @@
|
||||
@pagination="fetchHeatList"
|
||||
/>
|
||||
|
||||
<heatStatisticsCalculate ref="heatStatisticsCalculateRef"></heatStatisticsCalculate>
|
||||
|
||||
</div>
|
||||
</el-drawer>
|
||||
</div>
|
||||
@ -65,9 +73,11 @@
|
||||
<script>
|
||||
import { listFoodHeatStatistics, getFoodHeatStatistics, delFoodHeatStatistics, addFoodHeatStatistics, updateFoodHeatStatistics, exportFoodHeatStatistics } from "@/api/custom/foodHeatStatistics";
|
||||
import Clipboard from 'clipboard';
|
||||
import HeatStatisticsCalculate from "@/components/HeatStatisticsCalculate";
|
||||
export default {
|
||||
name: "HeatStatisticsDrawer",
|
||||
components: {
|
||||
'heatStatisticsCalculate':HeatStatisticsCalculate
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
@ -137,6 +147,11 @@ export default {
|
||||
message: '拷贝成功',
|
||||
type: 'success'
|
||||
});
|
||||
},
|
||||
handleCalculate(data){
|
||||
this.$refs.heatStatisticsCalculateRef.showDialog(data,() => {
|
||||
this.fetchHeatList();
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
|
@ -370,6 +370,7 @@
|
||||
if (response.code === 200) {
|
||||
this.msgSuccess("新增成功");
|
||||
this.open = false;
|
||||
this.reset();
|
||||
this.getList();
|
||||
}
|
||||
});
|
||||
|
@ -13,51 +13,52 @@
|
||||
<h3>个人信息</h3>
|
||||
<!--<div><span>{{form.name}}</span></div>-->
|
||||
</div>
|
||||
<el-form-item label="真实姓名" prop="name">
|
||||
<el-input v-model="customer.name" :readonly="true" placeholder="请输入真实姓名" maxlength="20"/>
|
||||
<el-form-item :label="'姓名:'+customer.name" prop="name">
|
||||
<!--<el-input v-model="customer.name" :readonly="true" placeholder="请输入真实姓名" maxlength="20"/>-->
|
||||
</el-form-item>
|
||||
<el-form-item :label="'手机号:'+customer.phone" prop="phone" style="margin-top: -15px">
|
||||
<!--<el-input v-model="customer.name" :readonly="true" placeholder="请输入真实姓名" maxlength="20"/>-->
|
||||
</el-form-item>
|
||||
<div>
|
||||
<h3>食材记录</h3>
|
||||
<!--<div><span>{{form.name}}</span></div>-->
|
||||
<h3>外食计算</h3>
|
||||
</div>
|
||||
<el-form-item label="已添加的食材" prop="name">
|
||||
<el-tag style="margin-left: 5px"
|
||||
v-for="tag in ingredientTagArray"
|
||||
:key="tag"
|
||||
closable
|
||||
:disable-transitions="false"
|
||||
@close="handleClose(tag)"
|
||||
>
|
||||
{{tag}}
|
||||
</el-tag>
|
||||
<!--<el-tag class="el-icon-plus" style="margin-left: 5px">
|
||||
添加
|
||||
</el-tag>-->
|
||||
</el-form-item>
|
||||
<div>
|
||||
<el-form-item label="食材名称" prop="ingredient">
|
||||
<el-input v-model="form.ingredient" placeholder="请输入食材名称" maxlength="50"/>
|
||||
<el-row>
|
||||
<el-button v-for="(item,index) in modular" type="primary" plain @click="modularChange(index)">{{item}}</el-button>
|
||||
</el-row>
|
||||
<div style="margin-top: 40px">
|
||||
<h3>{{currentTitle}}</h3>
|
||||
</div>
|
||||
<div v-show="currentShow == 0">
|
||||
<el-form-item label="已添加的食材" prop="name">
|
||||
<el-tag style="margin-left: 5px" v-for="tag in ingredientTagArray" :key="tag" closable :disable-transitions="false" @close="handleClose(tag)">
|
||||
{{tag}}
|
||||
</el-tag>
|
||||
</el-form-item>
|
||||
<el-form-item label="通俗计量" prop="numberUnit">
|
||||
<el-input-number v-model="form.number" controls-position="right" :controls="false" style="width: 48%" placeholder="请输入食材数量" :step="1" :max="100"></el-input-number>
|
||||
<el-select v-model="form.unit" placeholder="请选择单位" style="margin-left:5px;width: 50%" filterable clearable>
|
||||
<el-option
|
||||
v-for="dict in cusUnitOptions"
|
||||
:key="dict.dictValue"
|
||||
:label="dict.dictLabel"
|
||||
:value="parseInt(dict.dictValue)"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="重量(克)" prop="quantity">
|
||||
<el-input type="number" v-model="form.quantity" placeholder="请输入食材重量(整数)" maxlength="10"/>
|
||||
<div>
|
||||
<el-form-item label="食材名称" prop="ingredient">
|
||||
<el-input v-model="form.ingredient" placeholder="请输入食材名称" maxlength="20"/>
|
||||
</el-form-item>
|
||||
<el-form-item label="通俗计量" prop="numberUnit">
|
||||
<el-input v-model="form.number" style="width: 48%" placeholder="请输入食材数量" maxlength="10"/>
|
||||
<el-select v-model="form.unit" placeholder="请选择单位" style="margin-left:5px;width: 50%" filterable clearable>
|
||||
<el-option
|
||||
v-for="dict in cusUnitOptions"
|
||||
:key="dict.dictValue"
|
||||
:label="dict.dictLabel"
|
||||
:value="parseInt(dict.dictValue)"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="重量(克)" prop="quantity">
|
||||
<el-input v-model="form.quantity" placeholder="请输入食材重量(整数)" maxlength="10"/>
|
||||
</el-form-item>
|
||||
</div>
|
||||
<el-form-item style="text-align: center; margin: 40px auto" >
|
||||
<el-button type="primary" @click="continueAdd()" >继续添加</el-button>
|
||||
<el-button type="success" @click="submit()" >提交数据</el-button>
|
||||
</el-form-item>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<el-form-item style="text-align: center; margin: 40px auto" >
|
||||
<el-button type="primary" @click="continueAdd()" >继续添加</el-button>
|
||||
<el-button type="success" @click="submit()" >提交数据</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</section>
|
||||
</template>
|
||||
@ -67,7 +68,21 @@
|
||||
export default {
|
||||
name: "index",
|
||||
data() {
|
||||
const checkNumberUnit = (rule, value, callback) => {
|
||||
if (this.form.number) {
|
||||
if(!/^[1-9]\d*$/.test(value)){
|
||||
return callback(new Error("通俗计量的数量格式错误"));
|
||||
}
|
||||
if(!this.form.unit){
|
||||
return callback(new Error("请选择通俗计量单位"));
|
||||
}
|
||||
}
|
||||
callback();
|
||||
};
|
||||
return {
|
||||
modular:["食材提交"],
|
||||
currentShow: -1,
|
||||
currentTitle: "",
|
||||
logo,
|
||||
timer: null,
|
||||
customerExistFlag: false,
|
||||
@ -79,12 +94,15 @@
|
||||
},
|
||||
form: {
|
||||
ingredient: null,
|
||||
number: 0,
|
||||
number: null,
|
||||
unit: null,
|
||||
quantity: null,
|
||||
},
|
||||
rules: {
|
||||
ingredient: [{ required: true, trigger: "blur", message: "请输入食材名称" }]
|
||||
ingredient: [{ required: true, trigger: "blur", message: "请输入食材名称" }],
|
||||
/*numberUnit: [
|
||||
{ required: false, trigger: "blur", validator: checkNumberUnit }
|
||||
],*/
|
||||
},
|
||||
ingredientTagArray:[
|
||||
|
||||
@ -100,6 +118,15 @@
|
||||
|
||||
},
|
||||
methods: {
|
||||
modularChange(index){
|
||||
if(index != this.currentShow){
|
||||
this.currentShow = index;
|
||||
this.currentTitle = this.modular[index];
|
||||
}else{
|
||||
this.currentShow = -1;
|
||||
this.currentTitle = "";
|
||||
}
|
||||
},
|
||||
//根据用户ID获取用户基本信息(手机号、姓名)
|
||||
getCustomerBase(id){
|
||||
if(id == null || id == undefined){
|
||||
@ -120,7 +147,7 @@
|
||||
continueAdd(){
|
||||
this.$refs.form.validate((valid) => {
|
||||
if (valid) {
|
||||
if(this.ingredientTagArray.indexOf(this.form.ingredient.trim()) == -1){
|
||||
if(this.verify() && this.ingredientTagArray.indexOf(this.form.ingredient.trim()) == -1){
|
||||
this.ingredientArray.push(this.form);
|
||||
this.ingredientTagArray.push(this.form.ingredient);
|
||||
this.reset();
|
||||
@ -130,26 +157,48 @@
|
||||
}
|
||||
});
|
||||
},
|
||||
verify(){
|
||||
if(this.form.number != null && this.form.number != ""){
|
||||
if(!/^[1-9]\d*$/.test(this.form.number+"")){
|
||||
this.$message({message: "通俗计量的数量格式错误", type: "warning"});
|
||||
return false;
|
||||
}
|
||||
if(this.form.unit == null || this.form.unit == ""){
|
||||
this.$message({message: "请选择通俗计量单位", type: "warning"});
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if(this.form.quantity != null && this.form.quantity != "" && !/^[1-9]\d*$/.test(this.form.quantity)){
|
||||
this.$message({message: "重量格式错误", type: "warning"});
|
||||
return false;
|
||||
}
|
||||
if((this.form.number == null || this.form.number == "") && (this.form.quantity == null || this.form.quantity == "")){
|
||||
this.$message({message: "通俗计量和重量不能都为空", type: "warning"});
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
reset(){
|
||||
this.form = {
|
||||
ingredient: null,
|
||||
number: 0,
|
||||
number: null,
|
||||
unit: null,
|
||||
quantity: null
|
||||
}
|
||||
},
|
||||
againSumbit(){
|
||||
this.submitFlag = false;
|
||||
},
|
||||
submit(){
|
||||
if (this.submitFlag) {
|
||||
this.$message({
|
||||
message: "请勿重复提交,1分钟后重试",
|
||||
message: "请勿频繁提交,1分钟后重试",
|
||||
type: "warning",
|
||||
});
|
||||
return;
|
||||
}
|
||||
this.timer = setTimeout(function(){
|
||||
this.submitFlag = false;
|
||||
},1000*60);
|
||||
if(this.form.ingredient && this.ingredientTagArray.indexOf(this.form.ingredient.trim()) == -1){
|
||||
this.timer = setTimeout(this.againSumbit,1000*60);
|
||||
if(this.form.ingredient && this.verify() && this.ingredientTagArray.indexOf(this.form.ingredient.trim()) == -1){
|
||||
this.ingredientArray.push(this.form);
|
||||
this.ingredientTagArray.push(this.form.ingredient);
|
||||
this.reset();
|
||||
|
Reference in New Issue
Block a user