whyczyk
2022-02-09 3d8a4eb4995756b02d31417cafb882de0678cba0
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
<template>
    <div class="realMonitoring">
        <van-nav-bar title="实时监控" @click-left="$router.back()" left-arrow fixed safe-area-inset-top placeholder>
        </van-nav-bar>
        <div class="detailsCon">
            <div class="card">
                <div class="commonTitle cardTitle">
                    <van-field v-model="fieldValue" is-link readonly label="" placeholder="请选择具体站点" @click="showPopup = true" />
                </div>
                <div class="commonTitle">
                    <div class="label">电池状态:</div>
                    <div class="text">
                        {{backInputs.batt_state}}
                    </div>
                </div>
                <div class="commonTitle">
                    <div class="label">端电压:</div>
                    <div class="text">
                        {{backInputs.group_online_vol}}
                    </div>
                </div>
                <div class="commonTitle">
                    <div class="label">电池电流:</div>
                    <div class="text">
                        {{backInputs.group_curr}}
                    </div>
                </div>
                <div class="commonTitle">
                    <div class="label">更新日期:</div>
                    <div class="text">
                        {{backInputs.rec_datetime}}
                    </div>
                </div>
                <div class="commonTitle">
                    <div class="label">测试时长:</div>
                    <div class="text">
                        {{backInputs.batt_test_tlong}}
                    </div>
                </div>
                <div class="commonTitle">
                    <div class="label">测试容量:</div>
                    <div class="text">
                        {{backInputs.batt_test_cap}}
                    </div>
                </div>
                <div class="commonTitle">
                    <div class="label">剩余容量:</div>
                    <div class="text">
                        {{backInputs.batt_syrl_cap}}
                    </div>
                </div>
                <div class="commonTitle">
                    <div class="label">续航时长:</div>
                    <div class="text">
                        {{backInputs.sysc}}
                    </div>
                </div>
            </div>
 
            <div class="card">
                <div class="commonTitle cardTitle">电压</div>
                <div class="chartWarp">
                    <bar-chart ref="vol" id="vol" unit="V" right-menu></bar-chart>
                </div>
            </div>
 
            <div class="card">
                <div class="commonTitle cardTitle">内阻</div>
                <div class="chartWarp">
                    <bar-chart ref="res" id="res" unit="mΩ" max-color="red" min-color="green" right-menu></bar-chart>
                </div>
            </div>
 
            <div class="card">
                <div class="commonTitle cardTitle">温度</div>
                <div class="chartWarp">
                    <bar-chart ref="temp" id="temp" unit="℃" max-color="red" min-color="green" right-menu></bar-chart>
                </div>
            </div>
 
            <div class="card">
                <div class="commonTitle cardTitle">电导</div>
                <div class="chartWarp">
                    <bar-chart ref="conduct" id="conduct" right-menu></bar-chart>
                </div>
            </div>
 
            <div class="card">
                <div class="commonTitle cardTitle">均衡电流</div>
                <div class="chartWarp">
                    <bar-chart ref="curr" id="curr" unit="A" right-menu></bar-chart>
                </div>
            </div>
 
            <div class="card">
                <div class="commonTitle cardTitle">漏液电压</div>
                <div class="chartWarp">
                    <bar-chart ref="leakVol" id="leakVol" unit="V" right-menu></bar-chart>
                </div>
            </div>
 
            <div class="card">
                <div class="commonTitle cardTitle">均衡供电</div>
                <div class="listCon">
                    <div class="item">
                        {{otherTable[0].value}}
                        <div class="title">
                            版本号
                        </div>
                    </div>
                    <div class="item">
                        {{otherTable[1].value}}℃
                        <div class="title">
                            温度(℃)
                        </div>
                    </div>
                    <div class="item">
                        {{eleTable[0].value}}A
                        <div class="title">
                            总电流(A)
                        </div>
                    </div>
                    <div class="item">
                        {{totolTable[0].value}}V
                        <div class="title">
                            总电压(V)
                        </div>
                    </div>
                </div>
                <div class="chartWarp">
                    <progress-block-vertical-bar ref="outputVolList"></progress-block-vertical-bar>
                </div>
 
            </div>
 
        </div>
        <van-popup v-model="showPopup" round position="bottom">
            <van-cascader v-model="cascaderValue" title="请选择站点电池组" :options="options" active-color="#4b88f9" @change="onChange" @close="showPopup = false" @finish="onFinish" />
        </van-popup>
    </div>
