whychw
2020-12-14 9877de737c3185dcb8815047de297d39d41d9a83
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
<template>
    <div class="page-container" ref="page">
        <el-row class="out-row" :gutter="16">
            <el-col :span="4" style="height: 100%;">
                <el-row :gutter="16">
                    <el-col :span="24" style="height: 100%;">
                        <box-all 
                        title="充放电信息"
                        style="height: 100%;">
                            <div class="inner">
                                <test-list 
                                :params="testParams"
                                @select-change="handlerTestList"></test-list>
                                <div class="p-footer">
                                    <div class="btn_3d" :class="{'disabled': !selected}" @click="exportCsv">导出数据</div>
                                </div>
                            </div>
                        </box-all>
                    </el-col>
                </el-row>
                <el-row :gutter="16">
                    <el-col :span="24" style="height: 100%;">
                        <box-all 
                        title="设备状态" 
                        :style="getDiffStyle"
                        v-loading="rtstate.loading"
                        element-loading-background="rgba(0, 0, 0, 0.8)"
                        element-loading-text="数据加载中">
                            <div class="dev-states" v-show="showAbnormal">
                                <div class="dev-state-item">
                                    突变起始时间: {{start_time}}
                                </div>
                                <div class="dev-state-item">
                                    初始电流: {{start_curr}} A
                                </div>
                                <div class="dev-state-item">
                                    结束电流: {{end_curr}} A
                                </div>
                            </div>
                            <div class="dev-states" v-show="!showAbnormal">
                                <div class="dev-state-item">
                                    电池状态:{{getBattState}}
                                </div>
                                <div class="dev-state-item">
                                    端电压:在线 {{rtstate.data.online_vol}}V,组端 {{rtstate.data.group_vol}}V
                                </div>
                                <div class="dev-state-item">
                                    电池电流:{{rtstate.data.test_curr}}A
                                </div>
                                <div class="dev-state-item">
                                    测试日期:{{rtstate.data.test_starttime}}
                                </div>
                                <div class="dev-state-item">
                                    测试时长:{{getTestTimeLong}}
                                </div>
                                <div class="dev-state-item">
                                    测试容量:{{rtstate.data.test_cap | fixed(1)}}AH
                                </div>
                                <!-- <div class="dev-state-item">
                                    剩余容量:{{rtstate.data.batt_rest_cap}}AH
                                </div>
                                <div class="dev-state-item">
                                    续航时长:{{rtstate.data.xuhang}}
                                </div> -->
                            </div>
                        </box-all>
                    </el-col>
                </el-row>
            </el-col>
            <el-col :span="20" style="height: 100%; overflow: hidden;">
                <div class="G-wraper" :class="{'show-abnormal': showAbnormal}">
                    <el-row :gutter="16">
                        <el-col :span="12" style="height: 100%;">
                            <!-- <div class="col-inner"> -->
                                <box-all 
                                title="端电压折线图" 
                                style="height: 100%;"
                                v-loading="loading"
                                element-loading-background="rgba(0, 0, 0, 0.8)"
                                element-loading-text="数据加载中">
                                    <div class="graph">
                                        <div class="graph-container" ref="groupLine"></div>
                                    </div>
                                </box-all>
                            <!-- </div> -->
                        </el-col>
                        <el-col :span="12" style="height: 100%;">
                            <!-- <div class="col-inner"> -->
                                <box-all 
                                title="单体信息柱状图" 
                                style="height: 100%;"
                                v-loading="loading"
                                element-loading-background="rgba(0, 0, 0, 0.8)"
                                element-loading-text="数据加载中">
                                    <div class="graph cut38">
                                        <div class="graph-container" ref="monInfoBar"></div>
                                    </div>
                                    <div class="slider-container">
                                        <el-slider 
                                        v-model="slider"
                                        :format-tooltip="setDataBySlide"></el-slider>
                                    </div>
                                </box-all>
                            <!-- </div> -->
                        </el-col>
                    </el-row>
                    <el-row :gutter="16">
                        <el-col :span="12" style="height: 100%;">
                            <!-- <div class="col-inner"> -->
                                <box-all 
                                title="电池电流折线图" 
                                :style="getDiffStyle"
                                v-loading="loading"
                                element-loading-background="rgba(0, 0, 0, 0.8)"
                                element-loading-text="数据加载中">
                                    <div class="graph">
                                        <div class="graph-container" ref="currLine"></div>
                                    </div>
                                </box-all>
                            <!-- </div> -->
                        </el-col>
                        <el-col :span="12" style="height: 100%;">
                            <box-all 
                            title="单体电压折线图" 
                            :style="getDiffStyle"
                            v-loading="loading"
                            element-loading-background="rgba(0, 0, 0, 0.8)"
                            element-loading-text="数据加载中">
                                <div class="graph">
                                    <div class="graph-container" ref="monLine"></div>
                                </div>
                            </box-all>
                        </el-col>
                    </el-row>
                    <el-row class="panel-abnormal" :gutter="16">
                        <el-col :span="24" style="height: 100%;">
                            <box-all 
                                title="电池电流突变折线图" 
                                :style="getDiffStyle"
                                v-loading="loading"
                                element-loading-background="rgba(0, 0, 0, 0.8)"
                                element-loading-text="数据加载中">
                                <div class="graph">
                                    <div class="graph-container" ref="currAbnormalLine"></div>
                                </div>
                            </box-all>
                        </el-col>
                    </el-row>
                </div>
            </el-col>
        </el-row>
        <el-dialog
          title="修改"
          :visible.sync="settingsVisible"
          width="26em"
          class="dialog-bg">
          <div class="D-content">
            <el-form ref="form_settings" :model="settingsData" :rules="rules" label-position="left" label-width="14em">
              <el-form-item label="霍尔量程" prop="clamp_range">
                <el-input v-model="settingsData.clamp_range"><template slot="append">A</template></el-input>
              </el-form-item>
              <el-form-item label="电流变化阀值" prop="delta_limit">
                <el-input v-model="settingsData.delta_limit"><template slot="append">A</template></el-input>
              </el-form-item>
            </el-form>
          </div>
          <span slot="footer" class="dialog-footer h-center">
            <el-button type="primary" @click="settingsConfirm">确定</el-button>
            <el-button  @click="settingsVisible = false">取消</el-button>
          </span>
        </el-dialog>
        <progress-load 
        :show="progress.show"
        :percentage="progress.value"
        :text="progress.text"></progress-load>
    </div>
