he wei
2023-07-20 5748fde24928bbda455fb3b2f764b0d18efe683c
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
<template>
  <div class="home-contain">
    <!-- 左 -->
    <div class="main-item">
      <!-- 上 -->
      <div class="row-1">
        <card class="card row-1" title="基础资源信息" content-class="base-card">
          <total-data
            class="row-item"
            :type="0"
            :value="base.stationNum | toLarge"
          ></total-data>
          <total-data
            class="row-item"
            :type="1"
            :value="base.powerNum | toLarge"
          ></total-data>
          <total-data
            class="row-item"
            :type="2"
            :value="base.battGroupCount | toLarge"
          ></total-data>
          <total-data
            class="row-item"
            :type="3"
            :value="base.hrDisNum | toLarge"
            @click="getHrYeardisBatt"
          ></total-data>
        </card>
      </div>
      <!-- 中 -->
      <div class="sub-item row-2">
        <card class="card" title="站点信息" content-class="station">
          <template #tools>
            <el-radio-group
              size="mini"
              @input="stationLevelChange"
              :disabled="!chartData.station.length"
              v-model="stationLevel"
            >
              <el-radio-button :label="0">按电压等级</el-radio-button>
              <el-radio-button :label="1">按类型</el-radio-button>
            </el-radio-group>
            <el-tag
              class="cur-point mrl8"
              effect="dark"
              size="mini"
              type="success"
              @click="goToStationInfo"
              >更多>></el-tag
            >
          </template>
          <!-- <bar-chart ref="station"></bar-chart> -->
          <bar3d3 ref="station"></bar3d3>
        </card>
        <card class="card" title="电池信息">
          <template #tools>
            <el-radio-group
              size="mini"
              :disabled="!chartData.batt.length"
              @input="battLevelChange"
              v-model="battLevel"
            >
              <el-radio-button :label="0">按品牌</el-radio-button>
              <el-radio-button :label="1">按电压类型</el-radio-button>
            </el-radio-group>
            <el-tag
              class="cur-point mrl8"
              effect="dark"
              size="mini"
              type="success"
              @click="goToBattInfo"
              >更多>></el-tag
            >
          </template>
          <!-- <pie-chart ref="battInfo"></pie-chart> -->
          <pie3d ref="battInfo"></pie3d>
        </card>
      </div>
      <!-- 下 -->
      <div class="sub-item row-3">
        <card class="card" title="电源信息">
          <template #tools>
            <el-tag
              class="cur-point mrl8"
              effect="dark"
              size="mini"
              type="success"
              @click="goToPowerInfo"
              >更多>></el-tag
            >
          </template>
          <!-- <power-chart ref="powerChart"></power-chart> -->
          <pie3d ref="powerChart" :theme-idx="1"></pie3d>
        </card>
        <card class="card" title="测试信息" content-class="test">
          <template #tools>
            <el-radio-group
              size="mini"
              :disabled="!chartData.test.length"
              @input="testLevelChange"
              v-model="testLevel"
            >
              <el-radio-button :label="0">本月</el-radio-button>
              <el-radio-button :label="1">本季度</el-radio-button>
              <el-radio-button :label="2">本年</el-radio-button>
            </el-radio-group>
          </template>
          <bar3d ref="bar3d"></bar3d>
        </card>
      </div>
    </div>
    <!-- 右 -->
    <div class="main-item">
      <!-- 上 -->
      <div class="row-1">
        <card class="card" title="蓄电池优劣分析" content-class="base-card">
          <batt-card
            class="row-item"
            :type="0"
            :value="batt.groupNum | toLarge"
          ></batt-card>
          <batt-card
            class="row-item"
            :type="1"
            :value="batt.goodSum | toLarge"
          ></batt-card>
          <batt-card
            class="row-item"
            :type="2"
            :value="batt.alarmNum | toLarge"
          ></batt-card>
          <batt-card
            class="row-item"
            :type="3"
            :value="batt.changeNum | toLarge"
          ></batt-card>
        </card>
      </div>
      <!-- 中 -->
      <div class="row-2">
        <card class="card" title="同一投运时间不同品牌电池性能分析">
          <template #tools>
            <el-tag
              class="cur-point mrl8"
              effect="dark"
              size="mini"
              type="success"
              @click="goToTaskplan"
              >更多>></el-tag
            >
          </template>
          <div class="card-contain">
            <div class="batt-chart">
              <div class="pos-full">
                <batt-chart ref="battChart"></batt-chart>
              </div>
            </div>
            <div class="panel0">
              <panel title="请选择投运年限">
                <div class="content">
                  <el-select
                    v-model="year0"
                    @change="year0Change"
                    :disabled="!chartData.analysis.length"
                    size="mini"
                  >
                    <el-option
                      v-for="(item, idx) in years"
                      :key="'year0_' + idx"
                      :label="item.label"
                      :value="item.value"
                    >
                    </el-option>
                  </el-select>
                  <div class="wrap">
                    <!-- 损坏数量最多品牌 -->
                    <div class="batt-data break">
                      <div class="label">损坏数量<br />最多品牌</div>
                      <div class="value" v-if="listChange.length <= 1">
                        {{ changeProd }}
                      </div>
                      <el-tooltip
                        class="item"
                        v-else
                        effect="dark"
                        content="changeProd1"
                        placement="top-end"
                      >
                        <div class="value">{{ changeProd }}</div>
                      </el-tooltip>
                    </div>
                    <!-- 劣化数量最多品牌 -->
                    <div class="batt-data">
                      <div class="label">劣化数量<br />最多品牌</div>
                      <div class="value" v-if="listAlarm.length <= 1">
                        {{ alarmProd }}
                      </div>
                      <el-tooltip
                        class="item"
                        effect="dark"
                        v-else
                        content="alarmProd1"
                        placement="top-end"
                      >
                        <div class="value">{{ alarmProd }}</div>
                      </el-tooltip>
                    </div>
                  </div>
                </div>
              </panel>
            </div>
          </div>
        </card>
      </div>
      <!-- 下 -->
      <div class="row-3">
        <card class="card" title="同一投运时间相同品牌电池性能分析">
          <template #tools>
            <el-tag
              class="cur-point mrl8"
              effect="dark"
              size="mini"
              type="success"
              @click="goToTaskplan"
              >更多>></el-tag
            >
          </template>
          <div class="card-contain">
            <div class="chart">
              <div class="pos-full inner">
                <!-- <bar-chart ref="analysis1" :bar-width="80"></bar-chart> -->
                <bar3d2 ref="analysis1"></bar3d2>
              </div>
            </div>
            <!-- 中 -->
            <div class="selector">
              <panel class="big" title="请选择投运年限">
                <div class="content">
                  <el-select
                    v-model="year1"
                    @change="updateAnalysis1"
                    :disabled="!chartData.analysis1.length"
                    size="mini"
                  >
                    <el-option
                      v-for="(item, idx) in years"
                      :key="'year1_' + idx"
                      :label="item.label"
                      :value="item.value"
                    >
                    </el-option>
                  </el-select>
                </div>
              </panel>
              <panel class="small" title="请选择电池品牌">
                <div class="content">
                  <el-select
                    v-model="battProd"
                    @change="updateAnalysis1"
                    :disabled="!prodList.length"
                    size="mini"
                  >
                    <el-option
                      v-for="(item, idx) in prodList"
                      :key="'prod_' + idx"
                      :label="
                        item.name + '(' + item.alarm + '/' + item.change + ')'
                      "
                      :value="item.name"
                    >
                    </el-option>
                  </el-select>
                </div>
              </panel>
            </div>
            <!-- 右 -->
            <div class="card-info">
              <div class="item">
                <div class="icon break"></div>
                <div class="info">损坏数量: {{ changeCount }}</div>
              </div>
              <div class="item">
                <div class="icon bad"></div>
                <div class="info">劣化数量: {{ alarmCount }}</div>
              </div>
            </div>
          </div>
        </card>
      </div>
    </div>
    <el-dialog
      title="本年度已核容放电电池组列表"
      width="1300px"
      :visible.sync="listVisible"
      :close-on-click-modal="false"
      top="0"
      class="dialog-center"
      :modal-append-to-body="false"
    >
      <el-table height="400" :data="tableData" style="width: 100%">
        <el-table-column type="index" width="50"> </el-table-column>
        <el-table-column
          label="站名"
          prop="stationName"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          label="测试时间"
          prop="testStarttime"
          width="166"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          label="测试时长"
          prop="testTlong"
          width="100"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          label="测试容量"
          prop="testCap"
          width="150"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          label="预估实际容量"
          prop="rCap"
          width="120"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          label="放电停止原因"
          prop="testStoptypeReason"
          width="200"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column label="操作" width="80" align="center">
          <template slot-scope="scope">
            <el-button type="success" size="mini" @click="details(scope.row)"
              >详情</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>
  </div>
