外食计算器功能优化修改

This commit is contained in:
xiezhijun
2021-02-20 19:38:17 +08:00
parent afdee0abdf
commit 3f3fcda862
15 changed files with 822 additions and 108 deletions

View 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>

View File

@ -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();
});
}
},
};