longyvfengyun
2023-12-25 d8d792a6842832e8f6af6604274c438b25053afe
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
<template>
  <div class="res-line-wrapper">
    <div class="res-line-times">
      <flex-box no-header size="mini">
        <div class="checkbox-wrapper">
          <div class="checkbox-wrapper-header">
            <el-checkbox :indeterminate="isIndeterminate" v-model="checkAll" @change="handleCheckAllChange">全选</el-checkbox>
          </div>
          <div class="checkbox-group-wrapper">
            <el-checkbox-group v-model="checkedTimes" @change="handleCheckedTimesChange">
              <div class="checkbox-item" v-for="item in times" :key="item">
                <el-checkbox :label="item">{{item}}</el-checkbox>
              </div>
            </el-checkbox-group>
          </div>
        </div>
      </flex-box>
    </div>
    <div class="res-line-content">
      <flex-box no-header size="mini">
        <normal-lines ref="line"></normal-lines>
      </flex-box>
    </div>
  </div>
</template>
 
<script>
import FlexBox from "@/components/FlexBox";
import NormalLines from "@/components/myCharts/NormalLines";
export default {
  name: "resLineContrast",
  components: {
    NormalLines,
    FlexBox
  },
  props: {
    list: {
      type: Array,
      default() {
        return []
      },
    },
    updateTime: {
      type: Number,
      default: 0,
    },
    active: {
      type: String,
      default: ""
    }
  },
  data() {
    return {
      checkedTimes: [],
      times: [],
      checkAll: false,
      isIndeterminate: false,
      standardResData: [],
    }
  },
  watch: {
    updateTime() {
      this.init();
    },
    active() {
      this.$refs.line.resize();
    }
  },
  methods: {
    init() {
      this.times = this.list.filter(item=>{
        return !item.isStandard;
      }).map(item=>{
        return item.time;
      });
      // 初始化标准内阻值
      let standardResInfo = this.list.filter(item=>{
        return item.isStandard;
      });
      this.standardResData = standardResInfo.length!=0?standardResInfo[0].data:[];
    },
    handleCheckAllChange(val) {
      let times = this.times.map(item=>{
        return item;
      });
      this.checkedTimes = val ? times : [];
      this.isIndeterminate = false;
      this.setLineOption(this.checkedTimes);
    },
    handleCheckedTimesChange(value) {
      let checkedCount = value.length;
      this.checkAll = checkedCount === this.times.length;
      this.isIndeterminate = checkedCount > 0 && checkedCount < this.times.length;
      this.setLineOption(this.checkedTimes);
    },
    setLineOption(times) {
      let list = this.list;
      let standardResData = this.standardResData;
      let series = times.map(item=>{
        let tmp = {
          type: "line",
          name: item,
          data: []
        };
        for(let i=0; i<list.length; i++) {
          let item1 = list[i];
          if(item1.time == item) {
            tmp.data = item1.data;
            break;
          }
        }
        if(standardResData.length != 0) {
          tmp.data = tmp.data.map((value, key)=>{
            let standardValue = standardResData[key];
            console.log(standardValue);
            return standardValue?(value-standardValue):value;
          });
        }
        return tmp;
      });
      let xData = [];
      if(series.length != 0) {
        xData = series[0].data.map((item, key)=> {
          return "#"+(key+1);
        });
        this.$refs.line.setData({
          xData: xData,
          series: series
        })
      }else {
        this.$refs.line.clear();
        this.$refs.line.setData({
          xData: [],
          series: [{
            type: 'line',
            data: []
          }]
        });
      }
    }
  },
  mounted() {
    this.setLineOption(this.checkedTimes);
  }
}
</script>
 
<style scoped>
.res-line-wrapper {
  display: flex;
  height: 100%;
}
.res-line-times {
  padding: 0 0 0 8px;
}
.res-line-content {
  flex: 1;
  padding: 0 8px;
}
.checkbox-item {
  padding-bottom: 8px;
}
.checkbox-wrapper {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-width: 190px;
}
.checkbox-wrapper-header {
  padding: 8px 16px;
}
.checkbox-group-wrapper {
  flex: 1;
  overflow-y: scroll;
  padding: 0 16px;
}
</style>