zhuguifei
2025-04-28 442928123f63ee497d766f9a7a14f0a6ee067e25
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<template>
  <div class='app'>
 
    <div class='item'>
      <h4 v-if='data.length>0' :style="{  marginBottom: '20px' }" style='text-align: center'>  项目工时比例  </h4>
      <div class='chart-box'>
        <Pie style='width: 1000px'  :data-source='data' @click='pieClick' />
      </div>
    </div>
    <div v-if='project' class='item'>
      <a-divider dashed />
      <h4 :style="{  marginBottom: '20px' }" style='text-align: center'> {{ project }}  </h4>
      <div class='chart-box'>
        <Pie  style='width: 1000px' :data-source='itemData[project]' />
      </div>
    </div>
 
  </div>
</template>
 
<script>
 
import Pie from '@comp/chart/Pie'
import { filterMultiDictText, initDictOptions } from '@comp/dict/JDictSelectUtil'
 
/*
数据样本
const sourceData = [
  { item: '事例一', count: 40 },
  { item: '事例二', count: 21 },
  { item: '事例三', count: 17 },
  { item: '事例四', count: 13 },
  { item: '事例五', count: 9 }
];
*/
 
export default {
  name: 'StatisticsPie',
  components: { Pie },
  props: {
    dataSource: {
      type: Array,
      default: []
    }
 
  },
  watch: {
    dataSource: {
      immediate: true,
      handler() {
        if (this.dataSource.length==0) {
 
        }
      },
    },
  },
  data() {
    return {
      userDictOptions: [],
      project: ''
    }
  },
  created() {
    this.initDictConfig()
  },
  mounted() {
    // 项目详情饼图默认第一个数据
    if (this.data) {
      //this.project = this.data[0].item
    }
  },
  methods: {
    initDictConfig() {
      //初始化字典 - 性别
      initDictOptions('sys_user,realname,username').then((res) => {
        if (res.success) {
          this.$set(this.userDictOptions, 'username', res.result)
        }
      })
 
    },
    getDictText(text) {
      return filterMultiDictText(this.userDictOptions['username'], text)
    },
    pieClick(event, chart) {
      //
      if (!event.data || !event.data.point || !event.data.point.item) return
      let selectPro = event.data.point.item
      if (!selectPro) return
      this.project = selectPro
    }
  },
  computed: {
    //所有项目工时统计
    data() {
      if (!this.dataSource) return []
      //剔除合计数据
      let data = this.dataSource.filter((i) => i.xm != 'hj')
      let res = data.map(item => {
        return { item: item.xmName, count: item.hj }
      })
      return res
 
 
    },
    //每个项目 成员工时的统计
    itemData() {
      if (!this.dataSource) return []
      //剔除合计数据
      let data = this.dataSource.filter((i) => i.xm != 'hj')
      let res = {}
      data.forEach(item => {
        let row = []
        for (var key in item) {
          //过滤不需要统计列
          if (key == 'hj' || key == 'xm' || key == 'xmName') continue
          let col = {}
          col.item = this.getDictText(key),
            col.count = item[key]
          row.push(col)
        }
        res[item.xmName] = row
      })
      return res
    }
 
  }
}
</script>
 
<style lang='less' scoped>
.app {
  .item {
    .chart-box {
      width: 100%;
      display: flex;
      justify-content: center;
    }
 
    .title {
      width: 100%;
      text-align: center;
    }
  }
 
 
}
</style>