修复同一天同一餐别菜名相同合并的情况
This commit is contained in:
parent
4ce5f3f7da
commit
36384820bb
@ -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;
|
||||
|
@ -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;
|
||||
}, []);
|
||||
}
|
@ -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("食谱导出成功");
|
||||
});
|
||||
});
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user