5 Commit-ok 1355a89a51 ... b063924dc7

Szerző SHA1 Üzenet Dátum
  wangyang b063924dc7 食物规格列表页增加状态 5 éve
  wangyang 14ef1013d1 去除food的状态,食物规格增加状态 5 éve
  wangyang 31925d7479 update 5 éve
  wangyang 514626fdc8 完成特殊营养素单位转换 5 éve
  wangyang fb90b1ba49 完成%Vol单位录入 5 éve

+ 12 - 2
src/api/nutrient.js

@@ -45,9 +45,19 @@ export function updateSortOrder(id, data) {
 }
 
 // 获取营养素单位列表
-export function getNutrientUnits(id) {
+export function getNutrientUnits(id, params) {
   return request({
     url: `/api/nutrients/${id}/units`,
-    method: 'get'
+    method: 'get',
+    params
+  })
+}
+
+// 获取特殊营养素来源列表
+export function getNutrientSources(id, params) {
+  return request({
+    url: `/api/nutrients/${id}/sources`,
+    method: 'get',
+    params
   })
 }

+ 1 - 5
src/views/food/components/FoodDetail.vue

@@ -36,10 +36,6 @@
         <el-form-item label="GL:" prop="gl" style="margin-bottom: 40px;width: 60%">
           <el-input v-model="postForm.gl" placeholder="请输入gl" style="width: 60%" />
         </el-form-item>
-        <el-form-item label="状态:" prop="status" style="margin-bottom: 40px;width: 60%">
-          <el-radio :label="1" v-model="postForm.status">上架</el-radio>
-          <el-radio :label="0" v-model="postForm.status">下架</el-radio>
-        </el-form-item>
         <el-form-item label="食物种类:" prop="categoryId" style="margin-bottom: 40px;width: 60%">
           <el-cascader
             v-model="postForm.categoryId"
@@ -135,7 +131,7 @@ export default {
   },
   data() {
     return {
-      postForm: { id2: '', name: '', img: '', description: '', ep: 100, status: 0 },
+      postForm: { id2: '', name: '', img: '', description: '', ep: 100 },
       loading: false,
       rules: {
         name: [{ required: true, message: '名称不能为空', trigger: 'blur' }]

+ 1 - 10
src/views/food/index.vue

@@ -97,11 +97,6 @@
           <span>{{ row.dataSource }}</span>
         </template>
       </el-table-column>
-      <el-table-column label="状态" align="center" width="100px">
-        <template slot-scope="{row}">
-          <span>{{ row.status | statusFilter }}</span>
-        </template>
-      </el-table-column>
       <el-table-column label="创建时间" width="180px" align="center">
         <template slot-scope="{row}">
           <span>{{ row.createTime }}</span>
@@ -115,7 +110,7 @@
       <el-table-column label="操作" align="center" class-name="small-padding" fixed="right" width="90">
         <template slot-scope="{row,$index}">
           <el-dropdown @command="handleCommand">
-            <el-button :disabled="row.status === -1" size="small" @click.stop="{}" type="primary">
+            <el-button size="small" @click.stop="{}" type="primary">
               操作<i class="el-icon-arrow-down el-icon--right"></i>
             </el-button>
             <el-dropdown-menu slot="dropdown">
@@ -188,7 +183,6 @@ import axios from 'axios'
 import { getToken } from '@/utils/auth'
 
 const foodTypes = { 0: '主材', 1: '辅材' }
-const foodStatus = { '-1': '删除', '0': '下架', '1': '上架' }
 
 export default {
   name: 'FoodList',
@@ -196,9 +190,6 @@ export default {
   filters: {
     foodTypeFilter(value) {
       return foodTypes[value]
-    },
-    statusFilter(value) {
-      return foodStatus[value.toString()]
     }
   },
   data() {

+ 119 - 29
src/views/food/nutrient.vue

@@ -57,30 +57,43 @@
         <el-autocomplete
           class="inline-input"
           v-model="params.unit"
-          :fetch-suggestions="queryNutrientUnits"
+          :fetch-suggestions="(query, cb) => {queryNutrientUnits(query, params.nutrientId, cb)}"
+          @input="handleUnitChanged"
           placeholder="单位关键词"
         />
-        NRV%:
-        <el-input
-          v-model="params.nrvPercent"
-          style="width: 80px;"
-          class="filter-item"
-        />
+        <div v-show="showNutrientSource" style="display: inline-block">
+          <el-select
+            v-model="params.nutrientSource"
+            placeholder="请选择营养素来源"
+          >
+            <el-option v-for="item in nutrientSources" :key="item" :label="item" :value="item" />
+          </el-select>
+        </div>
+        <div v-show="showNRV" style="display: inline-block">
+          NRV%:
+          <el-input
+            v-model="params.nrvPercent"
+            style="width: 80px;"
+            class="filter-item"
+          />
+        </div>
       </el-row>
       <el-row style="margin-top: 10px">
-        Nv_Spec计量:
-        <el-input
-          v-model="params.nvSpec"
-          style="width: 80px;"
-          class="filter-item"
-          @focus="getInputFocus"
-        />
-        <el-autocomplete
-          class="inline-input"
-          v-model="params.nvSpecUnit"
-          :fetch-suggestions="queryUnits"
-          placeholder="单位关键词"
-        />
+        <div v-show="!isPercentByVolumeUnit(params)" style="display: inline-block">
+          Nv_Spec计量:
+          <el-input
+            v-model="params.nvSpec"
+            style="width: 80px;"
+            class="filter-item"
+            @focus="getInputFocus"
+          />
+          <el-autocomplete
+            class="inline-input"
+            v-model="params.nvSpecUnit"
+            :fetch-suggestions="queryUnits"
+            placeholder="单位关键词"
+          />
+        </div>
         信息来源:
         <el-autocomplete
           v-model="params.source"
@@ -152,21 +165,34 @@
       <el-table-column label="计量单位" align="center" width="150">
         <template slot-scope="{row}">
           <template v-if="row.edit">
-            <el-autocomplete v-model="row.unit" :fetch-suggestions="queryUnits" placeholder="单位关键词" />
+            <el-autocomplete
+              v-model="row.unit"
+              @input="handleRowUnitChanged(row)"
+              :fetch-suggestions="(query, cb) => {queryNutrientUnits(query, row.nutrientId, cb)}"
+              placeholder="单位关键词"
+            />
+            <el-select
+              clearable
+              v-show="showRowNutrientSource"
+              v-model="row.nutrientSource"
+              placeholder="请选择营养素来源"
+            >
+              <el-option v-for="item in nutrientSources" :key="item" :label="item" :value="item" />
+            </el-select>
           </template>
-          <span v-else>{{ row.unit }}</span>
+          <span v-else>{{ row.nutrientSource ? `${row.unit}(${row.nutrientSource})` : row.unit }}</span>
         </template>
       </el-table-column>
       <el-table-column label="NRV%" align="center" width="80">
         <template slot-scope="{row}">
           <template v-if="row.edit">
-            <el-input v-model="row.nrvPercent"/>
+            <el-input v-show="!isPercentByVolumeUnit(row)" v-model="row.nrvPercent"/>
           </template>
           <span v-else>{{ row.nrvPercent }}</span>
         </template>
       </el-table-column>
       <el-table-column label="Nv_Spec" align="center" width="80">
-        <template slot-scope="{row}">
+        <template slot-scope="{row}" v-if="!isPercentByVolumeUnit(row)">
           <template v-if="row.edit">
             <el-input v-model="row.nvSpec" class="filter-item" @focus="getInputFocus" />
           </template>
@@ -174,7 +200,7 @@
         </template>
       </el-table-column>
       <el-table-column label="计量单位" align="center" width="150">
-        <template slot-scope="{row}">
+        <template slot-scope="{row}" v-if="!isPercentByVolumeUnit(row)">
           <template v-if="row.edit">
             <el-autocomplete v-model="row.nvSpecUnit" :fetch-suggestions="queryUnits" placeholder="单位关键词" />
           </template>
@@ -268,10 +294,13 @@ import { getNutrientList, addFoodNutrient, updateFoodNutrient, removeFoodNutrien
   updateFoodNutrientSort, confirmDeleteFoodNutrient, importNutrientsFromTemplate,
   getList as getFoodList, importNutrientFromSimilarFood } from '@/api/food'
 import FloatingWindow from '@/components/FloatingWindow'
-import { getList, getNutrientUnits } from '@/api/nutrient'
+import { getList, getNutrientUnits, getNutrientSources } from '@/api/nutrient'
 import { getList as getUnits } from '@/api/unit'
 import { getNutrientTemplates } from '@/api/nutrientTemplate'
 
+// 特殊营养素 若单位不为baseUnit,则需要填写来源
+const SPECIAL_NUTRIENT_NAMES = ['维生素A', '维生素D', '维生素E', '烟酸', '叶酸']
+
 export default {
   name: 'AddNutrient',
   components: { FloatingWindow },
@@ -320,7 +349,11 @@ export default {
       importLoading: false,
       importItems: [],
       isFixed: false,
-      offsetTop: 0
+      offsetTop: 0,
+      showNutrientSource: false,
+      showRowNutrientSource: false,
+      nutrientSources: [],
+      showNRV: false
     }
   },
   methods: {
@@ -390,9 +423,9 @@ export default {
         this.nutrients = []
       })
     },
-    queryNutrientUnits(query, cb) {
+    queryNutrientUnits(query, nutrientId, cb) {
       let units = []
-      getNutrientUnits(this.params.nutrientId).then(res => {
+      getNutrientUnits(nutrientId, { query }).then(res => {
         res.data.forEach(item => units.push({ value: item }))
         cb(units)
       })
@@ -431,6 +464,7 @@ export default {
       } else {
         this.$set(row, 'radio', 0)
       }
+      this.handleRowUnitChanged(row)
     },
     radioChange(row) {
       this.$set(row, 'stdError', '')
@@ -442,6 +476,11 @@ export default {
       for (let nutrient of this.nutrients) {
         if (nutrient.id === value) {
           this.$set(this.params, 'unit', nutrient.baseUnit)
+          if (nutrient.nrvUnit) {
+            this.showNRV = true
+          } else {
+            this.showNRV = false
+          }
           break
         }
       }
@@ -526,6 +565,57 @@ export default {
       if (path) {
         this.$router.push({ path: path })
       }
+    },
+    isPercentByVolumeUnit(row) {
+      return row && row.unit === '%Vol'
+    },
+    isSpecialNutrient(nutrientId) {
+      let nutrient = null
+      for (let i = 0; i < this.nutrients.length; i++) {
+        if (this.nutrients[i].id === nutrientId) {
+          nutrient = this.nutrients[i]
+          break
+        }
+      }
+
+      // 如果特殊营养素单位不等于baseUnit,则显示来源
+      return nutrient && SPECIAL_NUTRIENT_NAMES.indexOf(nutrient.name) > -1
+    },
+    handleUnitChanged() {
+      if (this.isSpecialNutrient(this.params.nutrientId)) {
+        getNutrientSources(this.params.nutrientId, { unit: this.params.unit }).then(res => {
+          this.nutrientSources = res.data
+          if (this.nutrientSources.length > 0){
+            this.params.nutrientSource = this.nutrientSources[0]
+            this.showNutrientSource = true
+          } else {
+            this.showNutrientSource = false
+            this.params.nutrientSource = null
+          }
+        })
+      } else {
+        this.showNutrientSource = false
+        this.params.nutrientSource = null
+      }
+    },
+    handleRowUnitChanged(row) {
+      if (SPECIAL_NUTRIENT_NAMES.indexOf(row.nutrientName) > -1) {
+        getNutrientSources(row.nutrientId, { unit: row.unit }).then(res => {
+          this.nutrientSources = res.data
+          if (this.nutrientSources.length > 0){
+            if (!row.nutrientSource) {
+              row.nutrientSource = this.nutrientSources[0]
+            }
+            this.showRowNutrientSource = true
+          } else {
+            this.showRowNutrientSource = false
+            row.nutrientSource = null
+          }
+        })
+      } else {
+        this.showRowNutrientSource = false
+        row.nutrientSource = null
+      }
     }
   }
 }

+ 9 - 0
src/views/foodModifier/components/ModifierDetail.vue

@@ -56,6 +56,10 @@
             </el-form-item>
           </el-col>
         </el-row>
+        <el-form-item label="状态:" prop="status" style="margin-bottom: 40px;width: 60%">
+          <el-radio :label="1" v-model="postForm.status">上架</el-radio>
+          <el-radio :label="0" v-model="postForm.status">下架</el-radio>
+        </el-form-item>
         <el-form-item label="CF" style="margin-bottom: 40px;width: 60%" prop="cf">
           <el-input v-model="postForm.cf" :disabled="true" />
         </el-form-item>
@@ -193,6 +197,11 @@ export default {
     checkboxChange(value) {
       const name = value ? this.defaultModifierName : ''
       this.$set(this.postForm, 'name', name)
+
+      // 新建,状态默认为上架
+      if (!this.isEdit && value) {
+        this.$set(this.postForm, 'status', 1)
+      }
     },
     initHeight() {
       // 设置或获取位于对象最顶端和窗口中可见内容的最顶端之间的距离 (被卷曲的高度)

+ 12 - 0
src/views/foodModifier/index.vue

@@ -76,6 +76,11 @@
           <span>{{ row.unitTip }}</span>
         </template>
       </el-table-column>
+      <el-table-column label="状态" align="center">
+        <template slot-scope="{row}">
+          <span>{{ row.status | statusFilter }}</span>
+        </template>
+      </el-table-column>
       <el-table-column label="最小刻度" align="center" width="80px">
         <template slot-scope="{row}">
           <span>{{ row.minScale }}</span>
@@ -135,9 +140,16 @@ import { getFoodModifiers, removeFoodModifier, updateFoodModifierSort, convertFo
 import FloatingWindow from '@/components/FloatingWindow'
 import ModifierImport from './components/ModifierImport'
 
+const STATUS_MAP = { 0: '下架', 1: '上架' }
+
 export default {
   name: 'FoodModifierIndex',
   components: { FloatingWindow, ModifierImport },
+  filters: {
+    statusFilter(value){
+      return STATUS_MAP[value]
+    }
+  },
   data() {
     return {
       listLoading: false,

+ 107 - 25
src/views/nutrientTemplate/detail.vue

@@ -20,24 +20,36 @@
         <el-autocomplete
           class="inline-input"
           v-model="params.unit"
-          :fetch-suggestions="queryNutrientUnits"
+          :fetch-suggestions="queryNutrientUnits(params.nutrientId)"
+          @input="handleUnitChanged"
           placeholder="单位关键词"
         />
+        <div v-show="showNutrientSource" style="display: inline-block">
+          营养素来源:
+          <el-select
+            v-model="params.nutrientSource"
+            placeholder="请选择营养素来源"
+          >
+            <el-option v-for="item in nutrientSources" :key="item" :label="item" :value="item" />
+          </el-select>
+        </div>
       </el-row>
       <el-row style="margin-top: 10px">
-        Nv_Spec计量:
-        <el-input
-          v-model="params.nvSpec"
-          style="width: 80px;"
-          class="filter-item"
-        />
-        Nv_Spec计量单位:
-        <el-autocomplete
-          class="inline-input"
-          v-model="params.nvSpecUnit"
-          :fetch-suggestions="queryUnits"
-          placeholder="单位关键词"
-        />
+        <div v-show="!isPercentByVolumeUnit(params)" style="display: inline-block">
+          Nv_Spec计量:
+          <el-input
+            v-model="params.nvSpec"
+            style="width: 80px;"
+            class="filter-item"
+          />
+          Nv_Spec计量单位:
+          <el-autocomplete
+            class="inline-input"
+            v-model="params.nvSpecUnit"
+            :fetch-suggestions="queryUnits"
+            placeholder="单位关键词"
+          />
+        </div>
         信息来源:
         <el-autocomplete
           v-model="params.source"
@@ -77,15 +89,24 @@
               <el-autocomplete
                 class="inline-input"
                 v-model="row.unit"
-                :fetch-suggestions="queryUnits"
+                @input="handleRowUnitChanged(row)"
+                :fetch-suggestions="queryNutrientUnits(row.nutrientId)"
                 placeholder="单位关键词"
               />
+              <el-select
+                clearable
+                v-show="showRowNutrientSource"
+                v-model="row.nutrientSource"
+                placeholder="请选择营养素来源"
+              >
+                <el-option v-for="item in nutrientSources" :key="item" :label="item" :value="item" />
+              </el-select>
             </template>
-            <span v-else>{{ row.unit }}</span>
+            <span v-else>{{ row.nutrientSource ? `${row.unit}(${row.nutrientSource})` : row.unit }}</span>
           </template>
         </el-table-column>
         <el-table-column label="Nv_Spec" align="center" width="100px">
-          <template slot-scope="{row}">
+          <template slot-scope="{row}" v-if="!isPercentByVolumeUnit(row)">
             <template v-if="row.edit">
               <el-input
                 v-model="row.nvSpec"
@@ -96,7 +117,7 @@
           </template>
         </el-table-column>
         <el-table-column label="Nv_Spec单位" align="center" width="150px">
-          <template slot-scope="{row}">
+          <template slot-scope="{row}" v-if="!isPercentByVolumeUnit(row)">
             <template v-if="row.edit">
               <el-autocomplete
                 class="inline-input"
@@ -147,7 +168,7 @@
               </el-button>
             </template>
             <template v-else>
-              <el-button size="mini" type="primary" @click="row.edit=true">编辑</el-button>
+              <el-button size="mini" type="primary" @click="handleEdit(row)">编辑</el-button>
               <el-button size="mini" type="danger" @click="removeNutrient(row)">
                 删除
               </el-button>
@@ -160,12 +181,15 @@
 </template>
 
 <script>
-import { getList, getNutrientUnits } from '@/api/nutrient'
+import { getList, getNutrientUnits, getNutrientSources } from '@/api/nutrient'
 import { getList as getUnits } from '@/api/unit'
 import { getNutrients, addTemplateNutrient, updateTemplateNutrient, removeNutrient,
   updateTemplateNutrientSort, updateBatchDetailSorts } from '@/api/nutrientTemplate'
 import Sortable from 'sortablejs'
 
+// 特殊营养素 若单位不为baseUnit,则需要填写来源
+const SPECIAL_NUTRIENT_NAMES = ['维生素A', '维生素D', '维生素E', '烟酸', '叶酸']
+
 export default {
   name: 'Detail',
   components: {},
@@ -177,11 +201,14 @@ export default {
       list: [],
       units: [],
       nutrients: [],
-      params: { source: '营养标签' },
+      params: { source: '营养标签', nutrientSource: null },
       loading: false,
       unitLoading: false,
       sources: [{ value: "营养标签" }, { value: "食品官方资料" }, { value: "计算值" }],
-      sortable: null
+      sortable: null,
+      showNutrientSource: false,
+      showRowNutrientSource: false,
+      nutrientSources: []
     }
   },
   created() {
@@ -202,7 +229,7 @@ export default {
         addTemplateNutrient(this.templateId, this.params).then(res => {
           this.fetchNutrients()
           this.$notify.success('添加成功')
-          this.params = { source: '营养标签' }
+          this.params = { source: '营养标签', nutrientSource: null }
           this.$nextTick(() => {
             this.$refs['nutrientSelect'].focus()
           })
@@ -281,9 +308,9 @@ export default {
         return (restaurant.value.toLowerCase().indexOf(query.toLowerCase()) === 0);
       };
     },
-    queryNutrientUnits(query, cb) {
+    queryNutrientUnits(query, nutrientId, cb) {
       let units = []
-      getNutrientUnits(this.params.nutrientId).then(res => {
+      getNutrientUnits(nutrientId, { query }).then(res => {
         res.data.forEach(item => units.push({ value: item }))
         cb(units)
       })
@@ -318,6 +345,61 @@ export default {
           })
         }
       })
+    },
+    isSpecialNutrient(nutrientId) {
+      let nutrient = null
+      for (let i = 0; i < this.nutrients.length; i++) {
+        if (this.nutrients[i].id === nutrientId) {
+          nutrient = this.nutrients[i]
+          break
+        }
+      }
+
+      // 如果特殊营养素单位不等于baseUnit,则显示来源
+      return nutrient && SPECIAL_NUTRIENT_NAMES.indexOf(nutrient.name) > -1
+    },
+    handleUnitChanged() {
+      if (this.isSpecialNutrient(this.params.nutrientId)) {
+        getNutrientSources(this.params.nutrientId, { unit: this.params.unit }).then(res => {
+          this.nutrientSources = res.data
+          if (this.nutrientSources.length > 0){
+            this.params.nutrientSource = this.nutrientSources[0]
+            this.showNutrientSource = true
+          } else {
+            this.showNutrientSource = false
+            this.params.nutrientSource = null
+          }
+        })
+      } else {
+        this.showNutrientSource = false
+        // this.params.nutrientSource = null
+      }
+    },
+    handleRowUnitChanged(row) {
+      if (SPECIAL_NUTRIENT_NAMES.indexOf(row.nutrientName) > -1) {
+        getNutrientSources(row.nutrientId, { unit: row.unit }).then(res => {
+          this.nutrientSources = res.data
+          if (this.nutrientSources.length > 0){
+            if (!row.nutrientSource) {
+              row.nutrientSource = this.nutrientSources[0]
+            }
+            this.showRowNutrientSource = true
+          } else {
+            this.showRowNutrientSource = false
+            row.nutrientSource = null
+          }
+        })
+      } else {
+        this.showRowNutrientSource = false
+        row.nutrientSource = null
+      }
+    },
+    handleEdit(row) {
+      row.edit = true
+      this.handleRowUnitChanged(row)
+    },
+    isPercentByVolumeUnit(row) {
+      return row && row.unit === '%Vol'
     }
   }
 }