lishifeng
2020-09-15 ce10677f47a14879424e7f562f78442cc03cfda1
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
<template>
    <flex-layout direction="row" class="page-history">
        <home-list slot="header"
        @toggleChange="toggleChange"
        @leaf-click="leafClick"></home-list>
        <content-box style="margin-left: 4px; margin-right: 4px;" :title="battFullName">
            <div slot="box-tools" class="box-tools">
              <el-tooltip class="item" effect="dark" content="实时数据" placement="bottom">
                <i class="iconfont el-icon-jinru" @click="syncPage"></i>
              </el-tooltip>
            </div>
            <flex-layout>
                <div class="content-header" slot="header">
                    <div class="table-layout">
                        <div class="table-row">
                            <div class="table-cell text-right w80">电池状态:</div>
                            <div class="table-cell">
                                <el-input v-model="formateBattState" placeholder="" 
                                size="small" :disabled="true"></el-input>
                            </div>
                            <div class="table-cell text-right w80">端电压:</div>
                            <div class="table-cell">
                                <el-input v-model="top.group" placeholder="" 
                                size="small" :disabled="true" style="min-width:12rem"></el-input>
                            </div>
                            <div class="table-cell text-right w80">电池电流:</div>
                            <div class="table-cell">
                                <el-input v-model="top.curr" placeholder="" 
                                size="small" :disabled="true"></el-input>
                            </div>
                            <div class="table-cell text-right w80">测试时长:</div>
                            <div class="table-cell">
                                <el-input v-model="top.test_long" placeholder="" size="small" :disabled="true"></el-input>
                            </div>
                        </div>
                        <div class="table-row">
                            <div class="table-cell text-right w80">测试日期:</div>
                            <div class="table-cell">
                                <el-cascader v-model="test_record.value" :options="test_record.list" 
                                size="small" placeholder="请选择测试日期"
                                style="width: 100%; min-width:16rem"
                                @change="testRecordChange">
                                    <template slot-scope="{ node, data }">
                                        <span>{{ data.label }}</span>
                                        <span v-if="!node.isLeaf"> ({{ data.children.length }}) </span>
                                    </template>
                                </el-cascader>
                            </div>
                            <div class="table-cell text-right w80">测试容量:</div>
                            <div class="table-cell">
                                <el-input v-model="top.test_cap" placeholder="" 
                                size="small" :disabled="true"></el-input>
                            </div>
                            <div class="table-cell text-right w80">剩余容量:</div>
                            <div class="table-cell">
                                <el-input v-model="top.re_cap" placeholder="" 
                                size="small" :disabled="true"></el-input>
                            </div>
                            <div class="table-cell text-right w80">续航时间:</div>
                            <div class="table-cell">
                                <el-input v-model="top.xuhang" placeholder="" size="small" :disabled="true"></el-input>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="page-content">
                    <div class="flex-box-list">
                        <div class="flex-box">
                            <line-chart ref="groupVol" id="groupVol" unit="V"></line-chart>
                        </div>
                        <div class="flex-box">
                            <bar-chart ref="monBar" id="monBar" :show-label="false"></bar-chart>
                        </div>
                    </div>
                    <div class="flex-box-list">
                        <div class="flex-box">
                            <line-chart ref="groupCurr" id="groupCurr" unit="A"></line-chart>
                        </div>
                        <div class="flex-box">
                            <line-chart ref="monInfo" id="monInfo"></line-chart>
                        </div>
                    </div>
                </div>
                <div class="content-footer" slot="footer">
                    <div class="slider-container">
                        <el-slider v-model="slider" size="small" 
                        :format-tooltip="formatTooltip"
                        @input="sliderInput"></el-slider>
                    </div>
                </div>
            </flex-layout>
        </content-box>
    </flex-layout>
</template>
 
<script>
import ContentBox from "../../components/ContentBox";
import HomeList from "./HomeList";
import BarChart from "../../components/chart/BarChart";
import LineChart from "../../components/chart/LineChart";
 
import {
  searchBattTestData,
  searchBattTestDataStop,
  searchHistory
} from "../../assets/js/history";
 
