新增当天采购计划

This commit is contained in:
huangdeliang 2021-03-24 17:16:49 +08:00
parent c4d1cba225
commit 51a9c5c798
3 changed files with 96 additions and 61 deletions

View File

@ -68,11 +68,6 @@ export default {
]), ]),
...mapGetters(["analyseData"]), ...mapGetters(["analyseData"]),
}, },
watch: {
healthyData(val) {
console.log({ val });
},
},
methods: { methods: {
handleOnTabClick(tab) { handleOnTabClick(tab) {
this.activeName = tab.name; this.activeName = tab.name;

View File

@ -3,7 +3,16 @@
<!-- 营养分析 --> <!-- 营养分析 -->
<!-- <NutriComputeCom :date="date" :value="value" /> --> <!-- <NutriComputeCom :date="date" :value="value" /> -->
<div class="top"> <div class="top">
<img :src="logo" style="width: auto; height: 32px" alt="logo" /> <img
class="logo"
:src="logo"
style="width: auto; height: 32px"
alt="logo"
/>
<em
class="el-icon-shopping-cart-full icon_style shopping_cart"
@click="handleOnShoppingPlanClick"
/>
</div> </div>
<!-- 食谱详细 --> <!-- 食谱详细 -->
<el-card v-for="obj in menus" :key="obj.type" style="margin-top: 12px"> <el-card v-for="obj in menus" :key="obj.type" style="margin-top: 12px">
@ -34,6 +43,8 @@
</el-card> </el-card>
<!-- 复杂菜品展示 --> <!-- 复杂菜品展示 -->
<DishesDetailDialog ref="detailDialogRef" /> <DishesDetailDialog ref="detailDialogRef" />
<!-- 当天采购计划 -->
<TodayShoppingPlanDrawer ref="shoppingPlanRef" />
</div> </div>
</template> </template>
<script> <script>
@ -46,12 +57,14 @@ const {
} = createNamespacedHelpers("recipesShow"); } = createNamespacedHelpers("recipesShow");
// import NutriComputeCom from "./NutriComputeCom"; // import NutriComputeCom from "./NutriComputeCom";
import DishesDetailDialog from "./DishesDetailDialog"; import DishesDetailDialog from "./DishesDetailDialog";
import TodayShoppingPlanDrawer from "../PlanDrawer/ShoppingPlanDrawer";
export default { export default {
name: "menuDetail", name: "menuDetail",
props: ["value", "date"], props: ["value", "date"],
components: { components: {
// NutriComputeCom, // NutriComputeCom,
DishesDetailDialog, DishesDetailDialog,
TodayShoppingPlanDrawer,
}, },
data() { data() {
return { return {
@ -99,6 +112,17 @@ export default {
handleOnDetailClick(data) { handleOnDetailClick(data) {
this.$refs["detailDialogRef"].showDialog(data); this.$refs["detailDialogRef"].showDialog(data);
}, },
handleOnShoppingPlanClick() {
this.$refs["shoppingPlanRef"].showDrawer({
num: -1,
data: [
{
dishes: this.value,
},
],
label: this.date,
});
},
}, },
}; };
</script> </script>
@ -106,8 +130,27 @@ export default {
.menu_detail_wrapper { .menu_detail_wrapper {
padding: 0 12px 12px 12px; padding: 0 12px 12px 12px;
.top { .top {
text-align: center; height: 50px;
padding: 10px 14px; position: relative;
.logo {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.shopping_cart {
position: absolute;
right: 5px;
top: 10px;
display: flex;
align-items: center;
&::after {
margin-left: 2px;
content: "采购";
font-size: 12px;
}
}
} }
.header_style { .header_style {

View File

@ -74,17 +74,19 @@ export default {
}; };
}, },
methods: { methods: {
showDrawer(data) { showDrawer(obj) {
// console.log(data); const { recipesId, num, label, data } = obj;
const { recipesId, num, label } = data; console.log(obj);
this.label = label; this.label = label;
// num < 0 // num < 0
this.title = `${ this.title = `${
num === 3 ? "前3" : num === 4 ? "后4" : Math.abs(num) num === 3 ? "前3" : num === 4 ? "后4" : Math.abs(num)
}天采购计划`; }天采购计划`;
this.visible = true; this.visible = true;
if (this.recipes[recipesId]) { if (data) {
this.processShoppingCart(num, recipesId); this.processShoppingCart(num, data);
} else if (this.recipes[recipesId]) {
this.processShoppingCart(num, this.recipes[recipesId]);
} else { } else {
this.loading = true; this.loading = true;
this.fetchFullRecipes({ this.fetchFullRecipes({
@ -92,61 +94,56 @@ export default {
}).then(() => { }).then(() => {
this.loading = false; this.loading = false;
setTimeout(() => { setTimeout(() => {
this.processShoppingCart(num, recipesId); this.processShoppingCart(num, this.recipes[recipesId]);
}, 0); }, 0);
}); });
} }
}, },
processShoppingCart(num, recipesId) { processShoppingCart(num, data = []) {
this.shoppingCart = (this.recipes[recipesId] || []).reduce( this.shoppingCart = data.reduce((obj, cur, idx) => {
(obj, cur, idx) => { if (
if ( num < 0 || //
num < 0 || // num === 7 ||
num === 7 || (num === 3 && num > idx) ||
(num === 3 && num > idx) || (num === 4 && idx > 2)
(num === 4 && idx > 2) ) {
) { cur.dishes.forEach((dObj) => {
cur.dishes.forEach((dObj) => { dObj.igdList.forEach((iObj) => {
dObj.igdList.forEach((iObj) => { const tarTypeName = this.idgTypeDict[iObj.type];
const tarTypeName = this.idgTypeDict[iObj.type]; const tarObj = obj[tarTypeName];
const tarObj = obj[tarTypeName]; if (tarObj) {
if (tarObj) { const tarIObj = tarObj.find((zObj) => zObj.name === iObj.name);
const tarIObj = tarObj.find( if (tarIObj) {
(zObj) => zObj.name === iObj.name tarIObj.weight += this.igdUnitDict[iObj.name]
); ? iObj.cusWeight
if (tarIObj) { : iObj.weight;
tarIObj.weight += this.igdUnitDict[iObj.name]
? iObj.cusWeight
: iObj.weight;
} else {
tarObj.push({
type: iObj.type,
name: iObj.name,
weight: this.igdUnitDict[iObj.name]
? iObj.cusWeight
: iObj.weight,
unit: this.igdUnitDict[iObj.name] || "g",
});
}
} else { } else {
obj[tarTypeName] = [ tarObj.push({
{ type: iObj.type,
type: iObj.type, name: iObj.name,
name: iObj.name, weight: this.igdUnitDict[iObj.name]
weight: this.igdUnitDict[iObj.name] ? iObj.cusWeight
? iObj.cusWeight : iObj.weight,
: iObj.weight, unit: this.igdUnitDict[iObj.name] || "g",
unit: this.igdUnitDict[iObj.name] || "g", });
},
];
} }
}); } else {
obj[tarTypeName] = [
{
type: iObj.type,
name: iObj.name,
weight: this.igdUnitDict[iObj.name]
? iObj.cusWeight
: iObj.weight,
unit: this.igdUnitDict[iObj.name] || "g",
},
];
}
}); });
} });
return obj; }
}, return obj;
{} }, {});
);
// console.log(this.shoppingCart); // console.log(this.shoppingCart);
}, },
handleOnBackClick() { handleOnBackClick() {