</template>
 
<script>
import echarts from 'echarts'
import BoxAll from '../components/BoxAll'
import TestList from '@/components/TestList'
import ProgressLoad from '@/components/ProgressLoad'
import {
    formatSeconds,
    EGraph,
} from '@/assets/js/common'
 
let currAbnormalLine;
var groupLine = "";
var currLine = "";
var monLine = "";
var monInfoBar = "";
var allData = [];
export default {
    components: {
        BoxAll,
        TestList
        ,ProgressLoad
    },
    data() {
        return {
            settingsVisible: false,
            battIdx: this.$route.query.idx || 0,
            settingsData: {
              clamp_range: 0,
              delta_limit: 0
            },
            start_time: '',
            start_curr: 0,
            end_curr: 0,
            showAbnormal: false,
            selected: false,
            exportObj: null,
            progress: {
                show: false,
                value: 0,
                text: '',
            },
            main: {
                width: 100,
                height: 100
            },
            testParams: {
                num: '',
                BattGroupId: '',
            },
            rtstate: {
                loading: false,
                stop_resean: '无',    // 停止原因
                data: {
                    test_type: 0,
                    online_vol: 0,  // 在线电压
                    group_vol: 0,   // 组端电压
                    test_curr: 0,  // 电池电流
                    test_starttime: '1982-01-01 00:00:00',    // 测试日期
                    test_timelong: 0, // 测试时长
                    test_cap: 0,   // 测试容量
                    batt_rest_cap: 0,   // 剩余容量
                    xuhang: '------',   // 续航时间
                }
            },
            loading: false,
            slider: 100,
            record_num: 0,
            testData: {      // 所有的测试数据
                allData: [],
                everyCount: [],
                groupVol: [],
                onlineVol: [],
                testCurr: [],
                testTime: []
            },
            rules: {
              clamp_range: [{
                validator: (rule, value, callback) => {
                  // console.log(value);
                  if (!('' + value).trim()) {
                    callback(new Error('量程值必填'));
                  }
                  if (/[^0-9]/.test(('' + value).trim())) {
                    callback(new Error('量程值必须为正整数'));
                  }
                  if (value < 0 || value > 50000) {
                    callback(new Error('量程值应介于0~50000之间'));
                  } else {
                    callback()
                  }
                },
                trigger: 'blur'
              }]
              ,delta_limit: [{
                validator: (rule, value, callback) => {
                  // console.log(value);
                  if (!('' + value).trim()) {
                    callback(new Error('阀值必填'));
                  }
                  if (!/^\d+(?:\.\d{1})?$/.test(('' + value).trim())) {
                    callback(new Error('阀值必须为数值,最多一位小数'));
                  }
                  if (value <= 10 || value > 5000) {
                    callback(new Error('阀值应介于10~5000之间'));
                  } else {
                    callback()
                  }
                },
                trigger: 'blur'
              }]
            }
        }
    },
    watch: {
        '$route.query.idx' () {
            // 初始化页面
            this.initPage();
        }
    },
    filters: {
        fixed(val, num) {
            return Number(val.toFixed(num));
        }
    },
    methods: {
        getBatt: function() {
            var batt = this.$store.state.battGroup;
            if(batt.BattGroupId == undefined) {
                return -1;
            }else {
                return batt;
            }
        },
        initPage() {
            // 设置测试数据列表
            this.setTestParams();
            // 初始化电池状体值
            this.initRtState();
            // 初始化testData
            // this.testData = [];
            // 查询电流突变数据
            this.getAbnormalInfo();
        },
        initRtState() {
            var data = {
                test_type: 0,
                online_vol: 0,  // 在线电压
                group_vol: 0,   // 组端电压
                test_curr: 0,  // 电池电流
                test_starttime: '1982-01-01 00:00:00',    // 测试日期
                test_timelong: 0, // 测试时长
                test_cap: 0,   // 测试容量
                batt_rest_cap: 0,   // 剩余容量
                xuhang: '------',   // 续航时间
            };
            this.rtstate.data = data;
            // 初始化图表
            this.initGraph();
        },
        initGraph() {
            groupLine.clear();
            monLine.clear();
            currLine.clear();
            monInfoBar.clear();
            currAbnormalLine.clear();
            allData=[];
        },
        setTestParams() {
            var batt = this.getBatt();
            if(batt != -1) {
                this.testParams.num = batt.FBSDeviceId;
                this.testParams.BattGroupId = batt.BattGroupId;
            }
        },
        handlerTestList(data) {
            // console.log(data, 'data');
            if (data.abnormal) {
                this.showAbnormal = true;
                this.start_time = data.text;
                this.start_curr = data.start_curr;
                this.end_curr = data.end_curr;
                // 查询电流突变数据
                this.getAbnormalInfo(data.val);
            } else {
                this.showAbnormal = false;
                // 设置终止原因
                this.rtstate.stop_resean = data.stop;
                // 初始化电池状体值
                this.initRtState();
                // 查询历史信息
                this.searchHistory(data);
            }
            this.selected = true;
            this.exportObj = data;
        }
        // 查询电流突变数据
        ,getAbnormalInfo (id) {
            // BattcurrdataAction!serchByCondition
            // 根据设备id和test_record_count查询突变情况实时数据
            // 参数 json:{"BattGroupId":"10000004","test_record_count":"1"}
            // test_record_count哪一次
            let params = {
                BattGroupId: this.$store.state.battGroup.BattGroupId
                ,test_record_count: id
            };
            // 显示等待框
            this.loading = true;
            // 请求后台查询
            this.$axios({
                method: 'post',
                url: 'BattcurrdataAction!serchByCondition',
                data: 'json=' + JSON.stringify(params)
            }).then((res)=> {
                res = JSON.parse(res.data.result);
                // console.log(res.data);
                let times = [];
                let datalist = [];
                if (res.code) {
                    res.data.forEach((v) => {
                        times.push(v.record_time);
                        datalist.push(v.group_curr);
                    });
                    // console.log(times, datalist);
                    this.setCurrAbnormalInfo(times, datalist);
                }
 
                // 关闭等待框
                this.loading=false;
            }).catch(()=>{
                // 关闭等待框
                this.loading=false;
            });
 
        }
        ,searchHistory(data) {
            var batt = this.getBatt();
            var searchParams = {
                BattGroupId: batt.BattGroupId,
                test_record_count: data.val
            };
            // 显示等待框
            this.loading=true;
            // 请求后台查询
            this.$axios({
                method: 'post',
                url: 'BatttestdataAction!findhistory',
                data: 'json='+JSON.stringify(searchParams)
            }).then((res)=> {
                var rs = JSON.parse(res.data.result);
                if(rs.code == 1) {
                    var data = rs.data;
                    this.formatAlldata(data);
                }else {
                    this.formatAlldata([]);
                }
                // 关闭等待框
                this.loading=false;
            }).catch(()=>{
                // 关闭等待框
                this.loading=false;
            });
        },
        formatAlldata(data) {
            allData = data;
            var monNums = this.getMonNums();       // 获取单体编号
            var groupVol = [];          // 组端电压
            var onlineVol = [];         // 组端电流
            var testCurr = [];          // 测试电流
            var testTime = [];          // 测试时间
            var everyCount = [];        // 每次测试的状态数据
            var batt_test_data = [];        // 电池单体测试数据
            var batt_test_voldata = [];     // 电池单体电压折线图
            var batt_test_tmpdata = [];         // 电池单体温度折线图
            var test_record_num = -1;
            var start_record_num = -1;
            var batt_index = -1;
            
            // data长度不为0
            if(data.length != 0) {
                start_record_num = data[0].record_num;
            }
            for(var k=0;k<monNums.length;k++){
                batt_test_voldata[k] = new Array();
                batt_test_tmpdata[k] = new Array();
            }
            // 遍历数据并进行处理
            for(var i=0; i<data.length; i++) {
                var _data = data[i];
                if(_data.record_num != test_record_num){
                    test_record_num = _data.record_num;             // 设置记录的num
                    groupVol.push(_data.group_vol.toFixed(2));        //组端电压
                    onlineVol.push(_data.online_vol.toFixed(2));        //在线电压
                    testCurr.push(_data.test_curr.toFixed(1));        //组端电流
                    testTime.push(formatSeconds(_data.test_timelong));     // 测试时间
                    everyCount.push(_data);             // 每次记录的状态数据
                    // 设置电池单体数据容器
                    batt_test_data[++batt_index] = new Array();
                    if(test_record_num > start_record_num){
                        batt_test_data[batt_index]=batt_test_data[batt_index-1].slice(0);
                        this.setArrayvalue(batt_test_voldata,batt_index);
                        this.setArrayvalue(batt_test_tmpdata,batt_index);
                    }
                }
                // 设置单体数据
                batt_test_data[batt_index][_data.mon_num-1] = _data.mon_vol;
                batt_test_voldata[_data.mon_num-1][batt_index] = _data.mon_vol;
                batt_test_tmpdata[_data.mon_num-1][batt_index] = _data.mon_tmp.toFixed(1);
            }
            //console.log(everyCount);
            // 设置状态数据
            this.testData.everyCount = everyCount;
            // 设置值
            this.slider = 100;
            // 设置组端电压折线图
            this.setGroupLine(groupVol, onlineVol, testTime);
            // 设置测试电流折线图
            this.setCurrLine(testCurr, testTime);
            // 设置单体折线图
            this.setMonLine(batt_test_voldata, testTime);
        },
        setArrayvalue(list, index) {
          if(list!=undefined && index > 0){
            for(var i=0;i<list.length;i++){
              list[i][index] = list[i][index-1];
            }
          }
        },
        getMonNums() {
            var batt = this.getBatt();
            var monCount = batt.MonCount;
            var rs = [];
            for(var i=0; i<monCount; i++) {
                rs.push('#'+(i+1));
            }
            return rs;
        },
        setGroupLine(groupVol, onlineVol, testTime) {
            groupLine.changeData({
                x: testTime,
                y: [
                    {
                        name: '组端电压',
                        data: groupVol,
                    },
                    {
                        name: '在线电压',
                        data: onlineVol
                    }
                ]
            });
        },
        setCurrLine(testCurr, testTime) {
            currLine.changeData({
                x: testTime,
                y: [
                    {
                        name: '电池电流',
                        data: testCurr,
                    }
                ]
            });
        },
        setMonLine(monData, testTime) {
            monLine.changeData({
                x: testTime,
                y: (function(data) {
                        let arr = [];
                        let arr_max = [];
                        let arr_min = [];
                        let arr_average = [];
                        for (let m = 0, n = testTime.length ,j = data.length; m < n; m++) {
                            let _arr = [];
                            for(let i = 0; i < j; i++) {
                                _arr.push(data[i][m]);
                            }
                            let max = Math.max(..._arr);
                            let min = Math.min(..._arr);
                            let sum = _arr.reduce((t, v) => {
                                return t + v;
                            });
                            let average = (sum / j).toFixed(3) * 1;
                            arr_max.push(max);
                            arr_min.push(min);
                            arr_average.push(average);
                        }
                        arr.push({
                            name: '最大值'
                            ,data: arr_max
                        }, {
                            name: '最小值'
                            ,data: arr_min
                        }, {
                            name: '平均值'
                            ,data: arr_average
                        });
                        // console.log(arr, data, '====data');
                        return arr;
                    })(monData)
            });
        },
        setDataBySlide(val) {
            if(val == null) {
                return val;
            }
            var index = this.getIndex();
            var rs = "00:00:00";
            if(index != -1) {
                var testCount = this.getTestCount(index);
                // 设置滑块显示的数字
                rs = formatSeconds(testCount.test_timelong);
                // 设置rtstate的值
                this.setRtState(testCount);
                this.record_num = testCount.record_num;
                this.setMonInfo();
            }
            return rs;
        },
        getIndex: function() {          // 获取笔数下标
            var val = this.slider;
            var everyCount = this.testData.everyCount;
            if(everyCount.length != 0) {
                return Math.floor((everyCount.length-1)*val/100);
            }else {
                return -1;
            }
        },
        getTestCount(index) {       // 获取显示的笔数
            return this.testData.everyCount[index];
        },
        setRtState(data) {      // 设置rtstate的值
            this.rtstate.data = data;
        },
        getStopCause(c_type, s_cause) {
            var rs = "";
            rs = c_type+"(终止原因:"+s_cause+")";
            return rs;
        },
        setMonInfo() {        // 设置单体信息
            var monInfo = this.getMonInfo(this.record_num);
            // 根据数据生成单体编号
            var monNums = [];
            for(var i=0; i<monInfo.length; i++) {
                monNums.push('#'+(i+1));
            }
            monInfoBar.changeData({
                x: monNums,
                y: [
                    {
                        name: '单体电压',
                        data: monInfo
                    }
                ]
            });
        },
        setCurrAbnormalInfo (times, data) {
            currAbnormalLine.changeData({
                x: times,
                y: [
                    {
                        name: '组端电流',
                        data
                    }
                ]
            });
        },
        getMonInfo(record_num) {
            var rs = [];
            // 遍历allData
            for(var i=0; i<allData.length; i++) {
                var data = allData[i];
                if(data.record_num==record_num) {
                    rs.push(data.mon_vol);
                }else if(data.record_num>record_num){
                    break;
                }
            }
            // 返回结果
            return rs;
        }
        /**
         * 获取文件导出时的进度条
         * 参数 null
         */
        ,getProgress () {
            return this.$axios({
                method: 'post',
                url: 'LoginAction!serchFileProgress',
                data: null
            }).then((res) => {
                res = JSON.parse(res.data.result);
                let percentage = Number(res.data[0].toFixed(0));
                this.progress.value = percentage;
                // console.log(res);
                if(percentage == 0) {
                    this.progress.text="数据加载中...";
                }else {
                    this.progress.text="文件下载中...";
                }
 
                if(res.data<100 && this.progress.show) {
                    setTimeout(this.getProgress, 50);
                }else {
                    this.progress.value = 100;
                    // this.progress.show = false;
                }
            });
        }
        /**
         * 清除进度条进度
         */
        ,clearProgress () {
            return this.$axios({
                method: 'post',
                url: 'LoginAction!clearProgress',
                data: null
            });
        }
        ,exportCsv () {
          var batt = this.getBatt();
 
          if (!this.exportObj) {
            return false;
          }
 
          const count = this.exportObj.val;
          const date = this.exportObj.text.split(' ')[0];
 
          let param = {
            dev_name: batt.BattGroupName.replace('#', '号'),
            dev_id: batt.BattGroupId,
            test_record_count: count,
            export_num: this.exportObj.abnormal ? 7 : 3,
            table_name: date.replace(/-/g, '_'),
            record_time: date + " 00:00:00"
          };
          // console.log(param, 'param');
 
          // 显示进度条
          this.progress.show = true;
          // 请求后台
          this.clearProgress().then(()=> {
            this.getProgress();
            this.$axios({
              method: 'post'
              ,url: 'CsvFileDownloadAction!searchDownloadFile'
              ,data: 'json=' + JSON.stringify(param)
              ,timeout: 0
            }).then(res=>{
                res = JSON.parse(res.data.result);
                // console.log(res, 'download res');
                if(res.code == 1) {
                    // 关闭进度条
                    this.progress.show = false;
                    this.progress.value = 0;
                    let data = res.data[0];
                    const link = document.createElement("a");
                    link.href = encodeURI(this.$config.url + 'tomcat7_csv/' + data.fileName);
                    link.download = data.fileName;
                    document.body.appendChild(link);
                    link.click();
                    document.body.removeChild(link);
                    setTimeout(()=>{
                        // 关闭进度条
                        this.progress.show = false;
                        this.progress.value = 0;
                    }, 1000);
                }else {
                    // 关闭进度条
                    this.progress.show = false;
                    this.progress.value = 0;
                    this.$layer.msg('生成文件失败!');
                }
            }).catch(error=>{
                // 关闭进度条
                this.progress.show = false;
                this.progress.value = 0;
                this.$layer.msg('生成文件失败!');
                console.warn(error);
            });
          });
        }
        ,handleShowSettings () {
            this.getDeltaLimit();
            this.settingsVisible = true;
            this.$nextTick(() => {
              this.$refs.form_settings.validate();
            });
        }
        // 查询当前阀值
        // Fbs9100_setparamAction!serchByCondition //查询汇集器参数
        // 传参json:{"dev_id":"960000001","op_cmd":"241"}
        // dev_id设备id(你看看查询左侧电池组信息时有没有查出FBSDeviceId这个是设备低),op_cmd是李军给的命令 (241是读取参数,243是设置参数)
        ,getDeltaLimit () {
            let param = {
                dev_id: this.$store.state.battGroup.FBSDeviceId,
                op_cmd: 241
            };
            // console.log('param', param);
            if (!param.dev_id) {
              return false;
            }
 
            // console.log(param, 'param');
            this.$axios({
              method: 'post'
              ,url: 'Fbs9100_setparamAction!serchByCondition'
              ,data: 'json=' + JSON.stringify(param)
              ,timeout: 0
            }).then((res) => {
              res = JSON.parse(res.data.result);
              // console.log(res, 999999999999999)
              if (res.code) {
                let data = res.data[0];
                this.settingsData.clamp_range = data.MonomerLowCount;
                this.settingsData.delta_limit = data.MonomerVol_Low;
              }
            });
        }
        // Fbs9100_setparamAction!update
        // 设置参数
        // 传参json:{"dev_id":"960000001","op_cmd":"243","MonomerVol_Low":"60","MonomerLowCount":"800"}
        // MonomerVol_Low 阈值,MonomerLowCount霍尔量程
        ,settingsConfirm () {
          this.$refs.form_settings.validate((valid) => {
            if (valid) {
              let param = {
                dev_id: this.$store.state.battGroup.FBSDeviceId,
                op_cmd: 243,
                MonomerLowCount: this.settingsData.clamp_range,
                MonomerVol_Low: this.settingsData.delta_limit
              };
              // console.log(param, 'param');
              this.$axios({
                method: 'post'
                ,url: 'Fbs9100_setparamAction!update'
                ,data: 'json=' + JSON.stringify(param)
              }).then((res) => {
                res = JSON.parse(res.data.result);
                if (res.code) {
                  this.$message({
                    type: 'success',
                    message: res.msg
                  });
                  this.settingsVisible = false;
                } else {
                  this.$message({
                    type: 'warning',
                    message: res.msg
                  });
                }
              });
            }
          });
        }
        // 查询所有电池组
        ,getAllBattList () {
            return this.$axios({
                method: "post",
                url: 'BattInfAction!searchAll',
                data: null 
            }).then((res) => {
                res = JSON.parse(res.data.result);
                // console.log(res);
                if(res.code == 1) {
                    var data = res.data;
                    this.$store.dispatch('changeBattList', data);
                    this.$store.dispatch('changeBattGroup', this.$store.state.allBattList[this.battIdx]);
                }
            });
        }
    },
    computed: {
        getBattState() {
            var rtstate = this.rtstate.data;
            return rtstate.test_type==3?this.getStopCause('放电', this.rtstate.stop_resean):rtstate.test_type==2?"充电":"未知";
        },
        getDiffStyle() {
            return {
                height: '100%',
                // 'margin-top': '0.8rem'
            };
        },
        getTestTimeLong() {     // 获取测试时长
            return formatSeconds(this.rtstate.data.test_timelong);
        },
    },
    mounted() {
        // 设置导航栏
        this.$store.dispatch('changeNavActive', 1);
        this.$event.$on('showSettings', this.handleShowSettings);
        // if (!this.$store.state.allBattList.length) {
          this.getAllBattList().then(() => {
            this.initPage();
          });
       /* } else {
          // 初始化页面
          this.initPage();
        }*/
 
        // 端电压折线图
        groupLine = new EGraph(this.$refs.groupLine, {
            type: 'line',
            init: {
                yAxis: {
                    name: 'V'
                }
            }
        });
        groupLine.chart.group = 'group1';
        // 电池电流
        currLine = new EGraph(this.$refs.currLine, {
            type: 'line',
            init: {
                yAxis: {
                    name: 'A'
                }
            }
        });
        currLine.chart.group = 'group1';
        // 单体电压折线图
        monLine = new EGraph(this.$refs.monLine, {
            type: 'line',
            init: {
                yAxis: {
                    name: 'V'
                }
            }
        });
        monLine.chart.group = 'group1';
        // 关联图表
        echarts.connect('group1');
        // 单体信息图表
        monInfoBar = new EGraph(this.$refs.monInfoBar, {
            init: {
                yAxis: {
                    name: 'V'
                }
            }
        });
        currAbnormalLine = new EGraph(this.$refs.currAbnormalLine, {
            type: 'line',
            init: {
                yAxis: {
                    name: 'A'
                }
            }
        });
        
 
        // window大小发生变化时echarts重置大小
        window.onresize = function() {
            groupLine.resize();
            currLine.resize();
            monLine.resize();
            currAbnormalLine.resize();
            monInfoBar.resize();
        }
    },
    destroyed() {
        // 销毁echrts对象
        groupLine.dispose();
        currLine.dispose();
        monLine.dispose();
        monInfoBar.dispose();
        currAbnormalLine.dispose();
        // 解除window.onresize
        window.onresize = null;
    }
}
</script>
 
