|
@@ -608,6 +608,7 @@ import deepCopy from "@gby/deep-copy";
|
|
|
// 树形参照
|
|
|
import TreeRefers from '@/components/Refers/treeRefer.vue'
|
|
|
import ElPopoverSelectV2 from "@/components/popover-select-v2"
|
|
|
+import log from "../../../monitor/job/log";
|
|
|
|
|
|
export default {
|
|
|
name: "AnnualSaleGoalMerge",
|
|
@@ -1112,43 +1113,43 @@ export default {
|
|
|
mergeAnnualSaleMergeDetails(query).then(response => {
|
|
|
console.log(response);
|
|
|
this.annualSaleGoalMergeDetailsList = response.data.consolidatedDetail
|
|
|
- if (classify !== '销售区域') {
|
|
|
- this.areaDetailList = []
|
|
|
- this.customerDetailList = []
|
|
|
- } else {
|
|
|
- this.areaDetailList = response.data.areaDetail
|
|
|
- this.customerDetailList = response.data.customerDetail
|
|
|
- }
|
|
|
this.computeTotal()
|
|
|
})
|
|
|
},
|
|
|
// 获得区域目标汇总or客户目标汇总
|
|
|
getNewTwoArray() {
|
|
|
- let activeName = this.activeName
|
|
|
- let array = deepCopy(this.annualSaleGoalMergeDetailsList)
|
|
|
- console.log(this.annualSaleGoalMergeDetailsList);
|
|
|
- if (activeName === 'annualSaleGoalMergeDetails') {
|
|
|
- console.log('annualSaleGoalMergeDetails')
|
|
|
- } else if (activeName === 'zoneGoalSum(year)') {
|
|
|
- for (let i = 0; i < array.length; i++) {
|
|
|
- for (let j = 0; j < array.length; j++) {
|
|
|
- if (i !== j && array[i].saleOrg === array[j].saleOrg && array[i].saleZone === array[j].saleZone && array[i].creator === array[j].creator) {
|
|
|
- array[i].totalGoal += array[j].totalGoal
|
|
|
- array.splice(j, 1)
|
|
|
- }
|
|
|
+ let arr = JSON.parse(JSON.stringify(this.annualSaleGoalMergeDetailsList))
|
|
|
+ // 如果子表标签是annualSaleGoalMergeDetails 或者 主表的目标分类是“销售区域”
|
|
|
+ if (this.activeName === 'annualSaleGoalMergeDetails' || this.form.goalCategory !== '销售区域') {
|
|
|
+ this.areaDetailList = null
|
|
|
+ this.customerDetailList = null
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 根据某三个属性进行合并并相加totalGoal的函数
|
|
|
+ const mergeAndSumTotalGoal = (array) => {
|
|
|
+ return Array.from(array.reduce((map, obj) => {
|
|
|
+ let key = null
|
|
|
+ if (this.activeName === 'zoneGoalSum(year)') {
|
|
|
+ key = `${obj.saleOrg}-${obj.saleZone}-${obj.creator}`
|
|
|
+ } else if (this.activeName === 'customerGoalSum(year)') {
|
|
|
+ key = `${obj.saleOrg}-${obj.saleZone}-${obj.custom}`
|
|
|
}
|
|
|
- }
|
|
|
- this.areaDetailList = array
|
|
|
- } else if (activeName === 'customerGoalSum(year)') {
|
|
|
- for (let i = 0; i < array.length; i++) {
|
|
|
- for (let j = 0; j < array.length; j++) {
|
|
|
- if (i !== j && array[i].saleOrg === array[j].saleOrg && array[i].saleZone === array[j].saleZone && array[i].custom === array[j].custom) {
|
|
|
- array[i].totalGoal += array[j].totalGoal
|
|
|
- array.splice(j, 1)
|
|
|
- }
|
|
|
+ console.log(key);
|
|
|
+ if (map.has(key)) {
|
|
|
+ const existingObj = map.get(key)
|
|
|
+ existingObj.totalGoal += obj.totalGoal
|
|
|
+ } else {
|
|
|
+ map.set(key, { ...obj })
|
|
|
}
|
|
|
- }
|
|
|
- this.customerDetailList = array
|
|
|
+ return map
|
|
|
+ }, new Map()).values())
|
|
|
+ }
|
|
|
+ // 调用合并函数
|
|
|
+ const mergedArray = mergeAndSumTotalGoal(arr)
|
|
|
+ if (this.activeName === 'zoneGoalSum(year)') {
|
|
|
+ this.areaDetailList = mergedArray
|
|
|
+ } else if (this.activeName === 'customerGoalSum(year)') {
|
|
|
+ this.customerDetailList = mergedArray
|
|
|
}
|
|
|
}
|
|
|
}
|