|
|
@@ -2,7 +2,7 @@
|
|
|
<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:" style="margin-bottom: 40px;width: 60%" prop="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>
|
|
|
@@ -24,39 +24,11 @@
|
|
|
<el-input v-model="postForm.nvSpec" placeholder="请输入nvSpec" />
|
|
|
</el-col>
|
|
|
<el-col :span="6">
|
|
|
- <el-select
|
|
|
- v-model="postForm.nvSpecUnit"
|
|
|
- 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>
|
|
|
- <el-form-item label="in.init:" prop="inInit" style="margin-bottom: 40px;width: 60%">
|
|
|
- <el-row :gutter="10">
|
|
|
- <el-col :span="8">
|
|
|
- <el-input v-model="postForm.inInit" placeholder="请输入inInit" />
|
|
|
- </el-col>
|
|
|
- <el-col :span="6">
|
|
|
- <el-select
|
|
|
- v-model="postForm.inInitUnit"
|
|
|
- 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-autocomplete
|
|
|
+ v-model="postForm.nvSpecUnitName"
|
|
|
+ :fetch-suggestions="querySearchAsync"
|
|
|
+ placeholder="请输入内容"
|
|
|
+ ></el-autocomplete>
|
|
|
</el-col>
|
|
|
</el-row>
|
|
|
</el-form-item>
|
|
|
@@ -69,21 +41,10 @@
|
|
|
<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="计量单位提示:" 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%">
|
|
|
+ <el-form-item label="图片列表:" prop="images" style="margin-bottom: 30px;width: 60%">
|
|
|
<dropzone
|
|
|
:id="mainImgDropzone"
|
|
|
- :default-img="postForm.mainImgs"
|
|
|
- @dropzone-removedFile="removeFile"
|
|
|
- @dropzone-success="addFile"
|
|
|
- />
|
|
|
- </el-form-item>
|
|
|
- <el-form-item label="营养素信息图列表:" prop="img" style="margin-bottom: 30px;width: 60%">
|
|
|
- <dropzone
|
|
|
- :id="nutrientImgDropzone"
|
|
|
- :default-img="postForm.nutrientImgs"
|
|
|
+ :default-img="postForm.images"
|
|
|
@dropzone-removedFile="removeFile"
|
|
|
@dropzone-success="addFile"
|
|
|
/>
|
|
|
@@ -151,7 +112,6 @@ export default {
|
|
|
name: [{ required: true, message: '名称不能为空', trigger: 'blur' }]
|
|
|
},
|
|
|
foodId: '',
|
|
|
- units: [],
|
|
|
unitLoading: false,
|
|
|
dialogFormVisible: false,
|
|
|
templateLoading:false,
|
|
|
@@ -168,12 +128,6 @@ export default {
|
|
|
methods: {
|
|
|
fetchData(id) {
|
|
|
getDetail(id).then(res => {
|
|
|
- if (res.data.nvSpecUnit) {
|
|
|
- this.units.push({ id: res.data.nvSpecUnit, name: res.data.nvSpecUnitName })
|
|
|
- }
|
|
|
- if (res.data.inInitUnit && res.data.nvSpecUnitName !== res.data.inInitUnitName) {
|
|
|
- this.units.push({ id: res.data.inInitUnit, name: res.data.inInitUnitName })
|
|
|
- }
|
|
|
this.postForm = res.data
|
|
|
})
|
|
|
},
|
|
|
@@ -194,31 +148,26 @@ export default {
|
|
|
},
|
|
|
createData() {
|
|
|
create(this.postForm).then(res => {
|
|
|
- this.$notify({ title: '成功', message: '创建试题成功', type: 'success', duration: 2000 })
|
|
|
+ this.$message.success('创建成功')
|
|
|
this.loading = false
|
|
|
this.$router.push({ path: '/food' })
|
|
|
}).catch(error => {
|
|
|
- this.$notify({ title: '失败', message: error.response.data.message, type: 'error', duration: 2000 })
|
|
|
+ this.$message.error(res.data.message)
|
|
|
this.loading = false
|
|
|
})
|
|
|
},
|
|
|
updateData() {
|
|
|
update(this.foodId, this.postForm).then(res => {
|
|
|
- this.$notify({ title: '成功', message: '更新试题成功', type: 'success', duration: 2000 })
|
|
|
+ this.$message.success('更新成功')
|
|
|
this.loading = false
|
|
|
this.$router.push({ path: '/food' })
|
|
|
}).catch(error => {
|
|
|
- this.$notify({ title: '失败', message: error.response.data.message, type: 'error', duration: 2000 })
|
|
|
+ this.$message.error(res.data.message)
|
|
|
this.loading = false
|
|
|
})
|
|
|
},
|
|
|
removeFile(file) {
|
|
|
- let imgs = []
|
|
|
- if (file.dropzoneId === this.mainImgDropzone) {
|
|
|
- imgs = this.postForm.mainImgs
|
|
|
- } else {
|
|
|
- imgs = this.postForm.nutrientImgs
|
|
|
- }
|
|
|
+ let imgs = this.postForm.images
|
|
|
let imgIndex = -1
|
|
|
for (let i = 0; i < imgs.length; i++) {
|
|
|
if (imgs[i] === file.fileUrl) {
|
|
|
@@ -230,29 +179,13 @@ export default {
|
|
|
},
|
|
|
addFile(file) {
|
|
|
if (file.dropzoneId === this.mainImgDropzone) {
|
|
|
- if (this.postForm.mainImgs) {
|
|
|
- this.postForm.mainImgs.push(file.fileUrl)
|
|
|
+ if (this.postForm.images) {
|
|
|
+ this.postForm.images.push(file.fileUrl)
|
|
|
} else {
|
|
|
- this.postForm.mainImgs = [file.fileUrl]
|
|
|
- }
|
|
|
- } else {
|
|
|
- if (this.postForm.nutrientImgs) {
|
|
|
- this.postForm.nutrientImgs.push(file.fileUrl)
|
|
|
- } else {
|
|
|
- this.postForm.nutrientImgs = [file.fileUrl]
|
|
|
+ this.postForm.images = [file.fileUrl]
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
- queryUnits(query) {
|
|
|
- getUnits({ query }).then(res => {
|
|
|
- this.units = res.data.list
|
|
|
- // console.log(this.units)
|
|
|
- // for (let i=0; i < res.data.list.length; i++){
|
|
|
- // this.units.add({ id: res.data.list[i].id, name: res.data.list[i].name })
|
|
|
- // }
|
|
|
- }).catch(() => {
|
|
|
- })
|
|
|
- },
|
|
|
queryTemplates(query) {
|
|
|
getNutrientTemplates({ query }).then(res => {
|
|
|
this.templates = res.data.list
|
|
|
@@ -267,6 +200,13 @@ export default {
|
|
|
submitFromTemplate() {
|
|
|
this.postForm.templateId = this.templateId
|
|
|
this.submitForm()
|
|
|
+ },
|
|
|
+ querySearchAsync(query, cb) {
|
|
|
+ getUnits({ query }).then(res => {
|
|
|
+ cb(res.data.list.map(item => { return { value: item.name } }))
|
|
|
+ }).catch(() => {
|
|
|
+ cb([])
|
|
|
+ })
|
|
|
}
|
|
|
}
|
|
|
}
|