From 36384820bb123bff5c7cff9d3750c62725794cfd Mon Sep 17 00:00:00 2001
From: huangdeliang <huangdeliang@skieer.com>
Date: Fri, 26 Mar 2021 16:55:55 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=90=8C=E4=B8=80=E5=A4=A9?=
 =?UTF-8?q?=E5=90=8C=E4=B8=80=E9=A4=90=E5=88=AB=E8=8F=9C=E5=90=8D=E7=9B=B8?=
 =?UTF-8?q?=E5=90=8C=E5=90=88=E5=B9=B6=E7=9A=84=E6=83=85=E5=86=B5?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../RecipesView/RecipesCom/index.vue          | 82 +------------------
 .../RecipesView/RecipesCom/utils.js           | 81 ++++++++++++++++++
 .../RecipesView/RecipesHeaderCom/index.vue    |  3 +-
 3 files changed, 85 insertions(+), 81 deletions(-)
 create mode 100644 stdiet-ui/src/views/custom/recipesBuild/RecipesView/RecipesCom/utils.js

diff --git a/stdiet-ui/src/views/custom/recipesBuild/RecipesView/RecipesCom/index.vue b/stdiet-ui/src/views/custom/recipesBuild/RecipesView/RecipesCom/index.vue
index c32af5eb9..db4af82eb 100644
--- a/stdiet-ui/src/views/custom/recipesBuild/RecipesView/RecipesCom/index.vue
+++ b/stdiet-ui/src/views/custom/recipesBuild/RecipesView/RecipesCom/index.vue
@@ -275,6 +275,7 @@ import AddDishesDrawer from "./AddDishesDrawer";
 import DishesSettingDialog from "./DishesSettingDialog";
 import VueScrollTo from "vue-scrollto";
 import RemarkDialog from "./RemarkDialog";