<style scoped>
.page-container {
    height: 100%;
    /* display: -webkit-flex;
    display: flex;
    flex-direction: column; */
}
.page-container >>> .el-row:nth-child(1) {
    height: 47%;
}
.page-container >>> .el-row:nth-child(2) {
    height: 53%;
}
.page-container >>> .el-row:only-child {
    height: 100%;
}
>>> .el-row:first-of-type:not(:only-child) {
    padding-bottom: 10px;
    /*flex: 0.9;*/
}
.page-container div.el-row.out-row {
    padding-bottom: 0;
    height: 100%;
}
.dev-states {
    padding: 0.6rem;
}
.dev-state-item {
    line-height: 1.4rem;
}
.slider-container {
    padding-left: 0.8rem;
    padding-right: 0.8rem;
}
.graph,
.graph-container {
    height: 100%;
}
.graph.cut38 {
    height: calc(100% - 38px);
}
.inner {
    height: 100%;
    display: -webkit-flex;
    display: flex;
    flex-direction: column;
}
.inner .p-footer {
    display: -webkit-flex;
    display: flex;
    justify-content: center;
    padding: 6px;
}
.inner .p-footer .btn_3d {
    width: 8em;
}
.inner >>> .test-list {
    flex: 1;
}
.panel-abnormal {
    height: 100%;
}
.G-wraper {
    height: 100%;
    /*overflow: hidden;*/
}
.show-abnormal {
    -webkit-transform: translateY(-100%);
    transform: translateY(-100%);
}
.D-content {
  padding: 0 20px;
}
.D-content >>> .el-form-item__label {
  text-align: right;
  color: #fff;
}
.D-content >>> .el-input-group__append {
  width: 4em;
  color: #000;
}
>>> .dialog-bg .el-dialog__header {
    background-image: linear-gradient(#0fa1d9, #056aa5, #0fa1d9);
    color: #fff;
}
>>> .el-dialog__title {
    color: #fff;
}
>>> .el-dialog__headerbtn .el-dialog__close {
    color: #fff;
}
>>> .dialog-bg .el-dialog {
    background: #034362;
    color: #fff;
}
</style>