</template>
 
<script>
import Card from "@/components/bigScreenPage/big_screen_card";
import totalData from "./components/total-data";
import battCard from "./components/batt-card";
import barChart from "./components/bar-chart";
import pieChart from "./components/pie-chart";
import pie3d from "./components/pie3d";
import panel from "./components/panel";
import bar3d from "./components/bar-3d";
import bar3d3 from "./components/bar-3d3";
import bar3d2 from "./components/bar-3d2";
import powerChart from "./components/power-chart";
import battChart from "./components/batt-chart";
 
import noRepeat from "@/assets/js/tools/noRepeat";
 
import { getHrYeardisBatt } from "./js/api";
import formatSeconds from "@/assets/js/tools/formatSeconds";
 
import createWs from "@/assets/js/websocket";
const WSMixin = createWs("homeAdmin");
 
export default {
  name: "",
  mixins: [WSMixin],
  data() {
    return {
      // 维护 ‘其他’ 所对应的列表
      others: {
        battProd: [],
        battVol: [],
        pwrProd: [],
        // 因为投运年限有四个级别 所以要存四份
        battProdAnalysis: [[], [], [], []],
      },
      toObj: {},
      listVisible: false,
      tableData: [],
      updateFlag: false,
      years: [
        {
          value: 0,
          label: "3年以内",
        },
        {
          value: 1,
          label: "3-5年",
        },
        {
          value: 2,
          label: "5-7年",
        },
        {
          value: 3,
          label: "7年以上",
        },
      ],
      stationLevel: 0,
      battLevel: 0,
      testLevel: 0,
      changeCount: "--",
      alarmCount: "--",
      year0: 0,
      year1: 0,
      base: {
        stationNum: 0,
        powerNum: 0,
        battGroupCount: 0,
        hrDisNum: 0,
      },
      batt: {
        groupNum: 0,
        goodSum: 0,
        alarmNum: 0,
        changeNum: 0,
      },
      battProd: "",
      prodList: [],
      chartData: {
        station: [],
        batt: [],
        test: [],
        analysis: [],
        analysis1: [],
      },
      listChange: [],
      listAlarm: [],
    };
  },
  components: {
    Card,
    totalData,
    battCard,
    barChart,
    panel,
    pieChart,
    pie3d,
    bar3d,
    bar3d3,
    bar3d2,
    powerChart,
    battChart,
  },
  computed: {
    changeProd() {
      if (1 == this.listChange.length) {
        return this.listChange[0];
      } else if (this.listChange.length > 1) {
        return this.listChange[0] + " 等";
      } else {
        return "无";
      }
    },
    alarmProd() {
      if (1 == this.listAlarm.length) {
        return this.listAlarm[0];
      } else if (this.listAlarm.length > 1) {
        return this.listAlarm[0] + " 等";
      } else {
        return "无";
      }
    },
    changeProd1() {
      if (this.listChange.length > 1) {
        return this.listChange.join("、");
      } else {
        return "";
      }
    },
    alarmProd1() {
      if (this.listAlarm.length > 1) {
        return this.listAlarm.join("、");
      } else {
        return "";
      }
    },
  },
  filters: {
    toLarge(input) {
      if (undefined == input) {
        return "";
      } else {
        if (input > 999) {
          return "999+";
        } else {
          return input;
        }
      }
    },
  },
  methods: {
    goToStationInfo() {
      this.$router.push("/dataMager/totalStation");
    },
    goToBattInfo() {
      this.$router.push("/dataMager/produceTotal");
    },
    goToPowerInfo() {
      this.$router.push("/dataMager/powerMager");
    },
    goToTaskplan() {
      this.$router.push("/reportStatistics/taskplan");
    },
    onWSOpen() {
      this.$nextTick(() => {
        this.SOCKET.send("");
      });
    },
    onWSMessage(res) {
      res = JSON.parse(res.data);
      // console.log(res, "=====111data");
      let { resGroupAnalysis, resBattInfoAnalysis } = res.data;
      this.base = resBattInfoAnalysis.data2;
      this.batt = resGroupAnalysis.data2;
      this.updateCharts(res.data);
    },
    updateCharts(data) {
      let {
        resStationAnalysis: {
          data2: { node, stationType },
        },
        resProductQuaAnalysis: {
          data: { threeYear, fiveYear, sevenYear, otherYear },
        },
        resPwrdevInfAnalysis: { data2: power },
        battGroupInfo: {
          data2: { monVol, producer },
        },
        resTestdataInfAnalysis: {
          data2: { month, year, quarter },
        },
      } = data;
      let station = [];
      [stationType, node].forEach((item, idx) => {
        let res = {
          xLabel: [],
          sData: [],
          colorList: [
            ["#d3c209", "#e29300"],
            ["#02ddff", "#0082ff"],
          ],
        };
        Object.keys(item).forEach((v) => {
          if (0 == idx) {
            if (0 != v) {
              res.xLabel.push(v);
              res.sData.push(item[v]);
            }
          } else {
            res.xLabel.push(["非节点站", "节点站"][v]);
            res.sData.push(item[v]);
          }
        });
        station.push(res);
      });
      this.chartData.station = station;
      // 站点
      this.$refs.station.setData(station[this.stationLevel]);
 
      let batt = [];
      [producer, monVol].forEach((item, idx) => {
        batt.push(this.formatBattData(item, idx));
      });
      this.prodList = Object.keys(producer).map((v) => ({
        name: v,
        alarm: 0,
        change: 0,
      }));
      this.chartData.batt = batt;
      // 电池
      this.$refs.battInfo.setData(batt[this.battLevel]);
 
      let powerChart = (() => {
        let res = { sData: [] };
 
        let arr = Object.keys(power)
          .map((v) => ({ name: v, value: power[v] }))
          .sort((a, b) => {
            return b.value - a.value;
          });
        this.others.pwrProd = [];
        if (arr.length <= 5) {
          res.sData = arr;
        } else {
          let name = "其他";
          let value = 0;
          arr.splice(4).forEach((v) => {
            value += v.value * 1;
            this.others.pwrProd.push(v.name);
          });
          res.sData = arr;
          res.sData.push({ name, value });
        }
        return res;
      })();
      // 电源
      this.$refs.powerChart.setData(powerChart);
 
      let test = [];
      [month, quarter, year].forEach((item) => {
        // test.push({
        //   xLabel: ["核容放电", "核容充电", "监测放电", "监测充电"],
        //   sData: [item.hrdisNum, item.hrchNum, item.jcdisNum, item.jcchNum],
        // });
        test.push({
          xLabel: ["核容放电", "核容充电"],
          sData: [item.hrdisNum, item.hrchNum],
        });
      });
      this.chartData.test = test;
      // 测试
      this.$refs.bar3d.setData(test[this.testLevel]);
 
      let analysis = [],
        analysis1 = [];
      // let prodList = [];
      [threeYear, fiveYear, sevenYear, otherYear].forEach((item, idx) => {
        analysis.push(this.formatTestData(item, idx));
        analysis1.push(Object.keys(item).map((v) => ({ name: v, ...item[v] })));
        // prodList.push(...Object.keys(item));
      });
 
      this.chartData.analysis = analysis;
      this.chartData.analysis1 = analysis1;
      // this.prodList = noRepeat(prodList);
      if (!this.battProd) {
        this.battProd = this.prodList[0].name || "";
        this.updateAnalysis1();
      }
      // this.battProd = this.prodList[0] || '';
      // 性能1
      this.$refs.battChart.setData(analysis[this.year0]);
      this.year0Change(this.year0);
 
      let { getTestData, year1, battProd } = this;
      // 性能2
      this.$refs.analysis1.setData(getTestData(year1, battProd));
      if (!this.updateFlag) {
        this.updateFlag = true;
        this.resizeChart();
      }
    },
    resizeChart() {
      this.$refs.station?.resize();
      this.$refs.battInfo?.resize();
      this.$refs.powerChart?.resize();
      this.$refs.bar3d?.resize();
      this.$refs.battChart?.resize();
      this.$refs.analysis1?.resize();
    },
    formatTestData(data, idx) {
      let sData = [[], []];
      let xLabel = [];
      let battProdAnalysis = [];
      let arr = Object.keys(data)
        .map((v) => ({ name: v, ...data[v] }))
        .sort((a, b) => {
          if (a.change != b.change) {
            return b.change - a.change;
          } else {
            return b.alarm - a.alarm;
          }
        });
      if (arr.length <= 5) {
        arr.forEach((v) => {
          sData[0].push(v.alarm);
          sData[1].push(v.change);
          xLabel.push(v.name);
        });
      } else {
        let label = "其他";
        let alarm = 0,
          change = 0;
        arr.splice(4).forEach((v) => {
          alarm += v.alarm * 1;
          change += v.change * 1;
          battProdAnalysis.push(v.name);
        });
        arr.forEach((v) => {
          sData[0].push(v.alarm);
          sData[1].push(v.change);
          xLabel.push(v.name);
        });
        xLabel.push(label);
        sData[0].push(alarm);
        sData[1].push(change);
      }
 
      this.others.battProdAnalysis[idx] = battProdAnalysis;
      return { xLabel, sData };
    },
    formatBattData(data, idx) {
      let res = { sData: [] };
      if (idx) {
        this.others.battVol = [];
      } else {
        this.others.battProd = [];
      }
      let arr = Object.keys(data)
        .map((v) => ({ name: idx ? v * 1 + "伏" : v, value: data[v] }))
        .sort((a, b) => {
          return b.value - a.value;
        });
      if (arr.length <= 5) {
        res.sData = arr;
      } else {
        let name = "其他";
        let value = 0;
        arr.splice(4).forEach((v) => {
          value += v.value * 1;
          if (idx) {
            this.others.battVol.push(v.name.replace('伏', '') * 1);
          } else {
            this.others.battProd.push(v.name);
          }
        });
        res.sData = arr;
        res.sData.push({ name, value });
      }
      return res;
    },
    getTestData(year, prod) {
      let data = this.chartData.analysis1;
      let arr = data[year];
      let Ores = arr.filter((v) => v.name == prod)[0];
      this.prodList.forEach((v) => {
        let flag = arr.filter((val) => val.name == v.name)[0];
        if (flag) {
          v.alarm = flag.alarm;
          v.change = flag.change;
        } else {
          v.alarm = 0;
          v.change = 0;
        }
      });
      if (!Ores) {
        return {
          xLabel: ["劣化", "损坏"],
          sData: [0, 0],
        };
      }
      return {
        xLabel: ["劣化", "损坏"],
        sData: [Ores.alarm, Ores.change],
        colorList: [
          ["#f8f38d", "#23b5f5"],
          ["#51eab2", "#23b5f5"],
        ],
      };
    },
    // 获取最多损坏 最多劣化
    getMax(arr) {
      let OChange = {};
      let OAlarm = {};
      arr.forEach((v) => {
        // 劣化数量 v.alarm
        OAlarm[v.alarm] = OAlarm[v.alarm] || [];
        OAlarm[v.alarm].push(v.name);
        OChange[v.change] = OChange[v.change] || [];
        OChange[v.change].push(v.name);
      });
      // console.log(OChange, OAlarm);
      // 劣化最多的品牌
      let listA = [];
      let listC = [];
      // 劣化最多的数量
      let NumA = Object.keys(OAlarm).sort((a, b) => b - a)[0];
      let NumC = Object.keys(OChange).sort((a, b) => b - a)[0];
      if (NumA > 0) {
        listA = OAlarm[NumA];
      }
      if (NumC > 0) {
        listC = OChange[NumC];
      }
      return { listA, listC };
    },
    stationLevelChange(value) {
      // console.log('station change', value);
      this.$refs.station.setData(this.chartData.station[value]);
    },
    battLevelChange(value) {
      this.$refs.battInfo.clear();
      this.$refs.battInfo.setData(this.chartData.batt[value]);
    },
    testLevelChange(value) {
      this.$refs.bar3d.setData(this.chartData.test[value]);
    },
    year0Change(value) {
      // console.log(value, 'year0');
      this.$refs.battChart.setData(this.chartData.analysis[value]);
      // 更新统计
      let { listA, listC } = this.getMax(this.chartData.analysis1[value]);
      this.listChange = listC;
      this.listAlarm = listA;
    },
    updateAnalysis1() {
      let { getTestData, year1, battProd } = this;
      let data = getTestData(year1, battProd);
      // 性能2
      this.$refs.analysis1.setData(data);
      // 更新统计
      let {
        sData: [alarmCount, changeCount],
      } = data;
      this.changeCount = changeCount;
      this.alarmCount = alarmCount;
    },
    // 年度核容电池组
    getHrYeardisBatt() {
      if (this.base.hrDisNum == 0) {
        this.$message.success("没有相关电池组");
        return false;
      }
      this.tableData = [];
      let loading = this.$layer.loading();
      getHrYeardisBatt()
        .then((res) => {
          let { code, data, data2 } = res.data;
          if (code && data) {
            this.$layer.close(loading);
            this.listVisible = true;
            this.tableData = data2.map((v) => {
              v.isHis = true;
              v.testTlong = formatSeconds(v.testTimelong);
              v.rCap = v.realCap.toHold(1);
              v.stationName = v.stationName + " " + v.battGroupName;
              return v;
            });
          } else {
            this.$layer.close(loading);
            this.$message.error("查询失败");
          }
        })
        .catch((err) => {
          this.$message.error("异常");
          console.log(err);
        });
    },
    details(obj) {
      // console.log(obj);
      let search =
        "?province=" +
        obj.stationName1 +
        "&city=" +
        obj.stationName2 +
        "&county=" +
        obj.stationName5 +
        "&home=" +
        obj.stationName3 +
        "&batt=" +
        (obj.battGroupId ? obj.battGroupId : obj.powerDeviceId);
      // list组件重载
      // "&listReload=1";
      let url = "";
      if (obj.isHis) {
        url = "/dataTest/history" + search;
      } else {
        url = "/dataTest/movingRingSystem/" + search + "&listReload=1";
      }
      this.$router.push(url);
      this.listVisible = false;
      // if (obj.powerDeviceId) {
      //   this.$router.push("/dataTest/movingRingSystem/ele-info/" + obj.powerDeviceId);
      // } else {
      //   this.$router.push("/dataTest/movingRingSystem/" + search);
      // }
    },
    initChartEvent() {
      // 站点
      this.$refs.station.getChart().on("click", (params) => {
        // 0 : 按电压等级   1: 按类型
        let stationLevel = this.stationLevel;
        let query = [
          {
            stationType: params.name,
          },
          {
            nodeStation: params.name == "节点站" ? "1" : "0",
          },
        ][stationLevel];
        // 跳转到对应的页面
        this.$router.push({
          path: "/dataMager/totalStation",
          query,
        });
      });
 
      // 电池信息 饼图
      this.$refs.battInfo.getChart().on("click", (params) => {
        let battLevel = this.battLevel;
        let query = {};
        if ("其他" == params.seriesName) {
          query = [
            {
              produce: JSON.stringify(this.others.battProd),
            },
            {
              monVolType: JSON.stringify(this.others.battVol),
            },
          ][battLevel];
        } else {
          // 0: 按品牌    1:按电压
          query = [
            {
              produce: JSON.stringify([params.seriesName]),
            },
            {
              monVolType: JSON.stringify([params.seriesName.replace("伏", "")]),
            },
          ][battLevel];
        }
        // 跳转到对应的页面
        this.$router.push({
          path: "/dataMager/produceTotal",
          query,
        });
      });
 
      this.$refs.powerChart.getChart().on("click", (params) => {
        let producer = [];
        if ("其他" == params.seriesName) {
          producer = this.others.pwrProd;
        } else {
          producer = [params.seriesName];
        }
        // 跳转到对应的页面
        this.$router.push({
          path: "/dataMager/powerMager",
          query: {
            producer: JSON.stringify(producer),
          },
        });
      });
 
      this.$refs.bar3d.getChart().on("click", (params) => {
        let thistime = new Date();
        let yy = thistime.getFullYear();
        let MM = thistime.getMonth() + 1;
        let jdM = Math.floor((MM - 0.1) / 3) * 3 + 1;
        // 0: 月   1: 季度    2:年
        let startDrsj = [
          yy + "-" + MM + "-01",
          yy + "-" + jdM + "-01",
          yy + "-01-01",
        ][this.testLevel];
        let testType = params.name == "核容放电" ? "3" : "2";
        this.$router.push({
          path: "/dataTest/historyInfoMager",
          query: {
            testType,
            startDrsj,
            testStarttype: "3",
          },
        });
      });
 
      // 右中
      this.$refs.battChart.getChart().on("click", (params) => {
        // console.log(params.seriesName, params.name);
        // 劣化 1   损坏 0
        let quality = params.seriesName == "损坏" ? "0" : "1";
        let battProduct =
          params.name == "其他"
            ? this.others.battProdAnalysis[this.year0]
            : [params.name];
        this.$router.push({
          path: "/reportStatistics/taskplan",
          query: {
            quality,
            dateRange: this.year0,
            battProduct: JSON.stringify(battProduct),
          },
        });
      });
      // 右下
      this.$refs.analysis1.getChart().on("click", (params) => {
        // 劣化 1   损坏 0
        let quality = params.name == "损坏" ? "0" : "1";
        let battProduct = [this.battProd];
        this.$router.push({
          path: "/reportStatistics/taskplan",
          query: {
            quality,
            dateRange: this.year1,
            battProduct: JSON.stringify(battProduct),
          },
        });
      });
    },
  },
 
  mounted() {
    this.initChartEvent();
  },
};
</script>
 
