优化展示
This commit is contained in:
@@ -278,7 +278,7 @@ import {PaginationDTO, Response} from '../enums';
|
||||
/**
|
||||
* @typedef {object} RecipeIngredientDto
|
||||
* @property {number} raw_material_id - 原料ID
|
||||
* @property {number} [percentage] - 原料在配方中的百分比 (0-1之间)
|
||||
* @property {number} [percentage] - 原料在配方中的百分比 (0-100之间)
|
||||
*/
|
||||
|
||||
/**
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
<el-table-column prop="name" label="原料名称" />
|
||||
<el-table-column prop="percentage" label="占比">
|
||||
<template #default="scope">
|
||||
{{ (scope.row.percentage * 100).toFixed(2) }}%
|
||||
{{ scope.row.percentage.toFixed(2) }}%
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
@@ -35,7 +35,7 @@
|
||||
<el-table-column prop="name" label="原料名称" />
|
||||
<el-table-column label="占比">
|
||||
<template #default="scope">
|
||||
<el-input-number v-model="scope.row.percentage" :min="0" :max="1" :step="0.01" :precision="2" @change="updateNutrientSummary"></el-input-number>
|
||||
<el-input-number v-model="scope.row.percentage" :min="0" :max="100" :step="1" :precision="2" @change="updateNutrientSummary"></el-input-number>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作">
|
||||
@@ -111,7 +111,7 @@ export default {
|
||||
ingredients.forEach(ing => {
|
||||
if (ing.raw_material_nutrients) {
|
||||
ing.raw_material_nutrients.forEach(nutrient => {
|
||||
const contribution = nutrient.value * ing.percentage;
|
||||
const contribution = nutrient.value * (ing.percentage / 100); // 修正:计算时需要将百分比转换为小数
|
||||
if (summary.has(nutrient.nutrient_name)) {
|
||||
summary.set(nutrient.nutrient_name, summary.get(nutrient.nutrient_name) + contribution);
|
||||
} else {
|
||||
@@ -213,11 +213,11 @@ export default {
|
||||
|
||||
// 保存配方
|
||||
const handleSaveRecipe = async () => {
|
||||
// 验证占比总和是否为1
|
||||
// 验证占比总和是否为100
|
||||
const totalPercentage = localIngredientDetails.value.reduce((sum, ing) => sum + ing.percentage, 0);
|
||||
|
||||
if (Math.abs(totalPercentage - 1) > 0.001) { // 允许浮点数误差
|
||||
ElMessage.error(`原料总占比必须为100%,当前为${(totalPercentage * 100).toFixed(2)}%`);
|
||||
if (Math.abs(totalPercentage - 100) > 0.001) { // 允许浮点数误差
|
||||
ElMessage.error(`原料总占比必须为100%,当前为${totalPercentage.toFixed(2)}%`);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user