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'>
     <bar-horizontal :data-source='data' :title='title'   @click='barClick'  :height='height'/>
     <a-divider dashed />
     <bar-horizontal :data-source='itemData[project]' :title='subTitle'   :height='subHeight'  />
  </div>
</template>
 
<script>
 
import { filterMultiDictText, initDictOptions } from '@comp/dict/JDictSelectUtil'
import BarHorizontal from '@comp/chart/BarHorizontal'
 
/*
  数据样本
  const sourceData = [
  { type: '中国', value: 131744 },
  { type: '印度', value: 104970 },
  { type: '美国', value: 29034 },
  { type: '印尼', value: 23489 },
  { type: '巴西', value: 18203 },
];*/
 
export default {
  name: 'StatisticsBar',
  components: { BarHorizontal },
  props: {
    dataSource: {
      type: Array,
      default: []
    }
 
  },
  data() {
    return {
      title:'项目工时',
      subTitle:'',
      height:0,
      subHeight:0,
      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)
    },
    barClick(event, chart) {
      //
 
      if (!event.data || !event.data.point || !event.data.point.type) return
      let selectPro = event.data.point.type
      if (!selectPro) return
      this.project = selectPro
      //计算生成柱状图高度
      this.subHeight = this.itemData[this.project].length * 40 + 100
 
      //解决一条数据集不显示名字的bug
      if(this.itemData[this.project].length==1)  this.itemData[this.project].push({type:'',value:null})
 
      this.itemData[this.project].sort(function(a, b) {
        return a.value - b.value
      })
      this.subTitle = this.project
    }
  },
  computed: {
    //所有项目工时统计
    data() {
      if (!this.dataSource) return []
      //剔除合计数据
      let data = this.dataSource.filter((i) => i.xm != 'hj')
      let res = data.map(item => {
        return { type: item.xmName, value: item.hj }
      })
      res.sort(function(a, b) {
        return a.value - b.value
      })
      //解决一条数据集不显示名字的bug
      if(res.length==1)   res.push({type:'',value:null})
      //计算柱状图高度
      this.height = res.length * 40 + 100
      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.type = this.getDictText(key),
            col.value = 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>