</template>
 
<script>
import {
    searchStation,
    searchBattInfo,
    getBattGroupInfo,
    realTimeAlarm,
    realTimeSearch,
    realTimeGroup,
    JhStateActionSerchByCondition,
} from "@/pages/monitoring/js/api"
import BarChart from "@/components/chart/BarChart";
import progressBlockVerticalBar from "@/components/chart/progress-block-vertical-bar";
import getMarkLineData from "@/components/chart/js/getMarkLineData";
let vol, resChart, temp, conduct, currChart, leakVol;
let tblData = [];
export default {
    data() {
        return {
            showPopup: false,
            cascaderValue: '',
            fieldValue: '请选择站点',
            // 选项列表,children 代表子选项,支持多级嵌套
            options: [],
            /* 电池状态 模块 组端展示 */
            inputs: {
                group_vol: 0 /* 端电压-组端电压 */,
                online_vol: 0 /* 端电压-在线电压 */,
                group_curr: 0 /* 电池电流 */,
                batt_test_tlong: "0:00:00" /* 测试时长 */,
                rec_datetime: "1982-01-01 00:00:00" /* 更新日期 */,
                batt_test_cap: 0 /* 测试容量 */,
                batt_rest_cap: 0, // 剩余容量
                batt_state: 0 /* 电池状态 */
            },
            batt: {},
            timer: new this.$units.Timeout(),
            totolTable: [
                {
                    key: "input_vol_total",
                    name: "总输入电压",
                    value: 0,
                },
                {
                    key: "output_vol_total",
                    name: "总输出电压",
                    value: 0,
                },
            ],
            volTable: [
                {
                    key: "output_vol_one",
                    name: "输出电压1",
                    value: 0,
                },
                {
                    key: "output_vol_two",
                    name: "输出电压2",
                    value: 0,
                },
                {
                    key: "output_vol_three",
                    name: "输出电压3",
                    value: 0,
                },
                {
                    key: "output_vol_four",
                    name: "输出电压4",
                    value: 0,
                },
                {
                    key: "output_vol_five",
                    name: "输出电压5",
                    value: 0,
                },
                {
                    key: "output_vol_six",
                    name: "输出电压6",
                    value: 0,
                },
                {
                    key: "output_vol_seven",
                    name: "输出电压7",
                    value: 0,
                },
                {
                    key: "output_vol_eight",
                    name: "输出电压8",
                    value: 0,
                },
                {
                    key: "output_vol_nine",
                    name: "输出电压9",
                    value: 0,
                },
                {
                    key: "output_vol_ten",
                    name: "输出电压10",
                    value: 0,
                },
            ],
            eleTable: [
                {
                    key: "input_curr_total",
                    name: "总输入电流",
                    value: 0,
                },
                {
                    key: "output_curr_total",
                    name: "总输出电流",
                    value: 0,
                },
            ],
            otherTable: [
                {
                    key: "dev_version",
                    name: "版本号",
                    value: "???",
                },
                {
                    key: "dev_temp",
                    name: "温度",
                    value: "???",
                },
            ],
        }
    },
    components: {
        BarChart,
        progressBlockVerticalBar,
    },
    computed: {
        backInputs() {
            let obj = {
                0: "未知",
                1: "浮充",
                2: "充电",
                3: "放电",
                4: "均充",
            };
            let list = {
                batt_state: "未知",
                group_online_vol: "在线:0.00V;组端:0.00V",
                group_curr: "0.00A",
                rec_datetime: "1982-01-01 00:00:00",
                batt_test_tlong: this.$units.formatSeconds(0),
                batt_test_cap: "0Ah",
                batt_syrl_cap: "---",
                sysc: "------"
            };
            list.batt_state = obj[this.inputs.batt_state];
            list.group_online_vol =
                `在线:${this.inputs.online_vol.toFixed(
                    2
                )}V;组端:${this.inputs.group_vol.toFixed(2)}V`;
            list.group_curr = this.inputs.group_curr.toFixed(2) + "A";
            list.rec_datetime = this.inputs.rec_datetime;
            list.batt_test_tlong = this.$units.formatSeconds(this.inputs.batt_test_tlong);
 
            list.batt_test_cap = this.inputs.batt_test_cap.toFixed(1) + "AH";
            if (this.inputs.batt_state === 2) {
                list.batt_syrl_cap = "---";
            } else {
                list.batt_syrl_cap = this.inputs.batt_rest_cap.toFixed(1) + "AH";
            }
            if (this.inputs.batt_state === 3) {
                list.sysc = this.$units.sethoubeiTime(
                    parseFloat(this.inputs.batt_rest_cap) /
                    parseFloat(this.inputs.group_curr)
                );
            } else {
                list.sysc = "------";
            }
            return list;
        },
    },
    methods: {
        //定时器
        startTimer() {
            this.timer.start(() => {
                this.$axios
                    .all([
                        this.realTimeSearch(),
                        this.realTimeGroupss(),
                        this.search(),
                    ])
                    .then(() => {
                        this.timer.open();
                    })
                    .catch(() => {
                        this.timer.open();
                    });
            }, 3000);
        },
        search() {
            JhStateActionSerchByCondition({
                dev_id: this.batt.FBSDeviceId,
            })
                .then((res) => {
                    let resData = JSON.parse(res.data.result);
                    if (resData.code == 1) {
                        let dataObj = resData.data[0];
                        for (let key in dataObj) {
                            this.totolTable.map((item) => {
                                if (item.key == key) {
                                    item.value = dataObj[key];
                                }
                            });
                            this.volTable.map((item) => {
                                if (item.key == key) {
                                    item.value = dataObj[key];
                                }
                            });
                            this.eleTable.map((item) => {
                                if (item.key == key) {
                                    item.value = dataObj[key];
                                }
                            });
                            this.otherTable.map((item) => {
                                if (item.key == key) {
                                    item.value = dataObj[key];
                                }
                            });
                        }
                    }
                    // 设置输出电压柱状图
                    this.$refs.outputVolList.setData({
                        title: {
                            show: true,
                            text: "输出电压",
                            x: "center",
                            textStyle: {
                                fontSize: "14",
                                color: '#323233'
                            }
                        },
                        name: "输出电压",
                        list: this.volTable,
                    });
                })
                .catch((err) => {
                    console.log(err);
                });
        },
        //查询电池组信息
        getBattGroupInfo(BattGroupId) {
            getBattGroupInfo(BattGroupId).then(res => {
                let rs = JSON.parse(res.data.result);
                if (rs.code == 1) {
                    this.leafClick(rs.data[0]);
                } else {
                    this.$toast('未获取到电池组的信息');
                }
            }).catch(error => {
                console.log(error);
            });
        },
        leafClick(data) {
            this.batt = data;
            this.realTimeAlarmss();
            // 开启循环请求
            this.startTimer();
        },
        /* 查询电池告警参数 */
        realTimeAlarmss() {
            var batt = this.batt;
            realTimeAlarm({
                dev_id: batt.FBSDeviceId
            }).then(res => {
                let rs = JSON.parse(res.data.result);
                if (rs.code == 1) {
                    let list = rs.data;
                    // 单体电压
                    this.setChartMarkLine(vol, "Voltage", "Batt_Alarm_Type_MonVol", list);
                    // 单体温度
                    this.setChartMarkLine(temp, "Temperature", "Batt_Alarm_Type_MonTmp", list);
                    // 单体内阻
                    this.setChartMarkLine(resChart, "Resistance", "Batt_Alarm_Type_MonRes", list);
                    // 单体电导
                    this.setChartMarkLine(conduct, "Conductance", "Batt_Alarm_Type_MonRes", list);
                }
            });
        },
        setChartMarkLine(chartData, name, alm_name, list) {
            let batt = this.batt;
            // 遍历list
            for (let i = 0; i < list.length; i++) {
                let item = list[i];
                if (item.alm_name == alm_name) {
                    let high = 0;
                    let low = 0;
                    switch (name) {
                        case "Voltage":      // 电压告警
                            //单体电压
                            let std_mon_vol = batt.MonVolStd;
                            high = parseFloat(std_mon_vol * item.alm_high_coe).toHold(3);
                            low = parseFloat(std_mon_vol * item.alm_low_coe).toHold(3);
                            break;
                        case "Temperature":
                            //单体温度
                            let std_mon_tmp = 25;
                            high = parseFloat(std_mon_tmp * item.alm_high_coe).toHold(1);
                            low = parseFloat(std_mon_tmp * item.alm_low_coe).toHold(1);
                            break;
                        case "Resistance":
                            let std_mon_res = (1 * (batt.MonVolStd / 2)) / (batt.MonCapStd / 100);
                            high = parseFloat(std_mon_res * item.alm_high_coe).toHold(3);
                            low = parseFloat(std_mon_res * item.alm_low_coe).toHold(3);
                            break;
                        case "Conductance":
                            let std_mon_ser = batt.MonSerStd;
                            high = parseFloat(std_mon_ser * item.alm_high_coe).toHold(0);
                            low = parseFloat(std_mon_ser * item.alm_low_coe).toHold(0);
                            break;
                    }
                    // 低告警
                    chartData.series[0].markLine.data[0].yAxis = low;
                    // 高告警
                    chartData.series[0].markLine.data[1].yAxis = high;
                    break;
                }
            }
        },
        /* echars图表 */
        realTimeSearch() {
            var batt = this.batt;
            realTimeSearch({
                BattGroupId: batt.BattGroupId
            }).then(res => {
                let rs = JSON.parse(res.data.result);
                let data = [];
                if (rs.code == 1) {
                    data = rs.data.map(item => {
                        return {
                            num1: "#" + item.mon_num,
                            vol1: item.mon_vol,
                            res1: item.mon_res,
                            temp1: item.mon_tmp,
                            conduct1: item.mon_res ? (1 / item.mon_res * 1000).toFixed(0) : 0,
                            curr1: item.mon_JH_curr,
                            leakVol1: item.mon_LY_vol
                        };
                    });
                }
                // 更新表格
                if (this.acTabs == 'tblData') {
                    this.table.datas = data;
                } else {
                    tblData = data;
                }
                // 电压值
                let volTempVol = [];
                if (rs.code == 1) {
                    volTempVol = rs.data.map(item => {
                        return ["#" + item.mon_num, item.mon_vol];
                    });
                }
                let volBarNum = this.$units.getBarNum(volTempVol);
                vol.title.text = "最大值=" + volBarNum.max.toFixed(2) + "V;最小值=" + volBarNum.min.toFixed(2) + "V;平均值=" + volBarNum.avg
                    .toFixed(2) + "V";
                vol.series[0].data = volTempVol;
 
                // 内阻
                let volTempres = [];
                if (rs.code == 1) {
                    volTempres = rs.data.map(item => {
                        return ["#" + item.mon_num, item.mon_res];
                    });
                }
                let resBarNum = this.$units.getBarNum(volTempres);
                resChart.title.text = "最大值=" + resBarNum.max.toFixed(2) + "mΩ;最小值=" + resBarNum.min.toFixed(2) + "mΩ;平均值=" +
                    resBarNum.avg.toFixed(2) + "mΩ";
                resChart.series[0].data = volTempres;
 
                // 温度
                let volTempte = [];
                if (rs.code == 1) {
                    volTempte = rs.data.map(item => {
                        return ["#" + item.mon_num, item.mon_tmp];
                    });
                }
                let tempBarNum = this.$units.getBarNum(volTempte);
                temp.title.text = "最大值=" + tempBarNum.max.toFixed(1) + "℃;最小值=" + tempBarNum.min.toFixed(1) + "℃;平均值=" +
                    tempBarNum.avg.toFixed(1) + "℃";
                temp.series[0].data = volTempte;
 
                // 电导
                let conductTemp = [];
                if (rs.code == 1) {
                    conductTemp = rs.data.map(item => {
                        return ["#" + item.mon_num, item.mon_res ? (1 / item.mon_res * 1000).toFixed(0) : 0];
                    });
                }
                let conductBarNum = this.$units.getBarNum(conductTemp);
                conduct.title.text = "最大值=" + conductBarNum.max.toFixed(0) + ";最小值=" + conductBarNum.min.toFixed(0) + ";平均值=" +
                    conductBarNum.avg.toFixed(0);
                conduct.series[0].data = conductTemp;
                // 均衡电流
                let currTemp = [];
                if (rs.code == 1) {
                    currTemp = rs.data.map(item => {
                        return ["#" + item.mon_num, item.mon_JH_curr];
                    });
                }
                let currBarNum = this.$units.getBarNum(currTemp);
                currChart.title.text = "最大值=" + currBarNum.max.toFixed(1) + "mA;最小值=" + currBarNum.min.toFixed(1) + "mA;平均值=" +
                    currBarNum.avg.toFixed(1) + "mA";
                currChart.series[0].data = currTemp;
                // 漏液电压
                let leakVolTemp = [];
                if (rs.code == 1) {
                    leakVolTemp = rs.data.map(item => {
                        return ["#" + item.mon_num, item.mon_LY_vol];
                    });
                }
                let leakVolNum = this.$units.getBarNum(leakVolTemp);
                leakVol.title.text = "最大值=" + leakVolNum.max.toFixed(1) + "V;最小值=" + leakVolNum.min.toFixed(1) + "V;平均值=" +
                    leakVolNum.avg.toFixed(1) + 'V';
                leakVol.series[0].data = leakVolTemp;
                // 更新电压图表
                this.setChart();
            });
        },
        initChart() {
            // 电压
            vol = {
                title: {
                    show: true,
                    text: "最大值=0V;最小值=0V;平均值=0V",
                    x: "center",
                    textStyle: {
                        fontSize: "14",
                        color: '#323233'
                    }
                },
                series: [{
                    name: "电压",
                    type: "bar",
                    data: [],
                    markLine: {
                        data: getMarkLineData(),
                    },
                }]
            };
            // 漏液电压
            leakVol = {
                title: {
                    show: true,
                    text: "最大值=0V;最小值=0V;平均值=0V",
                    x: "center",
                    textStyle: {
                        fontSize: "14",
                        color: '#323233'
                    }
                },
                series: [{
                    name: "漏液电压",
                    type: "bar",
                    data: [],
                }]
            };
 
            // 内阻
            resChart = {
                title: {
                    show: true,
                    text: "最大值=0mΩ;最小值=mΩ;平均值=0mΩ",
                    x: "center",
                    textStyle: {
                        fontSize: "14",
                        color: '#323233'
                    }
                },
                series: [{
                    name: "内阻",
                    type: "bar",
                    data: [],
                    markLine: {
                        data: getMarkLineData(),
                    },
                }]
            };
 
            // 温度
            temp = {
                title: {
                    show: true,
                    text: "最大值=0℃;最小值=0℃;平均值=0℃",
                    x: "center",
                    textStyle: {
                        fontSize: "14",
                        color: '#323233'
                    }
                },
                series: [{
                    name: "温度",
                    type: "bar",
                    data: [],
                    markLine: {
                        data: getMarkLineData(),
                    },
                }]
            };
            // 电导
            conduct = {
                title: {
                    show: true,
                    text: "最大值=0;最小值=0;平均值=0",
                    x: "center",
                    textStyle: {
                        fontSize: "14",
                        color: '#323233'
                    }
                },
                series: [{
                    name: "电导",
                    type: "bar",
                    data: [],
                    markLine: {
                        data: getMarkLineData(),
                    },
                }]
            };
            // 均衡电流
            currChart = {
                title: {
                    show: true,
                    text: "最大值=0mA;最小值=0mA;平均值=0mA",
                    x: "center",
                    textStyle: {
                        fontSize: "14",
                        color: '#323233'
                    }
                },
                series: [{
                    name: "均衡电流",
                    type: "bar",
                    data: []
                }]
            };
            // 设置配置项
            this.setChart();
        },
        setChart() {
            this.$refs.vol.setOption(vol);
            this.$refs.res.setOption(resChart);
            this.$refs.temp.setOption(temp);
            this.$refs.conduct.setOption(conduct);
            this.$refs.curr.setOption(currChart);
            this.$refs.leakVol.setOption(leakVol);
        },
        /* 实时组端信息 */
        realTimeGroupss() {
            var batt = this.batt;
            realTimeGroup(batt.BattGroupId).then(res => {
                let rsa = JSON.parse(res.data.result);
                if (rsa.code == 1) {
                    this.inputs = rsa.data[0];
                }
            }).catch(err => {
                console.log(err)
            });
        },
        // 全部选项选择完毕后,会触发 finish 事件
        onFinish({ selectedOptions }) {
            this.showPopup = false;
            this.fieldValue = selectedOptions.map((option) => option.text).join('-');
            this.getBattGroupInfo(this.cascaderValue)
        },
        //选择站点时触发查询站点下电池组
        onChange(select) {
            if (select.tabIndex == 3) {
                let objs = select.selectedOptions[select.selectedOptions.length - 1];
                searchBattInfo({
                    StationName1: objs.data.StationName1,
                    StationName2: objs.data.StationName2,
                    StationName5: objs.data.StationName5,
                    StationName3: objs.data.StationName3
                }).then((res) => {
                    let rs = JSON.parse(res.data.result);
                    if (rs.code == 1) {
                        let data = rs.data;
                        data.map(item => {
                            item.text = item.StationName4 + '-' + item.BattGroupName
                            item.value = item.BattGroupId
                        })
                        this.options.map(item => {
                            item?.children.map(jtem => {
                                jtem?.children.map(etem => {
                                    etem?.children.map(gtem => {
                                        if (gtem.value == select.value) {
                                            gtem.children = data
                                        }
                                    })
                                })
                            })
                        })
                    }
                }).catch((err) => {
                    console.log(err)
                });
            }
        },
        //查询站点信息
        searchStation() {
            searchStation({
                StationName1: "",
                StationName2: "",
                StationName5: "",
            }).then((res) => {
                let rs = JSON.parse(res.data.result);
                let data = [];
                if (rs.code == 1) {
                    data = rs.data;
                }
                // 格式化数据
                this.formatData(data);
            }).catch(err => {
                console.log(err)
            });
        },
        //整理数据格式
        formatData(data) {
            let result = [];
            // 遍历数据构造树状
            data.forEach(item => {
                // 省
                let provice = this.addData(result, item.StationName1);
                // 市
                let city = this.addData(provice.children, item.StationName2, provice);
                // 区县
                let county = this.addData(city.children, item.StationName5, city);
                // 机房
                let home = this.addData(county.children, item.StationName3, county, item);
            });
            // 设置树状列表
            this.options = result;
        },
        addData(list, val, parent, data, leaf) {
            let item;
            let index = this.checkValIsIn(val, list);
            let parentId = parent ? parent.text + '-' : "";
            if (index == -1) {
                if (leaf) {
                    item = {
                        value: parentId + val + Math.random(),
                        text: val,
                        data: data,
                    };
                } else {
                    item = {
                        value: parentId + val + Math.random(),
                        text: val,
                        children: [],
                        data: data,
                    };
                }
                list.push(item);
            } else {
                item = list[index];
            }
            return item;
        },
        checkValIsIn(val, arr) {
            for (let i = 0; i < arr.length; i++) {
                if (arr[i].text == val) {
                    return i;
                }
            }
            return -1;
        },
    },
    mounted() {
        this.searchStation();
        // 初始化图表
        this.initChart();
    },
    destroyed() {
        this.timer.stop();
    }
}
</script>
 
