|
|
@@ -1,32 +1,63 @@
|
|
|
<template>
|
|
|
- <div class="createPost-container">
|
|
|
+ <div class="createPost-container" style="position: relative">
|
|
|
+
|
|
|
+ <floating-window :class="{'is_fixed': isFixed}" >
|
|
|
+ <el-dropdown @command="handleCommand">
|
|
|
+ <img width="50px" height="50px" src="@/assets/navigation.png" alt="导航.png" />
|
|
|
+ <el-dropdown-menu slot="dropdown">
|
|
|
+ <el-dropdown-item command="detail">食物更新</el-dropdown-item>
|
|
|
+ <el-dropdown-item command="nutrient">营养素关联</el-dropdown-item>
|
|
|
+ <el-dropdown-item command="unit">单位管理</el-dropdown-item>
|
|
|
+ <el-dropdown-item command="modifier">规格管理</el-dropdown-item>
|
|
|
+ <el-dropdown-item command="list">食物列表</el-dropdown-item>
|
|
|
+ </el-dropdown-menu>
|
|
|
+ </el-dropdown>
|
|
|
+ </floating-window>
|
|
|
+
|
|
|
<el-form ref="postForm" :model="postForm" :rules="rules" label-position="right" label-width="130px" class="form-container">
|
|
|
<div class="createPost-main-container">
|
|
|
<el-checkbox @change="checkboxChange" :disabled="isEdit" v-model="isDefaultModifier" style="margin: 0 0 10px 100px">默认规格</el-checkbox>
|
|
|
<el-form-item label="规格名称:" style="margin-bottom: 40px;width: 60%" prop="name">
|
|
|
<el-input :disabled="isDefaultModifier" v-model="postForm.name" placeholder="请输入名称" @blur="updateUnit" />
|
|
|
</el-form-item>
|
|
|
- <el-form-item v-show="!isDefaultModifier" label="数值:" style="margin-bottom: 40px;width: 60%" prop="quantity">
|
|
|
- <el-input v-model="postForm.quantity" placeholder="请输入数值" />
|
|
|
- </el-form-item>
|
|
|
- <el-form-item v-show="!isDefaultModifier" label="单位名称:" style="margin-bottom: 40px;width: 60%" prop="unit">
|
|
|
- <el-autocomplete
|
|
|
- style="width: 100%"
|
|
|
- v-model="postForm.unit"
|
|
|
- :fetch-suggestions="queryUnits"
|
|
|
- placeholder="单位关键词"
|
|
|
- />
|
|
|
- </el-form-item>
|
|
|
- <el-form-item label="推荐摄入量:" style="margin-bottom: 40px;width: 60%" prop="inInit">
|
|
|
- <el-input v-model="postForm.inInit" placeholder="请输入推荐量" />
|
|
|
+ <el-row style="width: 60%">
|
|
|
+ <el-col :span="12">
|
|
|
+ <el-form-item v-show="!isDefaultModifier" label="数值:" style="margin-bottom: 40px" prop="quantity">
|
|
|
+ <el-input v-model="postForm.quantity" placeholder="请输入数值" />
|
|
|
+ </el-form-item>
|
|
|
+ </el-col>
|
|
|
+ <el-col :span="12">
|
|
|
+ <el-form-item v-show="!isDefaultModifier" label="单位名称:" style="margin-bottom: 40px" prop="unit">
|
|
|
+ <el-autocomplete
|
|
|
+ style="width: 100%"
|
|
|
+ v-model="postForm.unit"
|
|
|
+ :fetch-suggestions="queryUnits"
|
|
|
+ placeholder="单位关键词"
|
|
|
+ />
|
|
|
+ </el-form-item>
|
|
|
+ </el-col>
|
|
|
+ </el-row>
|
|
|
+ <el-form-item label="CNVR" style="margin-bottom: 40px;width: 60%" prop="unitTip">
|
|
|
+ <el-input v-model="postForm.unitTip" placeholder="请输入CNVR" />
|
|
|
</el-form-item>
|
|
|
- <el-form-item label="推荐量单位名称:" style="margin-bottom: 40px;width: 60%" prop="inInitUnit">
|
|
|
- <el-autocomplete
|
|
|
- style="width: 100%"
|
|
|
- v-model="postForm.inInitUnit"
|
|
|
- :fetch-suggestions="queryUnits"
|
|
|
- placeholder="单位关键词"
|
|
|
- />
|
|
|
+ <el-row style="width: 60%">
|
|
|
+ <el-col :span="12">
|
|
|
+ <el-form-item label="推荐摄入量:" style="margin-bottom: 40px" prop="inInit">
|
|
|
+ <el-input v-model="postForm.inInit" placeholder="请输入推荐量" />
|
|
|
+ </el-form-item>
|
|
|
+ </el-col>
|
|
|
+ <el-col :span="12">
|
|
|
+ <el-form-item label="推荐量单位名称:" style="margin-bottom: 40px" prop="inInitUnit">
|
|
|
+ <el-autocomplete
|
|
|
+ v-model="postForm.inInitUnit"
|
|
|
+ :fetch-suggestions="queryUnits"
|
|
|
+ placeholder="单位关键词"
|
|
|
+ />
|
|
|
+ </el-form-item>
|
|
|
+ </el-col>
|
|
|
+ </el-row>
|
|
|
+ <el-form-item label="CF" style="margin-bottom: 40px;width: 60%" prop="cf">
|
|
|
+ <el-input v-model="postForm.cf" :disabled="true" />
|
|
|
</el-form-item>
|
|
|
<el-form-item label="最小刻度:" prop="minScale" style="margin-bottom: 40px;width: 60%">
|
|
|
<el-input v-model="postForm.minScale" placeholder="请输入最小刻度" />
|
|
|
@@ -55,6 +86,7 @@
|
|
|
|
|
|
<script>
|
|
|
import Dropzone from '@/components/Dropzone'
|
|
|
+import FloatingWindow from '@/components/FloatingWindow'
|
|
|
import { addFoodModifier, updateFoodModifier, getFoodModifier } from '@/api/food'
|
|
|
import { getList as getUnits } from '@/api/unit'
|
|
|
|
|
|
@@ -66,7 +98,7 @@ export default {
|
|
|
default: false
|
|
|
}
|
|
|
},
|
|
|
- components: { Dropzone },
|
|
|
+ components: { Dropzone, FloatingWindow },
|
|
|
data() {
|
|
|
return {
|
|
|
defaultModifierName: '-',
|
|
|
@@ -75,9 +107,18 @@ export default {
|
|
|
loading: false,
|
|
|
foodId: '',
|
|
|
modifierId: '',
|
|
|
- isDefaultModifier: false
|
|
|
+ isDefaultModifier: false,
|
|
|
+ isFixed: false,
|
|
|
+ offsetTop: 0
|
|
|
}
|
|
|
},
|
|
|
+ mounted() {
|
|
|
+ window.addEventListener('scroll', this.initHeight);
|
|
|
+ },
|
|
|
+ //回调中移除监听
|
|
|
+ destroyed() {
|
|
|
+ window.removeEventListener('scroll', this.handleScroll)
|
|
|
+ },
|
|
|
created() {
|
|
|
this.foodId = this.$route.params && this.$route.params.id
|
|
|
if (this.isEdit) {
|
|
|
@@ -152,6 +193,29 @@ export default {
|
|
|
checkboxChange(value) {
|
|
|
const name = value ? this.defaultModifierName : ''
|
|
|
this.$set(this.postForm, 'name', name)
|
|
|
+ },
|
|
|
+ initHeight() {
|
|
|
+ // 设置或获取位于对象最顶端和窗口中可见内容的最顶端之间的距离 (被卷曲的高度)
|
|
|
+ const scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop
|
|
|
+ //如果被卷曲的高度大于吸顶元素到顶端位置 的距离
|
|
|
+ this.isFixed = scrollTop > this.offsetTop;
|
|
|
+ },
|
|
|
+ handleCommand(value) {
|
|
|
+ let path = ''
|
|
|
+ if (value === 'detail') {
|
|
|
+ path = `/food/edit/${this.foodId}`
|
|
|
+ } else if (value === 'unit') {
|
|
|
+ path = `/food/${this.foodId}/unit`
|
|
|
+ } else if (value === 'nutrient') {
|
|
|
+ path = `/food/${this.foodId}/nutrient`
|
|
|
+ } else if (value === 'modifier') {
|
|
|
+ path = `/food/${this.foodId}/modifier`
|
|
|
+ } else if (value === 'list') {
|
|
|
+ path = `/food`
|
|
|
+ }
|
|
|
+ if (path) {
|
|
|
+ this.$router.push({ path: path })
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|