import {
  formatSeconds,
  GetMonomerCap,
  GetHourRate,
  getBarNum,
} from "../../assets/js/tools";
 
// 端信息
let allData = {
  groupVol: [],
  onlineVol: [],
  testCurr: [],
  testTimeLong: [],
  recordTime: [],
  testCap: [],
  dataList: []
};
// 单体折线信息
let monLineData = {
  vol: []
};
// 单体柱状信息
let monBarData = {
  vol: []
};
// 4个图表
let groupVolLineChart, currLineChart, monLineChart, monBarChart;
 
export default {
  components: {
    ContentBox,
    HomeList,
    BarChart,
    LineChart
  },
  data() {
    
    return {
      data: [],
      batt: {},
      top: {
        state: "", // 电池状态
        group: "", // 端电压
        curr: "", // 电池电流
        test_long: "", // 测试时长
        test_cap: "", // 测试容量
        re_cap: "", // 剩余容量
        xuhang: "" // 续航时长
      },
      test_record: {
        value: [],
        list: [
          {
            value: "herongDischarge",
            label: "核容放电",
            children: []
          },
          {
            value: "jianceDischarge",
            label: "监测放电",
            children: []
          },
          {
            value: "herongCharge",
            label: "核容充电",
            children: []
          },
          {
            value: "jianceCharge",
            label: "监测充电",
            children: []
          }
        ]
      },
      slider: 100,
      testTimeLong: [],
      battState: {
        test_type: -100,
        stop_reason: ''
      }
    }
  },
  methods: {
    toggleChange() {
      console.log(123);
      this.resize();
    },
    resize() {
      this.$G.chartManage.resize("groupVol");
      this.$G.chartManage.resize("monBar");
      this.$G.chartManage.resize("groupCurr");
      this.$G.chartManage.resize("monInfo");
    },
    leafClick(data) {
      this.batt = data;
      // 重置页面内容
      this.init();
      // 获取充放电记录
      this.searchBattTestData();
    },
    // 初始化页面数据
    init() {
      // 初始化充放电记录
      this.test_record.value = [];
      this.test_record.list[0].children = [];
      this.test_record.list[1].children = [];
      this.test_record.list[2].children = [];
      this.test_record.list[3].children = [];
      // 初始化顶部文本框内容
      this.top = {
        state: "", // 电池状态
        group: "", // 端电压
        curr: "", // 电池电流
        test_long: "", // 测试时长
        test_cap: "", // 测试容量
        re_cap: "", // 剩余容量
        xuhang: "---" // 续航时长
      };
 
      // 初始化电池状态
      this.battState.test_type = -100;
 
      // 初始化图表
      this.initChart();
    },
    // 初始化图表和图表数据
    initChart() {
      // 拖动条默认值100
      this.slider = 100;
      this.testTimeLong = [];
 
      // 端信息
      allData = {
        groupVol: [],
        onlineVol: [],
        testCurr: [],
        testTimeLong: [],
        recordTime: [],
        testCap: [],
        dataList: [],
      };
      // 单体折线信息
      monLineData = {
        vol: []
      };
      // 单体柱状信息
      monBarData = {
        vol: []
      };
      // 端电压折线图
      groupVolLineChart = {
        color: ["#FF0000", "#15E3F3"],
        title: {
          show: true,
          text: "端电压折线图",
          x: "center",
          textStyle: {
            fontSize: "14"
          }
        },
        legend: {
          show: true,
          data: ["组端电压", "在线电压"],
          right: 0,
          orient: "vertical"
        },
        series: [
          {
            name: "组端电压",
            data: []
          },
          {
            name: "在线电压",
            data: []
          }
        ]
      };
 
      // 电池电流折线图
      currLineChart = {
        title: {
          show: true,
          text: "电池电流折线图",
          x: "center",
          textStyle: {
            fontSize: "14"
          }
        },
        series: [
          {
            name: "电池电流",
            data: []
          }
        ]
      };
 
      // 单体信息折线图
      monLineChart = {
        title: {
          show: true,
          text: "单体电压",
          x: "center",
          textStyle: {
            fontSize: "14"
          }
        },
        series: []
      };
      // 设置折线图
      this.setLineChart();
 
      // 单体信息柱状图
      monBarChart = {
        title: {
          show: true,
          text: "最大值=0V;最小值=0V;平均值=0V",
          x: "center",
          textStyle: {
            fontSize: "14"
          }
        },
        series: [
          {
            name: "单体电压",
            zlevel: 1,
            data: []
          }
          // {
          //     name: '初始单体电压',
          //     barGap: '-100%',
          //     zlevel: 0,
          //     hColor: '#FFFFFF',
          //     data: []
          // }
        ]
      };
      // 设置柱状图
      this.setBarChart();
    },
    // 设置折线图
    setLineChart() {
      // 设置端电压折线图
      this.setGroupVolLineChart();
      // 设置电池电流折线图
      this.setCurrLineChart();
      // 设置单体折线图
      this.setMonLineChart();
      // 建立联动
      this.$G.chartManage.connect(["groupVol", "groupCurr", "monInfo"]);
    },
    // 设置端电压折线图
    setGroupVolLineChart() {
      // 根据allData.groupVol数据设置groupVolLineChart的值
      groupVolLineChart.series[0].data = allData.groupVol;
      groupVolLineChart.series[1].data = allData.onlineVol;
      // 更新图表
      this.$refs.groupVol.setOption(groupVolLineChart);
    },
    // 设置电池电流折线图
    setCurrLineChart() {
      // 根据allData.testCurr数据设置currLineChart的值
      currLineChart.series[0].data = allData.testCurr;
      // 更新图表
      this.$refs.groupCurr.setOption(currLineChart);
    },
    // 设置单体折线图
    setMonLineChart() {
      // 根据monLineData的值设置monLineChart
      let dataList = monLineData.vol;
      monLineChart.series = dataList.map((item, index) => {
        let monNum = "#" + (index + 1);
        return {
          name: monNum,
          data: item
        };
      });
      // 更新图表
      this.$refs.monInfo.setOption(monLineChart);
    },
    // 设置柱状图
    setBarChart() {
      let batt = this.batt;
      // 根据monBarData的值设置monBarChart
      let dataList = monBarData.vol;
      let index = this.getDataIndex(dataList.length, this.slider);
      if (index != -1) {
        let data = dataList[index];
        let batNum = getBarNum(data);
        monBarChart.title.text = "最大值="+batNum.max+"V;最小值="+batNum.min+"V;平均值="+batNum.avg.toFixed(3)+"V"
        monBarChart.series[0].data = data;
        // monBarChart.series[1].data = dataList[0];
      }
      // 设置柱状图
      this.$refs.monBar.setOption(monBarChart);
    },
    // 查询测试信息
    searchBattTestData() {
      let batt = this.batt;
      // 开启等待框
      let loading = this.$layer.loading(1);
      searchBattTestData({
        num: batt.FBSDeviceId,
        BattGroupId: batt.BattGroupId
      })
        .then(res => {
          // 关闭等待框
          this.$layer.close(loading);
          // 解析数据
          let rs = JSON.parse(res.data.result);
          let herongDischarge = []; // 核容放电
          let herongCharge = []; // 核容充电
          let jianceDischarge = []; // 监测放电
          let jianceCharge = []; // 监测充电
          if (rs.code == 1) {
            rs.data.forEach(item => {
              item.value = item.test_starttime;
              item.label = item.test_starttime;
              if (item.test_type == 3) {
                // 测试类型为放电
                if (item.test_starttype == 3) {
                  //  核容放电
                  herongDischarge.push(item);
                } else {
                  // 监测放电
                  jianceDischarge.push(item);
                }
              } else if (item.test_type == 2) {
                // 测试类型为充电
                if (item.test_starttype == 3) {
                  //  核容充电
                  herongCharge.push(item);
                } else {
                  // 监测充电
                  jianceCharge.push(item);
                }
              }
            });
          } else {
            this.$layer.msg("未获取到充放电记录");
          }
          // 充放电记录
          this.test_record.list[0].children = herongDischarge;
          this.test_record.list[1].children = jianceDischarge;
          this.test_record.list[2].children = herongCharge;
          this.test_record.list[3].children = jianceCharge;
        })
        .catch(error => {
          this.$layer.close(loading);
          console.log(error);
        });
    },
    // 切换测试信息
    testRecordChange() {
      let testRecord = this.getTestRecord();
      // 初始化图表
      this.initChart();
 
      // 获取顶部电池组信息
      this.searchBattTestDataStop(
        testRecord.BattGroupId,
        testRecord.test_record_count
      );
 
      // 查询历史数据
      this.searchHistory(testRecord.BattGroupId, testRecord.test_record_count);
    },
    // 查询顶部信息
    searchBattTestDataStop(BattGroupId, count) {
      searchBattTestDataStop(BattGroupId, count).then(res => {
        let rs = JSON.parse(res.data.result);
        if (rs.code == 1) {
          let data = rs.data[0];
          this.top.test_cap = data.test_cap.toFixed(1) + "AH";
          this.top.test_long = formatSeconds(data.test_timelong);
        }
      });
    },
    // 查询历史信息
    searchHistory(BattGroupId, count) {
      // 开启等待框
      let loading = this.$layer.loading(1);
      searchHistory({
        BattGroupId: BattGroupId,
        test_record_count: count
      }).then(res => {
          // 关闭等待框
          this.$layer.close(loading);
          let rs = JSON.parse(res.data.result);
          let data = [];
          // 数据
          if (rs.code == 1) {
            data = rs.data;
          }
          // 格式化数据
          this.formateHisData(data);
        })
        .catch(error => {
          // 关闭等待框
          this.$layer.close(loading);
          console.log(error);
        });
    },
    // 格式化历史信息数据
    formateHisData(data) {
      let record_time = -1; // 记录时间
      data.forEach(item => {
        let mon_num = item.mon_num;
        // 获取组端电压,在线电压,组端电流的信息和开辟一个单体柱状图
        if (record_time != item.record_time) {
          record_time = item.record_time;
          allData.groupVol.push([record_time, item.group_vol]);
          allData.onlineVol.push([record_time, item.online_vol]);
          allData.testCurr.push([record_time, item.test_curr]);
          allData.recordTime.push(record_time);
          allData.testTimeLong.push(item.test_timelong);
          allData.testCap.push(item.test_cap);
          allData.dataList.push(item);
          this.testTimeLong.push(item.test_timelong);
          // 开辟空间
          monBarData.vol.push([]);
        }
        // 单体电压柱状图设置
        let monBarVol = monBarData.vol[monBarData.vol.length - 1];
        monBarVol.push(["#" + mon_num, item.mon_vol]);
 
        // 设置单体折线图信息
        if (typeof monLineData.vol[mon_num - 1] != "object") {
          // 开辟空间
          monLineData.vol[mon_num - 1] = [];
        }
        // 获取到需要使用的空间
        let monLineVol = monLineData.vol[mon_num - 1];
        monLineVol.push([record_time, item.mon_vol]);
      });
      // 设置折线图表
      this.setLineChart();
      // 执行滑动事件
      this.sliderInput();
    },
    // 获取测试的信息
    getTestRecord() {
      let value = this.test_record.value;
      // 没有选择充放电记录,返回-1
      if (value.length == 0) {
        return -1;
      }
      let type = value[0];
      let time = value[1];
      let list = this.test_record.list;
      let result = 0;
      // 遍历list
      for (let i in list) {
        let item = list[i];
        if (item.value == type) {
          for (let j in item.children) {
            let child = item.children[j];
            if (child.value == time) {
              result = child;
              break;
            }
          }
          break;
        }
      }
      // 设置电池状态
      this.battState.test_type = result.test_type;
      this.battState.stop_reason = result.test_stoptype_reason;
      // 返回结果集
      return result;
    },
    // 格式化滑块显示的内容
    formatTooltip(value) {
      let testTimeLong = this.testTimeLong;
      let index = this.getDataIndex(testTimeLong.length, value);
      let test_long = formatSeconds(0);
      if (index != -1) {
        test_long = formatSeconds(testTimeLong[index]);
      }
      this.top.test_long = test_long;
      return test_long;
    },
    // 拖动滑块时触发
    sliderInput() {
      // 设置头部信息
      this.setTopData();
 
      // 设置柱状图
      this.setBarChart();
    },
    // 设置顶部文本框的数据
    setTopData() {
      let batt = this.batt;
      // 组端电压和在线电压
      let groupVol = allData.groupVol;
      let onlineVol = allData.onlineVol;
      let testCurr = allData.testCurr;
      let testCap = allData.testCap;
      let monVols = monBarData.vol;
      let dataList = allData.dataList;
      let index = this.getDataIndex(groupVol.length, this.slider);
      if (index != -1) {
        this.top.group =
          "在线:" +
          onlineVol[index][1].toFixed(2) +
          "V;组端:" +
          groupVol[index][1].toFixed(2) +
          "V";
        this.top.curr = testCurr[index][1].toFixed(1) + "A";
        this.top.test_cap = testCap[index].toFixed(1) + "AH";
        // 剩余容量
        let monVol = monVols[index];
        let list = dataList[index];
        let avg_curr = list.test_timelong>0?list.test_cap*3600/list.test_timelong:list.test_curr;
        let batNum = getBarNum(monVol);
        let over_cap = GetMonomerCap(batt.MonCapStd, GetHourRate(batt.MonCapStd, avg_curr), 
        list.test_cap, batNum.max, batNum.min,batt.MonVolStd, 0);
        this.top.re_cap = over_cap.toFixed(1)+'AH';
      }
    },
    // 根据百分比获取显示的数据的笔数
    getDataIndex(num, percent) {
      return Math.floor(num * percent / 100) - 1;
    },
    // 向父级发送同步页面的指令
    syncPage() {
      let batt = this.batt;
      let search="?province="+batt.StationName1
      +"&city="+batt.StationName2+"&county="+batt.StationName5
      +"&home="+batt.StationName3+"&batt="+batt.BattGroupId;
      window.parent.postMessage({
        cmd: "syncPage",
        params: {
          pageInfo: {
            label: '实时监测',
            name: 'realTime',
            src: '#/real-time'+search,
            closable: true,
          }
        },
      }, "*");
    }
  },
  computed: {
    battFullName() {
      let batt = this.batt;
      if (batt.StationName && batt.BattGroupName) {
        return batt.StationName + "-" + batt.BattGroupName;
      }
      return "电池组全称";
    },
    formateBattState() {
      let battState = this.battState;
      if(battState.test_type == 3) {
        return "放电(终止原因:"+battState.stop_reason+")";
      }else if(battState.test_type == 2) {
        return "充电"
      }else {
        return "";
      }
    }
  },
  mounted() {
    // 初始化图表
    this.initChart();
    // 屏幕缩放时触发
    window.addEventListener("resize", () => {
      this.resize();
    });
  }
};
</script>
 
<style scoped>
.page-history {
  color: #ffffff;
}
.table-cell.text-right {
  font-size: 14px;
}
.table-row .table-cell {
  padding-top: 12px;
}
.page-content {
  position: relative;
  padding-top: 8px;
  padding-bottom: 2px;
  box-sizing: border-box;
  height: 100%;
}
.history-list {
  position: absolute;
  top: 8px;
  left: 24px;
  z-index: 99;
}
.flex-box-list {
  display: flex;
  flex-direction: row;
  height: 50%;
  box-sizing: border-box;
}
.page-content .flex-box {
  flex: 1;
  overflow-x: hidden;
}
.slider-container {
  padding-left: 16px;
  padding-right: 16px;
  overflow: hidden;
}
.box-tools {
  line-height: 32px;
}
.box-tools .iconfont {
  font-size: 20px;
}
.box-tools .iconfont:hover {
  cursor: pointer;
  color: #cfcfcf;
}
.box-tools .iconfont:active {
  color: #FF0000;
}
</style>