|
|
@@ -8,6 +8,7 @@
|
|
|
filterable
|
|
|
remote
|
|
|
reserve-keyword
|
|
|
+ :default-first-option="true"
|
|
|
style="width: 200px;margin-left: 10px;"
|
|
|
placeholder="请输入营养素关键词"
|
|
|
:remote-method="queryNutrients"
|
|
|
@@ -21,38 +22,24 @@
|
|
|
style="width: 80px;"
|
|
|
class="filter-item"
|
|
|
/>
|
|
|
- <el-select
|
|
|
+ <el-autocomplete
|
|
|
+ class="inline-input"
|
|
|
v-model="params.unit"
|
|
|
- style="width: 120px;margin-left: 10px;"
|
|
|
- class="filter-item"
|
|
|
- filterable
|
|
|
- remote
|
|
|
- reserve-keyword
|
|
|
+ :fetch-suggestions="queryUnits"
|
|
|
placeholder="单位关键词"
|
|
|
- :loading="unitLoading"
|
|
|
- :remote-method="queryUnits"
|
|
|
- >
|
|
|
- <el-option v-for="item in units" :key="`nutrient${item.id}`" :label="item.name" :value="item.name" />
|
|
|
- </el-select>
|
|
|
+ />
|
|
|
Nv_Spec计量:
|
|
|
<el-input
|
|
|
v-model="params.nvSpec"
|
|
|
style="width: 80px;"
|
|
|
class="filter-item"
|
|
|
/>
|
|
|
- <el-select
|
|
|
+ <el-autocomplete
|
|
|
+ class="inline-input"
|
|
|
v-model="params.nvSpecUnit"
|
|
|
- style="width: 120px;margin-left: 10px;"
|
|
|
- class="filter-item"
|
|
|
- filterable
|
|
|
- remote
|
|
|
- reserve-keyword
|
|
|
+ :fetch-suggestions="queryUnits"
|
|
|
placeholder="单位关键词"
|
|
|
- :loading="unitLoading"
|
|
|
- :remote-method="queryUnits"
|
|
|
- >
|
|
|
- <el-option v-for="item in units" :key="`nutrient${item.id}`" :label="item.name" :value="item.name" />
|
|
|
- </el-select>
|
|
|
+ />
|
|
|
<el-button
|
|
|
class="filter-item"
|
|
|
style="margin-left: 10px;"
|
|
|
@@ -108,6 +95,7 @@ export default {
|
|
|
created() {
|
|
|
this.foodId = this.$route.params && this.$route.params.id
|
|
|
this.fetchData()
|
|
|
+ this.queryNutrients()
|
|
|
},
|
|
|
mounted() {
|
|
|
this.$nextTick(() => {
|
|
|
@@ -134,18 +122,21 @@ export default {
|
|
|
this.list = res.data
|
|
|
this.listLoading = false
|
|
|
if (this.list.length > 0) {
|
|
|
- this.params.nvSpec = this.list[0].nvSpec
|
|
|
- this.params.nvSpecUnit = this.list[0].nvSpecUnit
|
|
|
+ this.$set(this.params, "nvSpec", this.list[0].nvSpec)
|
|
|
+ this.$set(this.params, "nvSpecUnit", this.list[0].nvSpecUnit)
|
|
|
+ } else {
|
|
|
+ this.$set(this.params, 'nvSpec', null)
|
|
|
+ this.$set(this.params, 'nvSpecUnit', null)
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
addNutrient() {
|
|
|
this.params.foodId = this.foodId
|
|
|
addFoodNutrient(this.foodId, this.params).then(res => {
|
|
|
- this.fetchData()
|
|
|
this.params = {}
|
|
|
+ this.fetchData()
|
|
|
this.$notify.success('添加营养素成功')
|
|
|
- this.$refs.firstInput.focus()
|
|
|
+ this.$refs.nutrientSelect.focus()
|
|
|
}).catch(res => {
|
|
|
this.$message.error(res.data.message)
|
|
|
})
|
|
|
@@ -166,13 +157,13 @@ export default {
|
|
|
this.nutrients = []
|
|
|
})
|
|
|
},
|
|
|
- queryUnits(query) {
|
|
|
+ queryUnits(query, cb) {
|
|
|
+ let units = []
|
|
|
getUnits({ query }).then(res => {
|
|
|
- this.units = res.data.list
|
|
|
- }).catch(() => {
|
|
|
- this.units = []
|
|
|
+ res.data.list.forEach(item => units.push({ value: item.name }))
|
|
|
+ cb(units)
|
|
|
})
|
|
|
- },
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
</script>
|