<style scoped lang="less">
.home-contain {
  height: 100%;
  display: flex;
  padding: 0 8px;
}
 
.card {
  flex: 1;
}
 
.row-1 {
  height: 270px;
}
 
/deep/ .base-card {
  display: flex;
  flex-direction: row;
  justify-content: space-around;
  /* justify-content: space-between; */
  padding: 0 28px;
}
 
.row-2,
.row-3 {
  flex: 1.2;
}
 
.main-item {
  flex: 1;
  display: flex;
  flex-direction: column;
}
 
.sub-item {
  display: flex;
}
 
.pos-full {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
}
 
.card-contain {
  height: 100%;
  padding: 8px;
  box-sizing: border-box;
  display: flex;
 
  .batt-chart,
  .chart {
    flex: 1;
    position: relative;
 
    .inner {
      padding: 0 30px 4px;
    }
  }
 
  .panel0 {
    height: 100%;
    margin-left: 2em;
 
    .content {
      height: 100%;
      padding: 10px;
      box-sizing: border-box;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
    }
 
    .batt-data {
      font-size: 14px;
      font-weight: bold;
      color: #00fefe;
      background: #01354c;
      border: 1px #016273 solid;
      border-radius: 6px;
      display: flex;
      margin-top: 4px;
      height: 40px;
      line-height: 1;
 
      &.break {
        color: #f2a23b;
      }
 
      .value,
      .label {
        flex: 1;
        display: flex;
        justify-content: center;
        align-items: center;
      }
 
      .value {
        border-left: 1px #016273 solid;
      }
    }
  }
 
  .selector {
    height: 100%;
    display: flex;
    flex-direction: column;
    margin-left: 1em;
 
    .big {
      flex: 1.2;
    }
 
    .small {
      flex: 1;
    }
 
    .content {
      padding: 6px;
    }
  }
}
 
