|
@@ -8,11 +8,14 @@
|
|
|
<el-form-item label="数值:" style="margin-bottom: 40px;width: 60%" prop="quantity">
|
|
<el-form-item label="数值:" style="margin-bottom: 40px;width: 60%" prop="quantity">
|
|
|
<el-input v-model="postForm.quantity" placeholder="请输入数值" />
|
|
<el-input v-model="postForm.quantity" placeholder="请输入数值" />
|
|
|
</el-form-item>
|
|
</el-form-item>
|
|
|
- <el-form-item label="单位名称:" style="margin-bottom: 40px;width: 60%" prop="unitName">
|
|
|
|
|
- <el-input v-model="postForm.unitName" placeholder="请输入单位名称" />
|
|
|
|
|
|
|
+ <el-form-item label="单位名称:" style="margin-bottom: 40px;width: 60%" prop="unit">
|
|
|
|
|
+ <el-input v-model="postForm.unit" placeholder="请输入单位名称" />
|
|
|
</el-form-item>
|
|
</el-form-item>
|
|
|
<el-form-item label="推荐摄入量:" style="margin-bottom: 40px;width: 60%" prop="inInit">
|
|
<el-form-item label="推荐摄入量:" style="margin-bottom: 40px;width: 60%" prop="inInit">
|
|
|
- <el-input v-model="postForm.inInit" placeholder="请输入单位名称" />
|
|
|
|
|
|
|
+ <el-input v-model="postForm.inInit" placeholder="请输入推荐量" />
|
|
|
|
|
+ </el-form-item>
|
|
|
|
|
+ <el-form-item label="推荐量单位名称:" style="margin-bottom: 40px;width: 60%" prop="inInitUnit">
|
|
|
|
|
+ <el-input v-model="postForm.inInitUnit" placeholder="单位关键字" />
|
|
|
</el-form-item>
|
|
</el-form-item>
|
|
|
<el-form-item label="最小刻度:" prop="minScale" style="margin-bottom: 40px;width: 60%">
|
|
<el-form-item label="最小刻度:" prop="minScale" style="margin-bottom: 40px;width: 60%">
|
|
|
<el-input v-model="postForm.minScale" placeholder="请输入最小刻度" />
|
|
<el-input v-model="postForm.minScale" placeholder="请输入最小刻度" />
|
|
@@ -40,96 +43,84 @@
|
|
|
</template>
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
<script>
|
|
|
- import Dropzone from '@/components/Dropzone'
|
|
|
|
|
- import { addFoodModifier, updateFoodModifier, getFoodModifier } from '@/api/food'
|
|
|
|
|
|
|
+import Dropzone from '@/components/Dropzone'
|
|
|
|
|
+import { addFoodModifier, updateFoodModifier, getFoodModifier } from '@/api/food'
|
|
|
|
|
|
|
|
- export default {
|
|
|
|
|
- name: "ModifierDetail",
|
|
|
|
|
- props: {
|
|
|
|
|
- isEdit: {
|
|
|
|
|
- type: Boolean,
|
|
|
|
|
- default: false
|
|
|
|
|
- }
|
|
|
|
|
|
|
+export default {
|
|
|
|
|
+ name: "ModifierDetail",
|
|
|
|
|
+ props: {
|
|
|
|
|
+ isEdit: {
|
|
|
|
|
+ type: Boolean,
|
|
|
|
|
+ default: false
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ components: { Dropzone },
|
|
|
|
|
+ data() {
|
|
|
|
|
+ return {
|
|
|
|
|
+ postForm: {},
|
|
|
|
|
+ rules: {},
|
|
|
|
|
+ loading: false,
|
|
|
|
|
+ foodId: '',
|
|
|
|
|
+ modifierId: ''
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ created() {
|
|
|
|
|
+ this.foodId = this.$route.params && this.$route.params.id
|
|
|
|
|
+ if (this.isEdit) {
|
|
|
|
|
+ this.modifierId = this.$route.params && this.$route.params.modifierId
|
|
|
|
|
+ this.fetchData()
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ methods: {
|
|
|
|
|
+ fetchData() {
|
|
|
|
|
+ getFoodModifier(this.foodId, this.modifierId).then(res => {
|
|
|
|
|
+ this.postForm = res.data
|
|
|
|
|
+ })
|
|
|
},
|
|
},
|
|
|
- components: { Dropzone },
|
|
|
|
|
- created() {
|
|
|
|
|
- this.foodId = this.$route.params && this.$route.params.id
|
|
|
|
|
- if (this.isEdit) {
|
|
|
|
|
- this.modifierId = this.$route.params && this.$route.params.modifierId
|
|
|
|
|
- this.fetchData()
|
|
|
|
|
|
|
+ removeFile(file) {
|
|
|
|
|
+ let imgs = this.postForm.images
|
|
|
|
|
+ let imgIndex = -1
|
|
|
|
|
+ for (let i = 0; i < imgs.length; i++) {
|
|
|
|
|
+ if (imgs[i] === file.fileUrl) {
|
|
|
|
|
+ imgIndex = i
|
|
|
|
|
+ break
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
+ imgs.splice(imgIndex, 1)
|
|
|
},
|
|
},
|
|
|
- data() {
|
|
|
|
|
- return {
|
|
|
|
|
- postForm: {},
|
|
|
|
|
- rules: {},
|
|
|
|
|
- loading: false,
|
|
|
|
|
- foodId: '',
|
|
|
|
|
- modifierId: ''
|
|
|
|
|
|
|
+ addFile(file) {
|
|
|
|
|
+ if (this.postForm.images) {
|
|
|
|
|
+ this.postForm.images.push(file.fileUrl)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ this.postForm.images = [file.fileUrl]
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
- methods: {
|
|
|
|
|
- fetchData() {
|
|
|
|
|
- getFoodModifier(this.foodId, this.modifierId).then(res => {
|
|
|
|
|
- this.postForm = res.data
|
|
|
|
|
- })
|
|
|
|
|
- },
|
|
|
|
|
- removeFile(file) {
|
|
|
|
|
- let imgs = this.postForm.images
|
|
|
|
|
- let imgIndex = -1
|
|
|
|
|
- for (let i = 0; i < imgs.length; i++) {
|
|
|
|
|
- if (imgs[i] === file.fileUrl) {
|
|
|
|
|
- imgIndex = i
|
|
|
|
|
- break
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- imgs.splice(imgIndex, 1)
|
|
|
|
|
- },
|
|
|
|
|
- addFile(file) {
|
|
|
|
|
- if (this.postForm.images) {
|
|
|
|
|
- this.postForm.images.push(file.fileUrl)
|
|
|
|
|
|
|
+ submitForm() {
|
|
|
|
|
+ this.loading = true
|
|
|
|
|
+ this.postForm.foodId = this.foodId
|
|
|
|
|
+ this.$refs['postForm'].validate((valid) => {
|
|
|
|
|
+ if (valid) {
|
|
|
|
|
+ this.createOrUpdateData()
|
|
|
} else {
|
|
} else {
|
|
|
- this.postForm.images = [file.fileUrl]
|
|
|
|
|
- }
|
|
|
|
|
- },
|
|
|
|
|
- submitForm() {
|
|
|
|
|
- this.loading = true
|
|
|
|
|
- this.postForm.foodId = this.foodId
|
|
|
|
|
- this.$refs['postForm'].validate((valid) => {
|
|
|
|
|
- if (valid) {
|
|
|
|
|
- if (this.isEdit) {
|
|
|
|
|
- this.updateData()
|
|
|
|
|
- } else {
|
|
|
|
|
- this.createData()
|
|
|
|
|
- }
|
|
|
|
|
- } else {
|
|
|
|
|
- this.$notify({ title: '失败', message: '必填字段为空', type: 'error', duration: 2000 })
|
|
|
|
|
- this.loading = false
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
- },
|
|
|
|
|
- createData() {
|
|
|
|
|
- addFoodModifier(this.foodId, this.postForm).then(res => {
|
|
|
|
|
- this.$message.success('创建成功')
|
|
|
|
|
- this.loading = false
|
|
|
|
|
- this.$router.push({ path: `/food/${this.foodId}/modifier` })
|
|
|
|
|
- }).catch(res => {
|
|
|
|
|
- this.$message.error(res.data.message)
|
|
|
|
|
- this.loading = false
|
|
|
|
|
- })
|
|
|
|
|
- },
|
|
|
|
|
- updateData() {
|
|
|
|
|
- updateFoodModifier(this.foodId, this.postForm.id, this.postForm).then(res => {
|
|
|
|
|
- this.$message.success('更新成功')
|
|
|
|
|
|
|
+ this.$message.error('必填字段为空')
|
|
|
this.loading = false
|
|
this.loading = false
|
|
|
- this.$router.push({ path: `/food/${this.foodId}/modifier` })
|
|
|
|
|
- }).catch(res => {
|
|
|
|
|
- this.$message.error(res.data.message)
|
|
|
|
|
- this.loading = false
|
|
|
|
|
- })
|
|
|
|
|
- },
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ },
|
|
|
|
|
+ createOrUpdateData() {
|
|
|
|
|
+ const resultPromise = this.isEdit ? updateFoodModifier(this.foodId, this.postForm.id, this.postForm) :
|
|
|
|
|
+ addFoodModifier(this.foodId, this.postForm)
|
|
|
|
|
+ resultPromise.then(res => {
|
|
|
|
|
+ this.$message.success('创建成功')
|
|
|
|
|
+ this.loading = false
|
|
|
|
|
+ this.$router.push({ path: `/food/${this.foodId}/modifier` })
|
|
|
|
|
+ }).catch(res => {
|
|
|
|
|
+ this.$message.error(res.data.message)
|
|
|
|
|
+ this.loading = false
|
|
|
|
|
+ })
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+}
|
|
|
</script>
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped lang="scss">
|
|
<style scoped lang="scss">
|