|
|
@@ -2,8 +2,8 @@
|
|
|
<div class="createPost-container">
|
|
|
<el-form ref="postForm" :model="postForm" :rules="rules" label-position="right" label-width="90px" class="form-container">
|
|
|
<div class="createPost-main-container">
|
|
|
- <el-form-item label="ID:" required style="margin-bottom: 40px;width: 60%" prop="id">
|
|
|
- <el-input v-model="postForm.id" placeholder="请输入ID" />
|
|
|
+ <el-form-item label="ID:" style="margin-bottom: 40px;width: 60%" prop="id">
|
|
|
+ <el-input v-model="postForm.id2" placeholder="请输入ID" />
|
|
|
</el-form-item>
|
|
|
<el-form-item label="名称:" prop="name" style="margin-bottom: 40px;width: 60%" required>
|
|
|
<el-input v-model="postForm.name" placeholder="请输入名称" />
|
|
|
@@ -11,6 +11,10 @@
|
|
|
<el-form-item label="描述:" prop="description" style="margin-bottom: 30px;width: 40%">
|
|
|
<el-input v-model="postForm.description" type="textarea" :rows="4" placeholder="请输入描述" />
|
|
|
</el-form-item>
|
|
|
+ <el-form-item label="食物类型:" prop="foodType" style="margin-bottom: 30px;width: 40%">
|
|
|
+ <el-radio :label="0" v-model="postForm.foodType">主材</el-radio>
|
|
|
+ <el-radio :label="1" v-model="postForm.foodType">辅材</el-radio>
|
|
|
+ </el-form-item>
|
|
|
<el-form-item label="ep:" prop="ep" style="margin-bottom: 40px;width: 60%">
|
|
|
<el-input v-model="postForm.ep" placeholder="请输入ep" style="width: 40%" />
|
|
|
</el-form-item>
|
|
|
@@ -19,13 +23,19 @@
|
|
|
<el-col :span="8">
|
|
|
<el-input v-model="postForm.nvSpec" placeholder="请输入nvSpec" />
|
|
|
</el-col>
|
|
|
- <el-col :span="4">
|
|
|
- <el-autocomplete
|
|
|
- class="inline-input"
|
|
|
+ <el-col :span="6">
|
|
|
+ <el-select
|
|
|
v-model="postForm.nvSpecUnit"
|
|
|
- :fetch-suggestions="querySearch"
|
|
|
- placeholder="克"
|
|
|
- ></el-autocomplete>
|
|
|
+ class="filter-item"
|
|
|
+ filterable
|
|
|
+ remote
|
|
|
+ reserve-keyword
|
|
|
+ placeholder="请输入单位关键词"
|
|
|
+ :loading="unitLoading"
|
|
|
+ :remote-method="queryUnits"
|
|
|
+ >
|
|
|
+ <el-option v-for="item in units" :key="`nv_spec${item.id}`" :label="item.name" :value="item.id" />
|
|
|
+ </el-select>
|
|
|
</el-col>
|
|
|
</el-row>
|
|
|
</el-form-item>
|
|
|
@@ -34,24 +44,33 @@
|
|
|
<el-col :span="8">
|
|
|
<el-input v-model="postForm.inInit" placeholder="请输入inInit" />
|
|
|
</el-col>
|
|
|
- <el-col :span="4">
|
|
|
- <el-autocomplete
|
|
|
- class="inline-input"
|
|
|
+ <el-col :span="6">
|
|
|
+ <el-select
|
|
|
v-model="postForm.inInitUnit"
|
|
|
- :fetch-suggestions="querySearch"
|
|
|
- placeholder="克"
|
|
|
- ></el-autocomplete>
|
|
|
+ class="filter-item"
|
|
|
+ filterable
|
|
|
+ remote
|
|
|
+ reserve-keyword
|
|
|
+ placeholder="请输入单位关键词"
|
|
|
+ :loading="unitLoading"
|
|
|
+ :remote-method="queryUnits"
|
|
|
+ >
|
|
|
+ <el-option v-for="item in units" :key="`in_init${item.id}`" :label="item.name" :value="item.id" />
|
|
|
+ </el-select>
|
|
|
</el-col>
|
|
|
</el-row>
|
|
|
</el-form-item>
|
|
|
- <el-form-item label="CF:" prop="cf" style="margin-bottom: 40px;width: 60%">
|
|
|
- <el-input v-model="postForm.cf" placeholder="请输入cf" />
|
|
|
+ <el-form-item label="最小刻度:" prop="minScale" style="margin-bottom: 40px;width: 60%">
|
|
|
+ <el-input v-model="postForm.minScale" placeholder="请输入最小刻度" />
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="最大刻度:" prop="maxScale" style="margin-bottom: 40px;width: 60%">
|
|
|
+ <el-input v-model="postForm.maxScale" placeholder="请输入最大刻度" />
|
|
|
</el-form-item>
|
|
|
- <el-form-item label="CNVF:" prop="cnvf" style="margin-bottom: 40px;width: 60%">
|
|
|
- <el-input v-model="postForm.cnvf" placeholder="请输入cnvf" />
|
|
|
+ <el-form-item label="卡尺每格刻度:" prop="stepScale" style="margin-bottom: 40px;width: 60%">
|
|
|
+ <el-input v-model="postForm.stepScale" placeholder="请输入卡尺每格刻度" />
|
|
|
</el-form-item>
|
|
|
- <el-form-item label="qlf:" prop="qlf" style="margin-bottom: 40px;width: 60%">
|
|
|
- <el-input v-model="postForm.qlf" placeholder="请输入qlf" />
|
|
|
+ <el-form-item label="计量单位提示:" prop="unitTip" style="margin-bottom: 40px;width: 60%">
|
|
|
+ <el-input v-model="postForm.unitTip" placeholder="请输入计量单位提示" />
|
|
|
</el-form-item>
|
|
|
<el-form-item label="主图列表:" prop="img" style="margin-bottom: 30px;width: 60%">
|
|
|
<dropzone
|
|
|
@@ -72,15 +91,46 @@
|
|
|
<el-button v-loading="loading" style="margin-left: 10px;" type="success" @click="submitForm">
|
|
|
保存
|
|
|
</el-button>
|
|
|
+ <el-button v-loading="loading" style="margin-left: 10px;" type="success" v-if="!isEdit" @click="handleDialog">
|
|
|
+ 保存并从模板导入营养素
|
|
|
+ </el-button>
|
|
|
</div>
|
|
|
</el-form>
|
|
|
+
|
|
|
+ <el-dialog title="从模板导入营养素" :visible.sync="dialogFormVisible">
|
|
|
+ <el-form ref="dialogForm" label-position="left" label-width="80px" style="width: 400px; margin-left:50px;">
|
|
|
+ <el-form-item label="模板:" prop="templateId">
|
|
|
+ <el-select
|
|
|
+ v-model="templateId"
|
|
|
+ class="filter-item"
|
|
|
+ filterable
|
|
|
+ remote
|
|
|
+ reserve-keyword
|
|
|
+ placeholder="请输入模板关键词"
|
|
|
+ :loading="templateLoading"
|
|
|
+ :remote-method="queryTemplates"
|
|
|
+ >
|
|
|
+ <el-option v-for="item in templates" :key="`template${item.id}`" :label="item.name" :value="item.id" />
|
|
|
+ </el-select>
|
|
|
+ </el-form-item>
|
|
|
+ </el-form>
|
|
|
+ <div slot="footer" class="dialog-footer">
|
|
|
+ <el-button @click="dialogFormVisible = false">
|
|
|
+ 取消
|
|
|
+ </el-button>
|
|
|
+ <el-button type="primary" @click="submitFromTemplate">
|
|
|
+ 提交
|
|
|
+ </el-button>
|
|
|
+ </div>
|
|
|
+ </el-dialog>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
import { create, getDetail, update } from '@/api/food'
|
|
|
import Dropzone from '@/components/Dropzone'
|
|
|
-import store from '@/store'
|
|
|
+import { getList as getUnits } from '@/api/unit'
|
|
|
+import { getNutrientTemplates } from '@/api/nutrientTemplate'
|
|
|
|
|
|
export default {
|
|
|
name: "FoodDetail",
|
|
|
@@ -95,15 +145,18 @@ export default {
|
|
|
return {
|
|
|
mainImgDropzone: 'mainImgDropzone',
|
|
|
nutrientImgDropzone: 'nutrientImgDropzone',
|
|
|
- postForm: { id: '', name: '', img: '', description: '', nvSpec: 100, nvSpecUnit: '克',
|
|
|
- inInit: 100, inInitUnit: '克', cf: 1 },
|
|
|
+ postForm: { id2: '', name: '', img: '', description: ''},
|
|
|
loading: false,
|
|
|
rules: {
|
|
|
- id: [{ required: true, message: 'ID不能为空', trigger: 'blur' }],
|
|
|
name: [{ required: true, message: '名称不能为空', trigger: 'blur' }]
|
|
|
},
|
|
|
foodId: '',
|
|
|
- unitNames: []
|
|
|
+ units: [],
|
|
|
+ unitLoading: false,
|
|
|
+ dialogFormVisible: false,
|
|
|
+ templateLoading:false,
|
|
|
+ templates: [],
|
|
|
+ templateId: ''
|
|
|
}
|
|
|
},
|
|
|
created() {
|
|
|
@@ -111,14 +164,11 @@ export default {
|
|
|
this.foodId = this.$route.params && this.$route.params.id
|
|
|
this.fetchData(this.foodId)
|
|
|
}
|
|
|
- this.unitNames = store.getters.units.map(item => {
|
|
|
- return {value: item.name, label: `${item.name} | ${item.enName} | ${item.abbreviation}` } })
|
|
|
},
|
|
|
methods: {
|
|
|
fetchData(id) {
|
|
|
getDetail(id).then(res => {
|
|
|
this.postForm = res.data
|
|
|
- console.log(res.data)
|
|
|
})
|
|
|
},
|
|
|
submitForm() {
|
|
|
@@ -156,17 +206,6 @@ export default {
|
|
|
this.loading = false
|
|
|
})
|
|
|
},
|
|
|
- querySearch(queryString, cb) {
|
|
|
- let restaurants = this.unitNames;
|
|
|
- let results = queryString ? restaurants.filter(this.createFilter(queryString)) : restaurants;
|
|
|
- // 调用 callback 返回建议列表的数据
|
|
|
- cb(results);
|
|
|
- },
|
|
|
- createFilter(queryString) {
|
|
|
- return (restaurant) => {
|
|
|
- return (restaurant.label.toLowerCase().match(queryString.toLowerCase()) !== null);
|
|
|
- };
|
|
|
- },
|
|
|
removeFile(file) {
|
|
|
let imgs = []
|
|
|
if (file.dropzoneId === this.mainImgDropzone) {
|
|
|
@@ -197,6 +236,28 @@ export default {
|
|
|
this.postForm.nutrientImgs = [file.fileUrl]
|
|
|
}
|
|
|
}
|
|
|
+ },
|
|
|
+ queryUnits(query) {
|
|
|
+ getUnits({ query }).then(res => {
|
|
|
+ this.units = res.data.list
|
|
|
+ }).catch(() => {
|
|
|
+ this.units = []
|
|
|
+ })
|
|
|
+ },
|
|
|
+ queryTemplates(query) {
|
|
|
+ getNutrientTemplates({ query }).then(res => {
|
|
|
+ this.templates = res.data.list
|
|
|
+ }).catch(() => {
|
|
|
+ this.templates = []
|
|
|
+ })
|
|
|
+ },
|
|
|
+ handleDialog() {
|
|
|
+ this.templateId = ''
|
|
|
+ this.dialogFormVisible = true
|
|
|
+ },
|
|
|
+ submitFromTemplate() {
|
|
|
+ this.postForm.templateId = this.templateId
|
|
|
+ this.submitForm()
|
|
|
}
|
|
|
}
|
|
|
}
|