|
|
@@ -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;"
|
|
|
@@ -77,21 +64,62 @@
|
|
|
<span>{{ row.nutrientName }}</span>
|
|
|
</template>
|
|
|
</el-table-column>
|
|
|
- <el-table-column label="营养素计量" align="center" width="200">
|
|
|
+ <el-table-column label="营养素计量" align="center" width="80">
|
|
|
<template slot-scope="{row}">
|
|
|
- <span>{{ row.quantity + row.unit }}</span>
|
|
|
+ <template v-if="row.edit">
|
|
|
+ <el-input v-model="row.quantity" class="filter-item" />
|
|
|
+ </template>
|
|
|
+ <span v-else>{{ row.quantity }}</span>
|
|
|
</template>
|
|
|
</el-table-column>
|
|
|
- <el-table-column label="Nv_Spec" align="center" width="200">
|
|
|
+ <el-table-column label="计量单位" align="center" width="150">
|
|
|
<template slot-scope="{row}">
|
|
|
- <span>{{ row.nvSpec + row.nvSpecUnit }}</span>
|
|
|
+ <template v-if="row.edit">
|
|
|
+ <el-autocomplete v-model="row.unit" :fetch-suggestions="queryUnits" placeholder="单位关键词" />
|
|
|
+ </template>
|
|
|
+ <span v-else>{{ row.unit }}</span>
|
|
|
</template>
|
|
|
</el-table-column>
|
|
|
- <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="100">
|
|
|
+ <el-table-column label="Nv_Spec" align="center" width="80">
|
|
|
<template slot-scope="{row}">
|
|
|
- <el-button size="mini" type="danger" @click="removeNutrient(row)">
|
|
|
- 删除
|
|
|
- </el-button>
|
|
|
+ <template v-if="row.edit">
|
|
|
+ <el-input v-model="row.nvSpec" class="filter-item" />
|
|
|
+ </template>
|
|
|
+ <span v-else>{{ row.nvSpec }}</span>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column label="计量单位" align="center" width="150">
|
|
|
+ <template slot-scope="{row}">
|
|
|
+ <template v-if="row.edit">
|
|
|
+ <el-autocomplete v-model="row.nvSpecUnit" :fetch-suggestions="queryUnits" placeholder="单位关键词" />
|
|
|
+ </template>
|
|
|
+ <span v-else>{{ row.nvSpecUnit }}</span>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="160">
|
|
|
+ <template slot-scope="{row}">
|
|
|
+ <template v-if="row.edit">
|
|
|
+ <el-button
|
|
|
+ type="success"
|
|
|
+ size="mini"
|
|
|
+ @click="confirmEdit(row)"
|
|
|
+ >
|
|
|
+ 提交
|
|
|
+ </el-button>
|
|
|
+ <el-button
|
|
|
+ type="danger"
|
|
|
+ size="mini"
|
|
|
+ @click="fetchData"
|
|
|
+ >
|
|
|
+ 取消
|
|
|
+ </el-button>
|
|
|
+ </template>
|
|
|
+ <template v-else>
|
|
|
+ <el-button size="mini" type="primary" @click="row.edit=true">编辑</el-button>
|
|
|
+ <el-button size="mini" type="danger" @click="removeNutrient(row)">
|
|
|
+ 删除
|
|
|
+ </el-button>
|
|
|
+ </template>
|
|
|
</template>
|
|
|
</el-table-column>
|
|
|
</el-table>
|
|
|
@@ -99,7 +127,7 @@
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
-import { getNutrientList, addFoodNutrient, removeFoodNutrient } from '@/api/food'
|
|
|
+import { getNutrientList, addFoodNutrient, updateFoodNutrient, removeFoodNutrient } from '@/api/food'
|
|
|
import { getList } from '@/api/nutrient'
|
|
|
import { getList as getUnits } from '@/api/unit'
|
|
|
|
|
|
@@ -108,6 +136,7 @@ export default {
|
|
|
created() {
|
|
|
this.foodId = this.$route.params && this.$route.params.id
|
|
|
this.fetchData()
|
|
|
+ this.queryNutrients()
|
|
|
},
|
|
|
mounted() {
|
|
|
this.$nextTick(() => {
|
|
|
@@ -134,18 +163,29 @@ 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)
|
|
|
+ })
|
|
|
+ },
|
|
|
+ confirmEdit(row) {
|
|
|
+ updateFoodNutrient(this.foodId, row.nutrientId, row).then(res => {
|
|
|
+ this.fetchData()
|
|
|
+ this.$notify.success('提交成功')
|
|
|
}).catch(res => {
|
|
|
this.$message.error(res.data.message)
|
|
|
})
|
|
|
@@ -166,13 +206,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>
|