|
|
@@ -90,7 +90,8 @@
|
|
|
|
|
|
<script>
|
|
|
import { getFoodModifiers, removeFoodModifier, updateFoodModifierSort, convertFoodUnit, getNutrientList,
|
|
|
- getDetail} from '@/api/food'
|
|
|
+ getDetail, calculateNutrientsContent } from '@/api/food'
|
|
|
+import { convertUnits } from '@/api/unit'
|
|
|
|
|
|
export default {
|
|
|
name: 'FoodModifierIndex',
|
|
|
@@ -148,28 +149,45 @@ export default {
|
|
|
this.$message.error(res.data.message)
|
|
|
})
|
|
|
},
|
|
|
- showDialog(row, column, event) {
|
|
|
- getNutrientList(row.foodId).then(res => {
|
|
|
- const nutrients = res.data
|
|
|
- convertFoodUnit(row.foodId, { fromUnit: row.inInitUnit }).then(res => {
|
|
|
- if (!res.data.ratio) {
|
|
|
- return;
|
|
|
- }
|
|
|
- this.dialogHtml = `转换关系:1${row.inInitUnit}${this.food.name}=${res.data.ratio}${this.food.normalizedUnit}${this.food.name}<br>`
|
|
|
- this.dialogHtml += `${row.inInit}${row.inInitUnit}${this.food.name}含有如下营养素:<br>`
|
|
|
- this.dialogHtml += `******************************<br>`
|
|
|
- for (let i=0; i < nutrients.length; i++) {
|
|
|
- const nutrient = nutrients[i]
|
|
|
- const quantity = nutrient.normalizedQuantity * res.data.ratio * row.inInit
|
|
|
- this.dialogHtml += `${nutrient.nutrientName}:${quantity}${nutrient.unit}。<br>`
|
|
|
- this.dialogHtml += `营养素计量为:${nutrient.quantity}${nutrient.unit}。Nv_Spec为:${nutrient.nvSpec}${nutrient.nvSpecUnit}。<br>`
|
|
|
- this.dialogHtml += `******************************<br>`
|
|
|
- }
|
|
|
- this.dialogFormVisible = true
|
|
|
- })
|
|
|
- }).catch(res => {
|
|
|
- this.$message.error('获取数据失败')
|
|
|
+ async showDialog(row, column, event) {
|
|
|
+ calculateNutrientsContent(row.foodId, { unit: row.inInitUnit, quantity: row.inInit }).then(res => {
|
|
|
+ this.dialogFormVisible = true
|
|
|
+ this.dialogHtml = res.data
|
|
|
})
|
|
|
+ // try {
|
|
|
+ // const nutrientRes = await getNutrientList(row.foodId)
|
|
|
+ // const nutrients = nutrientRes.data
|
|
|
+ // const foodUnitRes = await convertFoodUnit(row.foodId, { fromUnit: row.inInitUnit })
|
|
|
+ // const foodUnitRatio = foodUnitRes.data.ratio
|
|
|
+ // if (!foodUnitRatio) {
|
|
|
+ // this.dialogHtml = ''
|
|
|
+ // return
|
|
|
+ // }
|
|
|
+ // let unitPairs = []
|
|
|
+ // nutrients.forEach(item => unitPairs.push({ fromUnit: }))
|
|
|
+ // const convertedUnits = await convertUnits()
|
|
|
+ //
|
|
|
+ //
|
|
|
+ // } catch {
|
|
|
+ // this.$message.error('获取数据失败')
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // this.dialogHtml = `转换关系:1${row.inInitUnit}${this.food.name}=${res.data.ratio}${this.food.normalizedUnit}${this.food.name}<br>`
|
|
|
+ // this.dialogHtml += `${row.inInit}${row.inInitUnit}${this.food.name}含有如下营养素:<br>`
|
|
|
+ // this.dialogHtml += `******************************<br>`
|
|
|
+ // for (let i=0; i < nutrients.length; i++) {
|
|
|
+ // const nutrient = nutrients[i]
|
|
|
+ // const quantity = nutrient.normalizedQuantity * res.data.ratio * row.inInit
|
|
|
+ // this.dialogHtml += `${nutrient.nutrientName}:${quantity}${nutrient.unit}。<br>`
|
|
|
+ // this.dialogHtml += `营养素计量为:${nutrient.quantity}${nutrient.unit}。Nv_Spec为:${nutrient.nvSpec}${nutrient.nvSpecUnit}。<br>`
|
|
|
+ // this.dialogHtml += `******************************<br>`
|
|
|
+ // }
|
|
|
+ // this.dialogFormVisible = true
|
|
|
+ // this.di
|
|
|
+ // })
|
|
|
+ // }).catch(res => {
|
|
|
+ // this.$message.error('获取数据失败')
|
|
|
+ // })
|
|
|
}
|
|
|
}
|
|
|
}
|