riku
2024-08-12 65124213af664a68ad88ce7f6dcb133116d7702f
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
import echarts from '../../../components/ec-canvas/echarts';
import dayjs from 'dayjs';
 
function setOption(chart, series, xAxisMonth) {
  const option = {
    title: {
      text: '整改趋势',
      // subtext: '巡查问题整改数统计',
    },
    grid: {
      left: '8%',
      right: '12%',
      bottom: '10%',
    },
    legend: {
      show: true,
      type: 'scroll',
      left: 'right',
    },
    xAxis: {
      // name: '月份',
      nameLocation: 'middle',
      type: 'category',
      // 两边留白
      boundaryGap: true,
      data: xAxisMonth,
      nameTextStyle: {
        fontSize: 10,
      },
      axisLabel: {
        rotate: 45,
      },
    },
    yAxis: [
      {
        type: 'value',
        name: '数量',
        minInterval: 1,
        offset: 5,
        axisLine: {
          symbol: 'arrow',
          lineStyle: {
            type: 'dashed',
          },
        },
        axisLabel: {
          fontSize: 10,
        },
      },
      {
        type: 'value',
        name: '整改率',
        min: 0,
        max: 100,
        offset: 4,
        minInterval: 20,
        axisLine: {
          symbol: 'arrow',
        },
        axisLabel: {
          formatter: '{value} %',
          fontSize: 10,
        },
      },
    ],
    series: series,
  };
  chart.setOption(option);
}
/**
 * 巡查监管问题整改数量统计相关
 */
export const useSummaryChart = Behavior({
  data: {
    ec: {
      lazyLoad: true,
    },
  },
  ready() {
    const component = this.selectComponent('#mychart-dom-bar');
    this.initChart(component);
  },
  methods: {
    initChart(component) {
      component.init((canvas, width, height, dpr) => {
        const chart = echarts.init(canvas, null, {
          width: width,
          height: height,
          devicePixelRatio: dpr, // new
        });
        this.chart = chart;
        this.init();
        return chart;
      });
    },
 
    // 根据当前选择的时间范围,确定x轴月份坐标
    getXAxisMonth() {
      const xAxisMonth = [];
      const { diffMonth, recentTimeValue } = this.data;
      let now = dayjs();
      xAxisMonth.unshift(now.month() + 1 + '月');
      for (let i = 0; i < diffMonth; i++) {
        now = now.subtract(1, 'month');
        xAxisMonth.unshift(now.month() + 1 + '月');
      }
      return xAxisMonth;
    },
 
    refreshChart() {
      const problems = [];
      const changes = [];
      const xAxisMonth = this.getXAxisMonth();
      xAxisMonth.forEach(m => {
        problems.push(0);
        changes.push(0);
      });
      this.data.subtaskSummary.forEach(s => {
        const month = dayjs(s.stPlanTime).month() + 1 + '月';
        const index = xAxisMonth.findIndex(value => {
          return month == value;
        });
        if (index != -1) {
          problems[index] += s.proNum;
          changes[index] += s.changeNum;
        }
      });
      const datas = [problems, changes];
      const series = ['问题数', '整改数', '整改率'].map((name, i) => {
        if (name == '整改率') {
          const list = datas[0].map((v, i2) => {
            return v == 0 ? '' : Math.round((datas[1][i2] / v) * 1000) / 10;
          });
          return {
            name,
            type: 'bar',
            barWidth: '10%',
            barMaxWidth: '6',
            yAxisIndex: 1,
            label: {
              show: true,
              formatter: '{c}%',
              position: 'top',
              rotate: 45,
              // color: '#fac858'
            },
            data: list,
          };
        } else {
          return {
            name,
            type: 'bar',
            // stack: 'total',
            barWidth: '15%',
            barMaxWidth: '10',
            yAxisIndex: 0,
            label: {
              show: false,
              // formatter: params => Math.round(params.value * 1000) / 10 + '%',
            },
            data: datas[i],
          };
        }
      });
      setOption(this.chart, series, xAxisMonth);
    },
  },
});