菜品增删查改对接
This commit is contained in:
@ -1,8 +1,31 @@
|
||||
import request from "@/utils/request";
|
||||
|
||||
export function getRecipes(id) {
|
||||
export function getRecipesApi(id) {
|
||||
return request({
|
||||
url: "/recipes/" + id,
|
||||
url: "/custom/recipes/" + id,
|
||||
method: "get"
|
||||
});
|
||||
}
|
||||
|
||||
export function updateDishesDetailApi(data) {
|
||||
return request({
|
||||
url: "/custom/recipes",
|
||||
method: "put",
|
||||
data
|
||||
});
|
||||
}
|
||||
|
||||
export function addDishesApi(data) {
|
||||
return request({
|
||||
url: "/custom/recipes",
|
||||
method: "post",
|
||||
data
|
||||
});
|
||||
}
|
||||
|
||||
export function deleteDishesApi(cid) {
|
||||
return request({
|
||||
url: "/custom/recipes/dishes/" + cid,
|
||||
method: "delete"
|
||||
});
|
||||
}
|
||||
|
@ -2,11 +2,18 @@ import { getOrder } from "@/api/custom/order";
|
||||
import { getCustomerPhysicalSignsByCusId } from "@/api/custom/customer";
|
||||
import { dealHealthy } from "@/utils/healthyData";
|
||||
import { getRecipesPlan } from "@/api/custom/recipesPlan";
|
||||
import { getRecipes } from "@/api/custom/recipes";
|
||||
import {
|
||||
getRecipesApi,
|
||||
updateDishesDetailApi,
|
||||
addDishesApi,
|
||||
deleteDishesApi
|
||||
} from "@/api/custom/recipes";
|
||||
import { getDicts } from "@/api/system/dict/data";
|
||||
import produce from "immer";
|
||||
import { updateDishes } from "@/api/custom/dishes";
|
||||
|
||||
const oriState = {
|
||||
recipesId: undefined,
|
||||
healthyData: {},
|
||||
healthyDataType: 0,
|
||||
recipesData: [],
|
||||
@ -18,6 +25,9 @@ const oriState = {
|
||||
};
|
||||
|
||||
const mutations = {
|
||||
setRecipiesId(state, payload) {
|
||||
state.recipesId = payload.recipesId;
|
||||
},
|
||||
setHealtyData(state, payload) {
|
||||
state.healthyDataType = payload.healthyDataType;
|
||||
state.healthyData = payload.healthyData;
|
||||
@ -40,7 +50,6 @@ const mutations = {
|
||||
}
|
||||
},
|
||||
addRecipesDishes(state, payload) {
|
||||
|
||||
state.recipesData[payload.num].dishes.push(payload.data);
|
||||
},
|
||||
updateOptions(state, payload) {
|
||||
@ -104,7 +113,7 @@ const actions = {
|
||||
|
||||
// 食谱数据
|
||||
if (payload.recipesId) {
|
||||
const recipesDataResult = await getRecipes(payload.recipesId);
|
||||
const recipesDataResult = await getRecipesApi(payload.recipesId);
|
||||
if (recipesDataResult.code === 200) {
|
||||
commit("setRecipesData", {
|
||||
recipesData: recipesDataResult.data.map(dayData => {
|
||||
@ -120,6 +129,7 @@ const actions = {
|
||||
) {
|
||||
arr.push({
|
||||
id: cur.id,
|
||||
cid: cur.cid,
|
||||
name: cur.name,
|
||||
methods: cur.methods,
|
||||
type: cur.type,
|
||||
@ -162,7 +172,89 @@ const actions = {
|
||||
throw new Error(recipesDataResult.msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
async saveRecipes({ commit, state }, payload) {
|
||||
const { recipesData } = state;
|
||||
const params = recipesData.map(menu => {
|
||||
return menu.dishes.map(dObj => {
|
||||
return {
|
||||
dishesId: dObj.id,
|
||||
type: dObj.type,
|
||||
detail: dObj.igdList.map(igd => ({
|
||||
id: igd.id,
|
||||
weight: igd.weight,
|
||||
cus_unit: igd.cusUnit,
|
||||
cus_weight: igd.cusWeight
|
||||
}))
|
||||
};
|
||||
});
|
||||
});
|
||||
console.log(params);
|
||||
},
|
||||
async addDishes({ commit, state }, payload) {
|
||||
const tarRecipesObj = state.recipesData[payload.num];
|
||||
if (tarRecipesObj && payload.data) {
|
||||
const { id, type, igdList } = payload.data;
|
||||
const params = {
|
||||
menuId: tarRecipesObj.id,
|
||||
id: id,
|
||||
type: type,
|
||||
detail: igdList.map(igd => ({
|
||||
id: igd.id,
|
||||
weight: igd.weight,
|
||||
cus_unit: igd.cusUnit,
|
||||
cus_weight: igd.cusWeight
|
||||
}))
|
||||
};
|
||||
const result = await addDishesApi(params);
|
||||
if (result.code === 200) {
|
||||
payload.data.cid = result.data;
|
||||
commit("addRecipesDishes", payload);
|
||||
}
|
||||
console.log(result);
|
||||
}
|
||||
},
|
||||
async updateDishes({ commit, state }, payload) {
|
||||
const tarDishes = state.recipesData[payload.num].dishes.find(
|
||||
obj => obj.id === payload.dishesId
|
||||
);
|
||||
if (tarDishes) {
|
||||
const mTarDishes = JSON.parse(JSON.stringify(tarDishes));
|
||||
const tarIgd = mTarDishes.igdList.find(obj => obj.id === payload.igdId);
|
||||
if (tarIgd) {
|
||||
payload.weight && (tarIgd.weight = payload.weight);
|
||||
payload.cusWeight && (tarIgd.cusWeight = payload.cusWeight);
|
||||
payload.cusUnit && (tarIgd.cusUnit = payload.cusUnit);
|
||||
|
||||
const params = {
|
||||
cid: mTarDishes.cid,
|
||||
detail: mTarDishes.igdList.map(igd => ({
|
||||
id: igd.id,
|
||||
weight: igd.weight,
|
||||
cus_unit: igd.cusUnit,
|
||||
cus_weight: igd.cusWeight
|
||||
}))
|
||||
};
|
||||
const result = await updateDishesDetailApi(params);
|
||||
if (result.code === 200) {
|
||||
commit("updateRecipesDishesDetail", payload);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
async deleteDishes({ commit, state }, payload) {
|
||||
const tarDishes = state.recipesData[payload.num].dishes.find(
|
||||
obj => obj.id === payload.dishesId
|
||||
);
|
||||
if (tarDishes) {
|
||||
const result = await deleteDishesApi(tarDishes.cid);
|
||||
if (result.code === 200) {
|
||||
commit("deleteSomeDayDishes", payload);
|
||||
}
|
||||
// console.log(params);
|
||||
}
|
||||
},
|
||||
async deleteMenu({ commit }, payload) {}
|
||||
};
|
||||
|
||||
const getters = {
|
||||
|
@ -4,6 +4,9 @@
|
||||
:style="`height: ${collapse ? 30 : 200}px`"
|
||||
>
|
||||
<div class="header">
|
||||
<el-button size="mini" type="primary" @click="handleOnSave"
|
||||
>保存</el-button
|
||||
>
|
||||
<el-button size="mini" type="text" @click="handleCollapseClick">{{
|
||||
`${collapse ? "展开分析" : "收起分析"}`
|
||||
}}</el-button>
|
||||
@ -25,6 +28,8 @@
|
||||
<script>
|
||||
import BarChart from "./BarChart";
|
||||
import PieChart from "./PieChart";
|
||||
import { createNamespacedHelpers } from "vuex";
|
||||
const { mapActions } = createNamespacedHelpers("recipes");
|
||||
export default {
|
||||
name: "RecipesAspectCom",
|
||||
components: {
|
||||
@ -43,6 +48,10 @@ export default {
|
||||
handleCollapseClick() {
|
||||
this.$emit("update:collapse", !this.collapse);
|
||||
},
|
||||
handleOnSave() {
|
||||
this.saveRecipes();
|
||||
},
|
||||
...mapActions(["saveRecipes"]),
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
@ -18,7 +18,9 @@
|
||||
}}</span>
|
||||
</template>
|
||||
<template slot-scope="scope">
|
||||
<span style="font-weight: bold; font-size: 14px">{{ typeFormatter(scope.row) }}</span>
|
||||
<span style="font-weight: bold; font-size: 14px">{{
|
||||
typeFormatter(scope.row)
|
||||
}}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="菜品" prop="name" align="center">
|
||||
@ -270,11 +272,11 @@ export default {
|
||||
},
|
||||
handleOnDelete(data) {
|
||||
// console.log(data);
|
||||
this.deleteSomeDayDishes({ num: this.num - 1, dishesId: data.id });
|
||||
this.deleteDishes({ num: this.num - 1, dishesId: data.id });
|
||||
},
|
||||
handleOnWeightChange(data, weight) {
|
||||
// console.log({ data, weight });
|
||||
this.updateRecipesDishesDetail({
|
||||
this.updateDishes({
|
||||
num: this.num - 1,
|
||||
dishesId: data.id,
|
||||
igdId: data.igdId,
|
||||
@ -282,7 +284,7 @@ export default {
|
||||
});
|
||||
},
|
||||
handleOnCustomUnitChange(data, { cusWeight, cusUnit }) {
|
||||
this.updateRecipesDishesDetail({
|
||||
this.updateDishes({
|
||||
num: this.num - 1,
|
||||
dishesId: data.id,
|
||||
igdId: data.igdId,
|
||||
@ -291,17 +293,13 @@ export default {
|
||||
});
|
||||
},
|
||||
handleOnDishesConfirm(data) {
|
||||
this.addRecipesDishes({
|
||||
this.addDishes({
|
||||
num: this.num - 1,
|
||||
data,
|
||||
});
|
||||
},
|
||||
...mapMutations([
|
||||
"setCurrentDay",
|
||||
"deleteSomeDayDishes",
|
||||
"updateRecipesDishesDetail",
|
||||
"addRecipesDishes",
|
||||
]),
|
||||
...mapActions(["updateDishes", "addDishes", "deleteDishes"]),
|
||||
...mapMutations(["setCurrentDay",]),
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
Reference in New Issue
Block a user