|
|
@@ -99,7 +99,7 @@
|
|
|
style="margin-left: 10px;"
|
|
|
type="success"
|
|
|
@click="handleImport">
|
|
|
- 从模板导入营养素
|
|
|
+ 导入营养素
|
|
|
</el-button>
|
|
|
</el-row>
|
|
|
</div>
|
|
|
@@ -231,20 +231,23 @@
|
|
|
</el-table-column>
|
|
|
</el-table>
|
|
|
|
|
|
- <el-dialog title="从模板导入营养素" :visible.sync="dialogFormVisible" v-loading="templateLoading">
|
|
|
- <el-form ref="dialogForm" label-position="left" label-width="60px" style="width: 80%; margin-left:50px;">
|
|
|
- <el-form-item label="模板:" prop="templateId">
|
|
|
+ <el-dialog title="导入营养素" :visible.sync="dialogFormVisible" v-loading="importLoading">
|
|
|
+ <el-form ref="dialogForm" label-position="left" style="width: 80%; margin-left:50px;">
|
|
|
+ <el-radio :label="0" v-model="importType" @change="handleImportTypeChange" >从模板导入</el-radio>
|
|
|
+ <el-radio :label="1" v-model="importType" @change="handleImportTypeChange" style="margin-bottom: 10px">从食物导入</el-radio>
|
|
|
+ <el-form-item prop="importId">
|
|
|
<el-select
|
|
|
- v-model="templateId"
|
|
|
+ v-model="importId"
|
|
|
class="filter-item"
|
|
|
filterable
|
|
|
remote
|
|
|
reserve-keyword
|
|
|
- placeholder="请输入模板关键词"
|
|
|
- :remote-method="queryTemplates"
|
|
|
+ placeholder="请输入关键词"
|
|
|
+ :loading="importLoading"
|
|
|
+ :remote-method="queryImportItems"
|
|
|
style="width: 100%"
|
|
|
>
|
|
|
- <el-option v-for="item in templates" :key="`template${item.id}`" :label="item.name" :value="item.id" />
|
|
|
+ <el-option v-for="item in importItems" :key="`import${item.id}`" :label="item.name" :value="item.id" />
|
|
|
</el-select>
|
|
|
</el-form-item>
|
|
|
</el-form>
|
|
|
@@ -252,7 +255,7 @@
|
|
|
<el-button @click="dialogFormVisible = false">
|
|
|
取消
|
|
|
</el-button>
|
|
|
- <el-button type="primary" @click="submitFromTemplate">
|
|
|
+ <el-button type="primary" @click="submitImport">
|
|
|
提交
|
|
|
</el-button>
|
|
|
</div>
|
|
|
@@ -262,7 +265,8 @@
|
|
|
|
|
|
<script>
|
|
|
import { getNutrientList, addFoodNutrient, updateFoodNutrient, removeFoodNutrient,
|
|
|
- updateFoodNutrientSort, confirmDeleteFoodNutrient, importNutrientsFromTemplate } from '@/api/food'
|
|
|
+ updateFoodNutrientSort, confirmDeleteFoodNutrient, importNutrientsFromTemplate,
|
|
|
+ getList as getFoodList, importNutrientFromSimilarFood } from '@/api/food'
|
|
|
import FloatingWindow from '@/components/FloatingWindow'
|
|
|
import { getList, getNutrientUnits } from '@/api/nutrient'
|
|
|
import { getList as getUnits } from '@/api/unit'
|
|
|
@@ -311,9 +315,10 @@ export default {
|
|
|
unitLoading: false,
|
|
|
sources: [{ value: "营养标签" }, { value: "食品官方资料" }, { value: "计算值" }],
|
|
|
dialogFormVisible: false,
|
|
|
- templateLoading: false,
|
|
|
- templateId: '',
|
|
|
- templates: [],
|
|
|
+ importType: 0,
|
|
|
+ importId: '',
|
|
|
+ importLoading: false,
|
|
|
+ importItems: [],
|
|
|
isFixed: false,
|
|
|
offsetTop: 0
|
|
|
}
|
|
|
@@ -445,31 +450,57 @@ export default {
|
|
|
event.currentTarget.select();
|
|
|
},
|
|
|
handleImport() {
|
|
|
- this.queryTemplates()
|
|
|
- this.dialogFormVisible = true
|
|
|
this.query = ''
|
|
|
- this.templateId = ''
|
|
|
+ this.importId = ''
|
|
|
+ this.importType = 0
|
|
|
+ this.importItems = []
|
|
|
+ this.queryImportItems()
|
|
|
+ this.dialogFormVisible = true
|
|
|
+ },
|
|
|
+ handleImportTypeChange() {
|
|
|
+ this.importId = ''
|
|
|
+ this.importItems = []
|
|
|
+ this.queryImportItems()
|
|
|
+ },
|
|
|
+ queryImportItems(query=''){
|
|
|
+ this.importType === 0 ? this.queryTemplates(query) : this.queryFoods(query)
|
|
|
},
|
|
|
queryTemplates(query='') {
|
|
|
+ this.importLoading = true
|
|
|
getNutrientTemplates({ query }).then(res => {
|
|
|
- this.templates = res.data.list
|
|
|
- if (this.templates.length > 0) {
|
|
|
- this.templateId = this.templates[0].id
|
|
|
+ this.importItems = res.data.list
|
|
|
+ if (this.importItems.length > 0) {
|
|
|
+ this.importId = this.importItems[0].id
|
|
|
}
|
|
|
+ this.importLoading = false
|
|
|
+ }).catch(() => {
|
|
|
+ this.importItems = []
|
|
|
+ this.importLoading = false
|
|
|
+ })
|
|
|
+ },
|
|
|
+ queryFoods(query='') {
|
|
|
+ this.importLoading = true
|
|
|
+ getFoodList({ query: query, orderBy: 0, pageNum: 1, pageSize: 20 }).then(res => {
|
|
|
+ this.importItems = res.data.list
|
|
|
+ this.importLoading = false
|
|
|
}).catch(() => {
|
|
|
- this.templates = []
|
|
|
+ this.importItems = []
|
|
|
+ this.importLoading = false
|
|
|
})
|
|
|
},
|
|
|
- submitFromTemplate() {
|
|
|
- this.templateLoading = true
|
|
|
- importNutrientsFromTemplate(this.foodId, { templateId: this.templateId }).then(res => {
|
|
|
+ submitImport() {
|
|
|
+ this.importLoading = true
|
|
|
+ const resPromise = this.importType === 0 ?
|
|
|
+ importNutrientsFromTemplate(this.foodId, { templateId: this.importId }) :
|
|
|
+ importNutrientFromSimilarFood(this.foodId, { foodId: this.importId })
|
|
|
+ resPromise.then(res => {
|
|
|
this.fetchData()
|
|
|
this.$notify.success("提交成功")
|
|
|
this.dialogFormVisible = false
|
|
|
- this.templateLoading = false
|
|
|
+ this.importLoading = false
|
|
|
}).catch(res => {
|
|
|
this.$message.error(res.data.message)
|
|
|
- this.templateLoading = false
|
|
|
+ this.importLoading = false
|
|
|
this.dialogFormVisible = false
|
|
|
})
|
|
|
},
|