+import { processMenuData } from "./utils";
 
 export default {
   name: "RecipesCom",
@@ -318,86 +319,7 @@ export default {
       if (!this.data.dishes) {
         return [];
       }
-      const mData = this.data.dishes
-        .sort((a, b) => a.type - b.type)
-        .reduce((arr, cur, idx) => {
-          if (cur.dishesId > 0 && cur.type !== "0") {
-            cur.igdList.forEach((igd) => {
-              let lastTypeHit = false,
-                lastNameHit = false;
-              if (arr.length > 0) {
-                // 倒推,找到第一个出现的位置
-                lastTypeHit = arr[arr.length - 1].type === cur.type;
-                if (lastTypeHit) {
-                  let typePos = arr.length - 1;
-                  for (let i = typePos; i >= 0; i--) {
-                    if (arr[i].type !== cur.type) {
-                      break;
-                    }
-                    typePos = i;
-                  }
-                  arr[typePos].typeSpan.rowspan += 1;
-                }
-                lastNameHit =
-                  arr[arr.length - 1].name === cur.name &&
-                  arr[arr.length - 1].type === cur.type;
-                // arr[arr.length - 1].dishesId === cur.dishesId;
-                if (lastNameHit) {
-                  let namePos = arr.length - 1;
-                  for (let i = namePos; i >= 0; i--) {
-                    if (arr[i].name !== cur.name) {
-                      break;
-                    }
-                    namePos = i;
-                  }
-                  arr[namePos].nameSpan.rowspan += 1;
-                }
-              }
-
-              // console.log(cur);
-              arr.push({
-                id: cur.id,
-                dishesId: cur.dishesId,
-                menuId: cur.menuId,
-                name: cur.name,
-                type: cur.type,
-                isMain: cur.isMain,
-                methods: cur.methods,
-                remark: cur.remark,
-                igdId: igd.id,
-                igdType: igd.type,
-                igdName: igd.name,
-                proteinRatio: igd.proteinRatio,
-                fatRatio: igd.fatRatio,
-                carbonRatio: igd.carbonRatio,
-                rec: igd.rec,
-                notRec: igd.notRec,
-                weight: igd.weight,
-                cusWeight: igd.cusWeight,
-                cusUnit: igd.cusUnit,
-                typeSpan: lastTypeHit
-                  ? {
-                      rowspan: 0,
-                      colspan: 0,
-                    }
-                  : {
-                      rowspan: 1,
-                      colspan: 1,
-                    },
-                nameSpan: lastNameHit
-                  ? {
-                      rowspan: 0,
-                      colspan: 0,
-                    }
-                  : {
-                      rowspan: 1,
-                      colspan: 1,
-                    },
-              });
-            });
-          }
-          return arr;
-        }, []);
+      const mData = processMenuData(this.data.dishes);
       // console.log(mData);
 
       return mData;
diff --git a/stdiet-ui/src/views/custom/recipesBuild/RecipesView/RecipesCom/utils.js b/stdiet-ui/src/views/custom/recipesBuild/RecipesView/RecipesCom/utils.js
new file mode 100644
index 000000000..e9a834d81
--- /dev/null
+++ b/stdiet-ui/src/views/custom/recipesBuild/RecipesView/RecipesCom/utils.js
@@ -0,0 +1,81 @@
+export function processMenuData(dishes) {
+  return dishes
+    .sort((a, b) => a.type - b.type)
+    .reduce((arr, cur) => {
+      if (cur.dishesId > 0 && cur.type !== "0") {
+        cur.igdList.forEach(igd => {
+          let lastTypeHit = false,
+            lastNameHit = false;
+          if (arr.length > 0) {
+            // 倒推,找到第一个出现的位置
+            lastTypeHit = arr[arr.length - 1].type === cur.type;
+            if (lastTypeHit) {
+              let typePos = arr.length - 1;
+              for (let i = typePos; i >= 0; i--) {
+                if (arr[i].type !== cur.type) {
+                  break;
+                }
+                typePos = i;
+              }
+              arr[typePos].typeSpan.rowspan += 1;
+            }
+            lastNameHit =
+              arr[arr.length - 1].dishesId === cur.dishesId &&
+              arr[arr.length - 1].type === cur.type;
+            if (lastNameHit) {
+              let namePos = arr.length - 1;
+              for (let i = namePos; i >= 0; i--) {
+                if (arr[i].dishesId !== cur.dishesId) {
+                  break;
+                }
+                namePos = i;
+              }
+              arr[namePos].nameSpan.rowspan += 1;
+            }
+          }
+
+          // console.log(cur);
+          arr.push({
+            id: cur.id,
+            dishesId: cur.dishesId,
+            menuId: cur.menuId,
+            name: cur.name,
+            type: cur.type,
+            isMain: cur.isMain,
+            methods: cur.methods,
+            remark: cur.remark,
+            igdId: igd.id,
+            igdType: igd.type,
+            igdName: igd.name,
+            proteinRatio: igd.proteinRatio,
+            fatRatio: igd.fatRatio,
+            carbonRatio: igd.carbonRatio,
+            rec: igd.rec,
+            notRec: igd.notRec,
+            weight: igd.weight,
+            cusWeight: igd.cusWeight,
+            cusUnit: igd.cusUnit,
+            typeSpan: lastTypeHit
+              ? {
+                  rowspan: 0,
+                  colspan: 0
+                }
+              : {
+                  rowspan: 1,
+                  colspan: 1
+                },
+            nameSpan: lastNameHit
+              ? {
+                  rowspan: 0,
+                  colspan: 0
+                }
+              : {
+                  rowspan: 1,
+                  colspan: 1
+                }
+          });
+        });
+      }
+      return arr;
+    }, []);
+}
diff --git a/stdiet-ui/src/views/custom/recipesBuild/RecipesView/RecipesHeaderCom/index.vue b/stdiet-ui/src/views/custom/recipesBuild/RecipesView/RecipesHeaderCom/index.vue
index 5f5a599cf..b9a91c467 100644
--- a/stdiet-ui/src/views/custom/recipesBuild/RecipesView/RecipesHeaderCom/index.vue
+++ b/stdiet-ui/src/views/custom/recipesBuild/RecipesView/RecipesHeaderCom/index.vue
@@ -229,7 +229,7 @@ export default {
         }
         recipesDom.style.overflow = "visible";
         html2canvans(recipesDom, {
-          scale: 1.5,
+          scale: 2,
           height: recipesDom.scrollHeight,
         }).then((canvas) => {
           const { name } = this.healthyData;
@@ -244,6 +244,7 @@ export default {
           recipesDom.style.overflow = "auto";
 
           this.downloading = false;
+          this.$message.success("食谱导出成功");
         });
       });
     },