|
|
@@ -57,30 +57,43 @@
|
|
|
<el-autocomplete
|
|
|
class="inline-input"
|
|
|
v-model="params.unit"
|
|
|
- :fetch-suggestions="queryNutrientUnits"
|
|
|
+ :fetch-suggestions="(query, cb) => {queryNutrientUnits(query, params.nutrientId, cb)}"
|
|
|
+ @input="handleUnitChanged"
|
|
|
placeholder="单位关键词"
|
|
|
/>
|
|
|
- NRV%:
|
|
|
- <el-input
|
|
|
- v-model="params.nrvPercent"
|
|
|
- style="width: 80px;"
|
|
|
- class="filter-item"
|
|
|
- />
|
|
|
+ <div v-show="showNutrientSource" style="display: inline-block">
|
|
|
+ <el-select
|
|
|
+ v-model="params.nutrientSource"
|
|
|
+ placeholder="请选择营养素来源"
|
|
|
+ >
|
|
|
+ <el-option v-for="item in nutrientSources" :key="item" :label="item" :value="item" />
|
|
|
+ </el-select>
|
|
|
+ </div>
|
|
|
+ <div v-show="showNRV" style="display: inline-block">
|
|
|
+ NRV%:
|
|
|
+ <el-input
|
|
|
+ v-model="params.nrvPercent"
|
|
|
+ style="width: 80px;"
|
|
|
+ class="filter-item"
|
|
|
+ />
|
|
|
+ </div>
|
|
|
</el-row>
|
|
|
<el-row style="margin-top: 10px">
|
|
|
- Nv_Spec计量:
|
|
|
- <el-input
|
|
|
- v-model="params.nvSpec"
|
|
|
- style="width: 80px;"
|
|
|
- class="filter-item"
|
|
|
- @focus="getInputFocus"
|
|
|
- />
|
|
|
- <el-autocomplete
|
|
|
- class="inline-input"
|
|
|
- v-model="params.nvSpecUnit"
|
|
|
- :fetch-suggestions="queryUnits"
|
|
|
- placeholder="单位关键词"
|
|
|
- />
|
|
|
+ <div v-show="!isPercentByVolumeUnit(params)" style="display: inline-block">
|
|
|
+ Nv_Spec计量:
|
|
|
+ <el-input
|
|
|
+ v-model="params.nvSpec"
|
|
|
+ style="width: 80px;"
|
|
|
+ class="filter-item"
|
|
|
+ @focus="getInputFocus"
|
|
|
+ />
|
|
|
+ <el-autocomplete
|
|
|
+ class="inline-input"
|
|
|
+ v-model="params.nvSpecUnit"
|
|
|
+ :fetch-suggestions="queryUnits"
|
|
|
+ placeholder="单位关键词"
|
|
|
+ />
|
|
|
+ </div>
|
|
|
信息来源:
|
|
|
<el-autocomplete
|
|
|
v-model="params.source"
|
|
|
@@ -152,21 +165,34 @@
|
|
|
<el-table-column label="计量单位" align="center" width="150">
|
|
|
<template slot-scope="{row}">
|
|
|
<template v-if="row.edit">
|
|
|
- <el-autocomplete v-model="row.unit" :fetch-suggestions="queryUnits" placeholder="单位关键词" />
|
|
|
+ <el-autocomplete
|
|
|
+ v-model="row.unit"
|
|
|
+ @input="handleRowUnitChanged(row)"
|
|
|
+ :fetch-suggestions="(query, cb) => {queryNutrientUnits(query, row.nutrientId, cb)}"
|
|
|
+ placeholder="单位关键词"
|
|
|
+ />
|
|
|
+ <el-select
|
|
|
+ clearable
|
|
|
+ v-show="showRowNutrientSource"
|
|
|
+ v-model="row.nutrientSource"
|
|
|
+ placeholder="请选择营养素来源"
|
|
|
+ >
|
|
|
+ <el-option v-for="item in nutrientSources" :key="item" :label="item" :value="item" />
|
|
|
+ </el-select>
|
|
|
</template>
|
|
|
- <span v-else>{{ row.unit }}</span>
|
|
|
+ <span v-else>{{ row.nutrientSource ? `${row.unit}(${row.nutrientSource})` : row.unit }}</span>
|
|
|
</template>
|
|
|
</el-table-column>
|
|
|
<el-table-column label="NRV%" align="center" width="80">
|
|
|
<template slot-scope="{row}">
|
|
|
<template v-if="row.edit">
|
|
|
- <el-input v-model="row.nrvPercent"/>
|
|
|
+ <el-input v-show="!isPercentByVolumeUnit(row)" v-model="row.nrvPercent"/>
|
|
|
</template>
|
|
|
<span v-else>{{ row.nrvPercent }}</span>
|
|
|
</template>
|
|
|
</el-table-column>
|
|
|
<el-table-column label="Nv_Spec" align="center" width="80">
|
|
|
- <template slot-scope="{row}">
|
|
|
+ <template slot-scope="{row}" v-if="!isPercentByVolumeUnit(row)">
|
|
|
<template v-if="row.edit">
|
|
|
<el-input v-model="row.nvSpec" class="filter-item" @focus="getInputFocus" />
|
|
|
</template>
|
|
|
@@ -174,7 +200,7 @@
|
|
|
</template>
|
|
|
</el-table-column>
|
|
|
<el-table-column label="计量单位" align="center" width="150">
|
|
|
- <template slot-scope="{row}">
|
|
|
+ <template slot-scope="{row}" v-if="!isPercentByVolumeUnit(row)">
|
|
|
<template v-if="row.edit">
|
|
|
<el-autocomplete v-model="row.nvSpecUnit" :fetch-suggestions="queryUnits" placeholder="单位关键词" />
|
|
|
</template>
|
|
|
@@ -268,10 +294,13 @@ import { getNutrientList, addFoodNutrient, updateFoodNutrient, removeFoodNutrien
|
|
|
updateFoodNutrientSort, confirmDeleteFoodNutrient, importNutrientsFromTemplate,
|
|
|
getList as getFoodList, importNutrientFromSimilarFood } from '@/api/food'
|
|
|
import FloatingWindow from '@/components/FloatingWindow'
|
|
|
-import { getList, getNutrientUnits } from '@/api/nutrient'
|
|
|
+import { getList, getNutrientUnits, getNutrientSources } from '@/api/nutrient'
|
|
|
import { getList as getUnits } from '@/api/unit'
|
|
|
import { getNutrientTemplates } from '@/api/nutrientTemplate'
|
|
|
|
|
|
+// 特殊营养素 若单位不为baseUnit,则需要填写来源
|
|
|
+const SPECIAL_NUTRIENT_NAMES = ['维生素A', '维生素D', '维生素E', '烟酸', '叶酸']
|
|
|
+
|
|
|
export default {
|
|
|
name: 'AddNutrient',
|
|
|
components: { FloatingWindow },
|
|
|
@@ -320,7 +349,11 @@ export default {
|
|
|
importLoading: false,
|
|
|
importItems: [],
|
|
|
isFixed: false,
|
|
|
- offsetTop: 0
|
|
|
+ offsetTop: 0,
|
|
|
+ showNutrientSource: false,
|
|
|
+ showRowNutrientSource: false,
|
|
|
+ nutrientSources: [],
|
|
|
+ showNRV: false
|
|
|
}
|
|
|
},
|
|
|
methods: {
|
|
|
@@ -390,9 +423,9 @@ export default {
|
|
|
this.nutrients = []
|
|
|
})
|
|
|
},
|
|
|
- queryNutrientUnits(query, cb) {
|
|
|
+ queryNutrientUnits(query, nutrientId, cb) {
|
|
|
let units = []
|
|
|
- getNutrientUnits(this.params.nutrientId).then(res => {
|
|
|
+ getNutrientUnits(nutrientId, { query }).then(res => {
|
|
|
res.data.forEach(item => units.push({ value: item }))
|
|
|
cb(units)
|
|
|
})
|
|
|
@@ -431,6 +464,7 @@ export default {
|
|
|
} else {
|
|
|
this.$set(row, 'radio', 0)
|
|
|
}
|
|
|
+ this.handleRowUnitChanged(row)
|
|
|
},
|
|
|
radioChange(row) {
|
|
|
this.$set(row, 'stdError', '')
|
|
|
@@ -442,6 +476,11 @@ export default {
|
|
|
for (let nutrient of this.nutrients) {
|
|
|
if (nutrient.id === value) {
|
|
|
this.$set(this.params, 'unit', nutrient.baseUnit)
|
|
|
+ if (nutrient.nrvUnit) {
|
|
|
+ this.showNRV = true
|
|
|
+ } else {
|
|
|
+ this.showNRV = false
|
|
|
+ }
|
|
|
break
|
|
|
}
|
|
|
}
|
|
|
@@ -526,6 +565,57 @@ export default {
|
|
|
if (path) {
|
|
|
this.$router.push({ path: path })
|
|
|
}
|
|
|
+ },
|
|
|
+ isPercentByVolumeUnit(row) {
|
|
|
+ return row && row.unit === '%Vol'
|
|
|
+ },
|
|
|
+ isSpecialNutrient(nutrientId) {
|
|
|
+ let nutrient = null
|
|
|
+ for (let i = 0; i < this.nutrients.length; i++) {
|
|
|
+ if (this.nutrients[i].id === nutrientId) {
|
|
|
+ nutrient = this.nutrients[i]
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果特殊营养素单位不等于baseUnit,则显示来源
|
|
|
+ return nutrient && SPECIAL_NUTRIENT_NAMES.indexOf(nutrient.name) > -1
|
|
|
+ },
|
|
|
+ handleUnitChanged() {
|
|
|
+ if (this.isSpecialNutrient(this.params.nutrientId)) {
|
|
|
+ getNutrientSources(this.params.nutrientId, { unit: this.params.unit }).then(res => {
|
|
|
+ this.nutrientSources = res.data
|
|
|
+ if (this.nutrientSources.length > 0){
|
|
|
+ this.params.nutrientSource = this.nutrientSources[0]
|
|
|
+ this.showNutrientSource = true
|
|
|
+ } else {
|
|
|
+ this.showNutrientSource = false
|
|
|
+ this.params.nutrientSource = null
|
|
|
+ }
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ this.showNutrientSource = false
|
|
|
+ this.params.nutrientSource = null
|
|
|
+ }
|
|
|
+ },
|
|
|
+ handleRowUnitChanged(row) {
|
|
|
+ if (SPECIAL_NUTRIENT_NAMES.indexOf(row.nutrientName) > -1) {
|
|
|
+ getNutrientSources(row.nutrientId, { unit: row.unit }).then(res => {
|
|
|
+ this.nutrientSources = res.data
|
|
|
+ if (this.nutrientSources.length > 0){
|
|
|
+ if (!row.nutrientSource) {
|
|
|
+ row.nutrientSource = this.nutrientSources[0]
|
|
|
+ }
|
|
|
+ this.showRowNutrientSource = true
|
|
|
+ } else {
|
|
|
+ this.showRowNutrientSource = false
|
|
|
+ row.nutrientSource = null
|
|
|
+ }
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ this.showRowNutrientSource = false
|
|
|
+ row.nutrientSource = null
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|