wangyang пре 5 година
родитељ
комит
30389ae266
2 измењених фајлова са 13 додато и 16 уклоњено
  1. 5 5
      src/api/food.js
  2. 8 11
      src/views/recipe/food.vue

+ 5 - 5
src/api/food.js

@@ -136,11 +136,11 @@ export function removeFoodUnit(id, data) {
   })
 }
 
-// 查询食物信息,用于菜谱食物选择
-export function getFoodBriefInfos(params) {
+// 获取食物允许填入的单位列表
+export function getFoodAllUnits(id) {
   return request({
-    url: `/api/foods/brief-infos`,
-    method: 'get',
-    params
+    url: `/api/foods/${id}/unit-names`,
+    method: 'get'
   })
 }
+

+ 8 - 11
src/views/recipe/food.vue

@@ -28,7 +28,7 @@
         class="filter-item"
       />
       <el-select
-        v-model="params.unitName"
+        v-model="params.unit"
         style="width: 200px;margin-left: 10px;"
       >
         <el-option
@@ -67,7 +67,7 @@
       </el-table-column>
       <el-table-column label="用量" align="center">
         <template slot-scope="{row}">
-          <span>{{ row.quantity + row.unitName }}</span>
+          <span>{{ row.quantity + row.unit }}</span>
         </template>
       </el-table-column>
       <el-table-column label="主材/辅材" align="center">
@@ -87,7 +87,7 @@
 </template>
 
 <script>
-import { getFoodBriefInfos } from '@/api/food'
+import { getList, getFoodAllUnits } from '@/api/food'
 import { getRecipeFoods, addFood, removeRecipeFood } from '@/api/recipe'
 
 const foodTypeMapping = { 0: '主材', 1: '辅材' }
@@ -129,7 +129,7 @@ export default {
       })
     },
     queryFoods(query) {
-      getFoodBriefInfos({ query }).then(res => {
+      getList({ query }).then(res => {
         this.foods = res.data.list
       }).catch(() => {
         this.foods = []
@@ -137,15 +137,12 @@ export default {
     },
     changeUnits(value) {
       this.units = []
-      for (let i=0; i < this.foods.length; i++) {
-        if (this.foods[i].id === value){
-          this.units = this.foods[i].unitNames
-          break
-        }
-      }
+      getFoodAllUnits(value).then(res => {
+        this.units = res.data.list
+      })
     },
     addFood() {
-      if (!this.params.foodId || !this.params.unitName || !this.params.quantity) {
+      if (!this.params.foodId || !this.params.unit || !this.params.quantity) {
         this.$message.error('请完善录入信息')
         return
       }