<style scoped>
.realMonitoring {
    width: 100%;
    min-height: 100%;
    background: #f5f5f5;
}
.detailsCon {
    padding: 24px;
}
 
.card {
    background-color: #ffffff;
    border-radius: 16px;
    margin: 0 auto 24px;
    width: 702px;
    padding: 24px;
    box-shadow: 0px 4px 20px 0px rgba(75, 136, 249, 0.2);
}
 
.commonTitle {
    font-size: 28px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #333333;
    line-height: 40px;
    padding-bottom: 24px;
    border-bottom: 1px solid #eeeeee;
    margin-bottom: 22px;
    display: flex;
}
 
.cardTitle {
    font-weight: bold;
}
 
.cardTitle .van-cell {
    padding: 0;
}
 
.commonTitle .label {
    line-height: 40px;
    display: inline-block;
    width: 170px;
}
 
.commonTitle .text {
    flex: 1;
}
 
.chartWarp {
    width: 100%;
    height: 500px;
}
 
.listCon {
    width: 100%;
    height: 178px;
    border-bottom: 2px solid #eeeeee;
    display: flex;
    align-items: center;
    justify-content: space-around;
    position: relative;
    margin-bottom: 22px;
}
 
.listCon .item {
    font-size: 36px;
    font-family: DINAlternate-Bold, DINAlternate;
    font-weight: bold;
    color: #4b88f9;
    line-height: 56px;
    text-align: center;
}
 
.listCon .item .title {
    font-size: 28px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #333333;
    line-height: 40px;
    margin-top: 8px;
}
</style>