|
@@ -315,9 +315,10 @@ export const fixedGrouping = {
|
|
|
|
|
|
// 更具计算返回对应的占比
|
|
// 更具计算返回对应的占比
|
|
export const getProportion = (list, fixedKey) => {
|
|
export const getProportion = (list, fixedKey) => {
|
|
|
|
+ const newList = JSON.parse(JSON.stringify(list))
|
|
const listItem = fixedGrouping[fixedKey]
|
|
const listItem = fixedGrouping[fixedKey]
|
|
const proportion = listItem.proportion
|
|
const proportion = listItem.proportion
|
|
- list.forEach(item => {
|
|
|
|
|
|
+ newList.forEach(item => {
|
|
proportion.forEach(proportionItem => {
|
|
proportion.forEach(proportionItem => {
|
|
if(!item[proportionItem.key]) {
|
|
if(!item[proportionItem.key]) {
|
|
item[proportionItem.key] = item[proportionItem.value]
|
|
item[proportionItem.key] = item[proportionItem.value]
|
|
@@ -326,7 +327,7 @@ export const getProportion = (list, fixedKey) => {
|
|
}
|
|
}
|
|
})
|
|
})
|
|
})
|
|
})
|
|
- list.forEach(item => {
|
|
|
|
|
|
+ newList.forEach(item => {
|
|
proportion.forEach(proportionItem => {
|
|
proportion.forEach(proportionItem => {
|
|
if(item[proportionItem.key] != 0) {
|
|
if(item[proportionItem.key] != 0) {
|
|
let num = (item[proportionItem.key] / item.totalWorkTime) * 100
|
|
let num = (item[proportionItem.key] / item.totalWorkTime) * 100
|
|
@@ -334,5 +335,36 @@ export const getProportion = (list, fixedKey) => {
|
|
}
|
|
}
|
|
})
|
|
})
|
|
})
|
|
})
|
|
- return list
|
|
|
|
|
|
+ return newList
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// 汇总计算
|
|
|
|
+export const collectNUm = (list, fixedKey) => {
|
|
|
|
+ const newList = JSON.parse(JSON.stringify(list))
|
|
|
|
+ const listItem = fixedGrouping[fixedKey]
|
|
|
|
+ const proportion = listItem.proportion
|
|
|
|
+ let totalNum = list.reduce((prev, curr) => { // 总计值
|
|
|
|
+ return { totalWorkTime: prev.totalWorkTime + curr.totalWorkTime };
|
|
|
|
+ }, { totalWorkTime: 0 }).totalWorkTime
|
|
|
|
+ let returnedValue = {}
|
|
|
|
+ newList.forEach(item => {
|
|
|
|
+ proportion.forEach(proportionItem => {
|
|
|
|
+ if(!item[proportionItem.key]) {
|
|
|
|
+ item[proportionItem.key] = item[proportionItem.value]
|
|
|
|
+ } else {
|
|
|
|
+ item[proportionItem.key] += item[proportionItem.value]
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ proportion.forEach(proportionItem => {
|
|
|
|
+ returnedValue[proportionItem.key] = newList.reduce((prev, curr) => { // 总计值
|
|
|
|
+ return { [proportionItem.key]: prev[proportionItem.key] + curr[proportionItem.key] };
|
|
|
|
+ }, { [proportionItem.key]: 0 })[proportionItem.key]
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ return {
|
|
|
|
+ ...returnedValue,
|
|
|
|
+ totalNum: totalNum
|
|
|
|
+ }
|
|
}
|
|
}
|