Преглед на файлове

完善食物录入排序

wangyang преди 5 години
родител
ревизия
bdcd5cb912
променени са 3 файла, в които са добавени 47 реда и са изтрити 4 реда
  1. 18 0
      src/api/food.js
  2. 13 2
      src/views/food/nutrient.vue
  3. 16 2
      src/views/foodModifier/index.vue

+ 18 - 0
src/api/food.js

@@ -61,6 +61,15 @@ export function updateFoodNutrient(id, nutrientId, data) {
   })
 }
 
+// 更新食物关联的营养素的排序
+export function updateFoodNutrientSort(id, nutrientId, data) {
+  return request({
+    url: `/api/foods/${id}/nutrients/${nutrientId}/sorts`,
+    method: 'post',
+    data
+  })
+}
+
 // 删除食物关联的营养素
 export function removeFoodNutrient(foodId, nutrientId) {
   return request({
@@ -95,6 +104,15 @@ export function updateFoodModifier(id, modifierId, data) {
   })
 }
 
+// 更新食物规格排序
+export function updateFoodModifierSort(id, modifierId, data) {
+  return request({
+    url: `/api/foods/${id}/modifiers/${modifierId}/sorts`,
+    method: 'post',
+    data
+  })
+}
+
 // 删除食物规格
 export function removeFoodModifier(id, modifierId) {
   return request({

+ 13 - 2
src/views/food/nutrient.vue

@@ -96,7 +96,7 @@
           <span v-else>{{ row.nvSpecUnit }}</span>
         </template>
       </el-table-column>
-      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="160">
+      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="320">
         <template slot-scope="{row}">
           <template v-if="row.edit">
             <el-button
@@ -116,6 +116,8 @@
           </template>
           <template v-else>
             <el-button size="mini" type="primary" @click="row.edit=true">编辑</el-button>
+            <el-button size="mini" type="primary" @click="updateSort(row, 0)">上移</el-button>
+            <el-button size="mini" type="primary" @click="updateSort(row, 1)">下移</el-button>
             <el-button size="mini" type="danger" @click="removeNutrient(row)">
               删除
             </el-button>
@@ -127,7 +129,8 @@
 </template>
 
 <script>
-import { getNutrientList, addFoodNutrient, updateFoodNutrient, removeFoodNutrient } from '@/api/food'
+import { getNutrientList, addFoodNutrient, updateFoodNutrient, removeFoodNutrient,
+  updateFoodNutrientSort } from '@/api/food'
 import { getList } from '@/api/nutrient'
 import { getList as getUnits } from '@/api/unit'
 
@@ -212,6 +215,14 @@ export default {
         res.data.list.forEach(item => units.push({ value: item.name }))
         cb(units)
       })
+    },
+    updateSort(row, type) {
+      updateFoodNutrientSort(this.foodId, row.nutrientId, { type }).then(res => {
+        this.$notify.success('提交成功')
+        this.fetchData()
+      }).catch(res => {
+        this.$message.error(res.data.message)
+      })
     }
   }
 }

+ 16 - 2
src/views/foodModifier/index.vue

@@ -62,11 +62,17 @@
           <span>{{ row.updateTime }}</span>
         </template>
       </el-table-column>
-      <el-table-column label="操作" align="center" class-name="small-padding">
+      <el-table-column label="操作" align="center" class-name="small-padding" width="320">
         <template slot-scope="{row}">
           <el-button type="primary" size="mini" @click="handleUpdate(row)">
             更新
           </el-button>
+          <el-button type="primary" size="mini" @click="updateSort(row, 0)">
+            上移
+          </el-button>
+          <el-button type="primary" size="mini" @click="updateSort(row, 1)">
+            下移
+          </el-button>
           <el-button size="mini" type="danger" @click="handleDelete(row)">
             删除
           </el-button>
@@ -77,7 +83,7 @@
 </template>
 
 <script>
-import { getFoodModifiers, removeFoodModifier } from '@/api/food'
+import { getFoodModifiers, removeFoodModifier, updateFoodModifierSort } from '@/api/food'
 
 export default {
   name: 'FoodModifierIndex',
@@ -117,6 +123,14 @@ export default {
         this.$message.error('获取数据失败')
         this.listLoading = false
       })
+    },
+    updateSort(row, type) {
+      updateFoodModifierSort(this.foodId, row.id, { type }).then(res => {
+        this.$notify.success('提交成功')
+        this.fetchData()
+      }).catch(res => {
+        this.$message.error(res.data.message)
+      })
     }
   }
 }