Selaa lähdekoodia

调整工时成本统计人员的总计显示

Lijy 1 vuosi sitten
vanhempi
commit
888fcfbce5
1 muutettua tiedostoa jossa 36 lisäystä ja 5 poistoa
  1. 36 5
      fhKeeper/formulahousekeeper/timesheet/src/views/project/cost.vue

+ 36 - 5
fhKeeper/formulahousekeeper/timesheet/src/views/project/cost.vue

@@ -557,7 +557,7 @@
                             // console.log('人员返回', this.allListData);
                             this.gtff()
                         }
-                    } else {
+                    } else { 
                         this.$message({
                         message: res.msg + '里面',
                         type: "error"
@@ -606,7 +606,26 @@
                     for(var i in array) {
                         yList.push(array[i]);
                         var dataList = [];
-                        // console.log('for 2 1');
+                        let nameObj = {}
+                        list.forEach(item => {
+                            let moneyTol = 0;
+                            let timeTol = 0;
+                            item.project.forEach((project, index) => {
+                                moneyTol += +project.money;
+                                timeTol += +project.time;
+                            });
+                            // 假设每个 item.project 都至少有一个元素
+                            if (item.project.length > 0) {
+                                const lastProject = item.project[item.project.length - 1];
+                                nameObj[item.name] = {moneyTol: moneyTol, timeTol: timeTol}
+                                lastProject.moneyTol = moneyTol;
+                                lastProject.timeTol = timeTol;
+                            }
+                        });
+
+
+                        console.log('==================>', list, nameObj);
+
                         for(var j in list) {
                             var project = list[j].project , num = 0;
                             if(project.length != 0) {
@@ -623,6 +642,10 @@
                                             item.cost = project[k].time
                                             // totalHours += parseFloat(project[k].time);
                                         }
+                                        if(project[k].moneyTol) {
+                                            item.moneyTol = project[k].moneyTol
+                                            item.timeTol = project[k].timeTol
+                                        }
                                         dataList.push(item)
                                         
                                     } else {
@@ -644,20 +667,28 @@
                                 })
                             }
                         }
+                        // console.log(array[i], dataList, array, '《==============看看数据')
+                        let cerName = array[array.length - 1] // 最后一个项目
+                        let yAxisValue = this.yAxisValue
                         series.push({
                             name: array[i],
                             type: 'bar',
-                            stack:'1',
+                            stack: '1',
                             barMaxWidth: 30,
                             data: dataList,
                             label: {
                                 normal: {
                                     show: true,
                                     position: 'top',
-                                    formatter: `{c} ${this.yAxisValue==0 ? '元' : '小时'}`,
+                                    formatter: function(params) {
+                                        const { seriesName, data, name} = params
+                                        const unit = yAxisValue == 0 ? '元' : '小时';
+                                        const totalValue = yAxisValue == 0 ? nameObj[name].moneyTol : nameObj[name].timeTol;
+                                        return seriesName === cerName ? `${totalValue ? totalValue.toFixed(0) : 0} ${unit}` : '';
+                                    }
                                 }
                             }
-                        })
+                        });
                     }
                     }