Bläddra i källkod

提交定制报表的代码

Lijy 11 månader sedan
förälder
incheckning
b383cc8c7e

+ 35 - 3
fhKeeper/formulahousekeeper/timesheet/src/views/corpreport/echartsData.js

@@ -315,9 +315,10 @@ export const fixedGrouping = {
 
 // 更具计算返回对应的占比
 export const getProportion = (list, fixedKey) => {
+  const newList = JSON.parse(JSON.stringify(list))
   const listItem = fixedGrouping[fixedKey]
   const proportion = listItem.proportion
-  list.forEach(item => {
+  newList.forEach(item => {
     proportion.forEach(proportionItem => {
       if(!item[proportionItem.key]) {
         item[proportionItem.key] = item[proportionItem.value]
@@ -326,7 +327,7 @@ export const getProportion = (list, fixedKey) => {
       }
     })
   })
-  list.forEach(item => {
+  newList.forEach(item => {
     proportion.forEach(proportionItem => {
       if(item[proportionItem.key] != 0) {
         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
+  }
 }

+ 10 - 4
fhKeeper/formulahousekeeper/timesheet/src/views/corpreport/packetConsumption/tables.vue

@@ -92,7 +92,7 @@
 </template>
 
 <script>
-import { debounce, fixedGrouping, getPieEchartOption, getProportion } from "../echartsData.js";
+import { debounce, fixedGrouping, getPieEchartOption, getProportion, collectNUm } from "../echartsData.js";
 import EchartsEchar from "@/components/echartsEchar.vue"
 export default {
   props: {
@@ -123,7 +123,8 @@ export default {
       typesDataObj: fixedGrouping,
       echartsTableData: [],
       echartsKey: 1,
-      echartTableType: '图表'
+      echartTableType: '图表',
+      returnedValueItem: {}
     };
   },
   computed: {},
@@ -217,6 +218,8 @@ export default {
           fledStrList: [...new Set(strList)]
         }
       })
+      // console.log(collectNUm(dataList, this.types), '<===== 返回的数据 ============>')
+      this.returnedValueItem = collectNUm(dataList, this.types)
       this.tableList = getProportion(dataList, this.types)
       this.typesDataObj[this.types].tableKey = this.randomInt()
       console.log(this.tableList, '<====== 返回最终的数据')
@@ -320,14 +323,17 @@ export default {
       const { columns, data } = param;
       const sums = [];
       const strList = (data[0] && data[0].fledStrList) || []
+      const totalNum = this.returnedValueItem.totalNum
       columns.forEach((column, index) => {
         if (index === 0) {
           sums[index] = '总计';
           return;
         }
         if (strList.includes(column.property)) {
-          sums[index] = ' ';
-          return;
+          let val = this.returnedValueItem[column.property]
+          let num = (val / totalNum) * 100
+          sums[index] = Number(num.toFixed(2)) + '%';
+          return
         }
         const values = data.map(item => Number(item[column.property]));
         if (!values.every(value => isNaN(value))) {

+ 1 - 0
fhKeeper/formulahousekeeper/timesheet/src/views/team/index.vue

@@ -236,6 +236,7 @@
                 <el-table-column :label="$t('jiao-se')" width="100">
                     <template slot-scope="scope">{{scope.row.roleName}}</template>
                 </el-table-column>
+                <el-table-column label="分组" prop="groupName" width="150" v-if="permissions.userGroupManage"></el-table-column>
                 <el-table-column prop="monthCost" :label="$t('monthcost')" align="right" v-if="permissions.structurePersonnel" width="140">
                     <template slot-scope="scope">{{user.timeType.isSecretSalary==0?(scope.row.monthCost==null?0:scope.row.monthCost.toFixed(2)):'*'}} {{ $t('yuan') }}</template>
                 </el-table-column>