| @@ -68,11 +68,6 @@ export default { | ||||
|     ]), | ||||
|     ...mapGetters(["analyseData"]), | ||||
|   }, | ||||
|   watch: { | ||||
|     healthyData(val) { | ||||
|       console.log({ val }); | ||||
|     }, | ||||
|   }, | ||||
|   methods: { | ||||
|     handleOnTabClick(tab) { | ||||
|       this.activeName = tab.name; | ||||
|   | ||||
| @@ -3,7 +3,16 @@ | ||||
|     <!-- 营养分析 --> | ||||
|     <!-- <NutriComputeCom :date="date" :value="value" /> --> | ||||
|     <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> | ||||
|     <!-- 食谱详细 --> | ||||
|     <el-card v-for="obj in menus" :key="obj.type" style="margin-top: 12px"> | ||||
| @@ -34,6 +43,8 @@ | ||||
|     </el-card> | ||||
|     <!-- 复杂菜品展示 --> | ||||
|     <DishesDetailDialog ref="detailDialogRef" /> | ||||
|     <!-- 当天采购计划 --> | ||||
|     <TodayShoppingPlanDrawer ref="shoppingPlanRef" /> | ||||
|   </div> | ||||
| </template> | ||||
| <script> | ||||
| @@ -46,12 +57,14 @@ const { | ||||
| } = createNamespacedHelpers("recipesShow"); | ||||
| // import NutriComputeCom from "./NutriComputeCom"; | ||||
| import DishesDetailDialog from "./DishesDetailDialog"; | ||||
| import TodayShoppingPlanDrawer from "../PlanDrawer/ShoppingPlanDrawer"; | ||||
| export default { | ||||
|   name: "menuDetail", | ||||
|   props: ["value", "date"], | ||||
|   components: { | ||||
|     // NutriComputeCom, | ||||
|     DishesDetailDialog, | ||||
|     TodayShoppingPlanDrawer, | ||||
|   }, | ||||
|   data() { | ||||
|     return { | ||||
| @@ -99,6 +112,17 @@ export default { | ||||
|     handleOnDetailClick(data) { | ||||
|       this.$refs["detailDialogRef"].showDialog(data); | ||||
|     }, | ||||
|     handleOnShoppingPlanClick() { | ||||
|       this.$refs["shoppingPlanRef"].showDrawer({ | ||||
|         num: -1, | ||||
|         data: [ | ||||
|           { | ||||
|             dishes: this.value, | ||||
|           }, | ||||
|         ], | ||||
|         label: this.date, | ||||
|       }); | ||||
|     }, | ||||
|   }, | ||||
| }; | ||||
| </script> | ||||
| @@ -106,8 +130,27 @@ export default { | ||||
| .menu_detail_wrapper { | ||||
|   padding: 0 12px 12px 12px; | ||||
|   .top { | ||||
|     text-align: center; | ||||
|     padding: 10px 14px; | ||||
|     height: 50px; | ||||
|     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 { | ||||
|   | ||||
| @@ -74,17 +74,19 @@ export default { | ||||
|     }; | ||||
|   }, | ||||
|   methods: { | ||||
|     showDrawer(data) { | ||||
|       // console.log(data); | ||||
|       const { recipesId, num, label } = data; | ||||
|     showDrawer(obj) { | ||||
|       const { recipesId, num, label, data } = obj; | ||||
|       console.log(obj); | ||||
|       this.label = label; | ||||
|       // num < 0 全部计算 | ||||
|       this.title = `${ | ||||
|         num === 3 ? "前3" : num === 4 ? "后4" : Math.abs(num) | ||||
|       }天采购计划`; | ||||
|       this.visible = true; | ||||
|       if (this.recipes[recipesId]) { | ||||
|         this.processShoppingCart(num, recipesId); | ||||
|       if (data) { | ||||
|         this.processShoppingCart(num, data); | ||||
|       } else if (this.recipes[recipesId]) { | ||||
|         this.processShoppingCart(num, this.recipes[recipesId]); | ||||
|       } else { | ||||
|         this.loading = true; | ||||
|         this.fetchFullRecipes({ | ||||
| @@ -92,61 +94,56 @@ export default { | ||||
|         }).then(() => { | ||||
|           this.loading = false; | ||||
|           setTimeout(() => { | ||||
|             this.processShoppingCart(num, recipesId); | ||||
|             this.processShoppingCart(num, this.recipes[recipesId]); | ||||
|           }, 0); | ||||
|         }); | ||||
|       } | ||||
|     }, | ||||
|     processShoppingCart(num, recipesId) { | ||||
|       this.shoppingCart = (this.recipes[recipesId] || []).reduce( | ||||
|         (obj, cur, idx) => { | ||||
|           if ( | ||||
|             num < 0 || // 全部计算 | ||||
|             num === 7 || | ||||
|             (num === 3 && num > idx) || | ||||
|             (num === 4 && idx > 2) | ||||
|           ) { | ||||
|             cur.dishes.forEach((dObj) => { | ||||
|               dObj.igdList.forEach((iObj) => { | ||||
|                 const tarTypeName = this.idgTypeDict[iObj.type]; | ||||
|                 const tarObj = obj[tarTypeName]; | ||||
|                 if (tarObj) { | ||||
|                   const tarIObj = tarObj.find( | ||||
|                     (zObj) => zObj.name === iObj.name | ||||
|                   ); | ||||
|                   if (tarIObj) { | ||||
|                     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", | ||||
|                     }); | ||||
|                   } | ||||
|     processShoppingCart(num, data = []) { | ||||
|       this.shoppingCart = data.reduce((obj, cur, idx) => { | ||||
|         if ( | ||||
|           num < 0 || // 全部计算 | ||||
|           num === 7 || | ||||
|           (num === 3 && num > idx) || | ||||
|           (num === 4 && idx > 2) | ||||
|         ) { | ||||
|           cur.dishes.forEach((dObj) => { | ||||
|             dObj.igdList.forEach((iObj) => { | ||||
|               const tarTypeName = this.idgTypeDict[iObj.type]; | ||||
|               const tarObj = obj[tarTypeName]; | ||||
|               if (tarObj) { | ||||
|                 const tarIObj = tarObj.find((zObj) => zObj.name === iObj.name); | ||||
|                 if (tarIObj) { | ||||
|                   tarIObj.weight += this.igdUnitDict[iObj.name] | ||||
|                     ? iObj.cusWeight | ||||
|                     : iObj.weight; | ||||
|                 } else { | ||||
|                   obj[tarTypeName] = [ | ||||
|                     { | ||||
|                       type: iObj.type, | ||||
|                       name: iObj.name, | ||||
|                       weight: this.igdUnitDict[iObj.name] | ||||
|                         ? iObj.cusWeight | ||||
|                         : iObj.weight, | ||||
|                       unit: this.igdUnitDict[iObj.name] || "g", | ||||
|                     }, | ||||
|                   ]; | ||||
|                   tarObj.push({ | ||||
|                     type: iObj.type, | ||||
|                     name: iObj.name, | ||||
|                     weight: this.igdUnitDict[iObj.name] | ||||
|                       ? iObj.cusWeight | ||||
|                       : iObj.weight, | ||||
|                     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); | ||||
|     }, | ||||
|     handleOnBackClick() { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user