月份数据统计,后台返回数据拆分12个对象,代表12个月份,而且月
2024-02-19 本文已影响0人
而生lhw
let rawData = {
One:[{month:1,count:10},{month:12,count:2}],
Two::[{month:1,count:14},{month:3,count:23}],
Three:[],
Four::[{month:1,count:10}],
};
// 拆分成想要的数据 ysdList、lydList、tzdList、bfdList都会包含12个对象,12个月份,而且对象没有顺序,没有的count赋值为0
// ysdList:[10,0,0,0,0,0,0,0,0,0,0,2]
// lydList:[14,0,23,0,0,0,0,0,0,0,0,0]
// tzdList:[0,0,0,0,0,0,0,0,0,0,0,0]
// bfdList:[10,0,0,0,0,0,0,0,0,0,0,0]
let targetData = {
ysdList: [],
lydList: [],
tzdList: [],
bfdList: [],
};
for (let i = 1; i < 13; i++) {
let ss = [];
if (!rawData.One) {
ss = [];
} else {
ss = rawData.One.filter((item) => {
return item.month == i;
});
}
if (ss.length <= 0) {
targetData.ysdList.push("0");
} else {
targetData.ysdList.push(ss[0].count + "");
}
let aa = [];
if (!rawData.Two) {
aa = [];
} else {
aa = rawData.Two.filter((item) => {
return item.month == i;
});
}
if (aa.length <= 0) {
targetData.lydList.push("0");
} else {
targetData.lydList.push(aa[0].count + "");
}
let bb = [];
if (!rawData.Three) {
bb = [];
} else {
bb = rawData.Three.filter((item) => {
return item.month == i;
});
}
if (bb.length <= 0) {
targetData.tzdList.push("0");
} else {
targetData.tzdList.push(bb[0].count + "");
}
let cc = [];
if (!rawData.Four) {
cc = [];
} else {
cc = rawData.Four.filter((item) => {
return item.month == i;
});
}
if (cc.length <= 0) {
targetData.bfdList.push("0");
} else {
targetData.bfdList.push(cc[0].count + "");
}
}
this.picList = { ...targetData };