.sub-item .card {
  flex: 1;
 
  &:not(:first-child) {
    margin-left: 10px;
  }
}
 
.main-item ~ .main-item {
  margin-left: 10px;
}
 
/deep/ .test,
/deep/ .station {
  padding: 0 40px 8px;
}
 
/deep/ .el-radio-button--mini .el-radio-button__inner {
  padding: 0.28rem 0.7rem;
  font-size: 0.6rem;
  border-radius: 0;
  border: 0 none;
  background: #00bbc3;
  color: #022c44;
}
 
/deep/ :not(:first-child) > .el-radio-button__inner {
  border-left: 1px solid #0096a3;
}
 
/deep/ .el-radio-button__orig-radio:checked + .el-radio-button__inner {
  box-shadow: none;
}
 
/deep/ .el-radio-button__orig-radio:checked + .el-radio-button__inner {
  background-color: #2982f6;
  color: #fff;
}
 
.card-info {
  width: 152px;
  padding: 4px 0;
  border: 2px #00fefe solid;
  margin-left: 0.4em;
  display: flex;
  flex-direction: column;
  justify-content: space-around;
 
  .item {
    // flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
 
    .icon {
      width: 70px;
      height: 70px;
 
      &.bad {
        background: url("./images/batt_bad.png") center center / contain
          no-repeat;
      }
 
      &.break {
        background: url("./images/batt_break.png") center center / contain
          no-repeat;
      }
    }
 
    .info {
      font-size: 16px;
      color: #ffff00;
      font-weight: bold;
    }
  }
}
.cur-point {
  cursor: pointer;
}
.mrl8 {
  margin-left: 8px;
}
</style>