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
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
<template>
  <flex-layout no-bg>
    <div class="chart-tools-wrapper">
      <el-button size="mini" type="primary" @click="drawer=true">添加标准曲线</el-button>
    </div>
    <div class="flex-content-wrapper">
      <div class="flex-content-item" v-for="item in charts" :key="item">
        <line-chart :ref="item" :id="item" unit="V" no-full></line-chart>
      </div>
    </div>
    <el-drawer
        title="我是标题"
        direction="btt"
        :withHeader="false"
        size="80%"
        :visible.sync="drawer">
      <flex-layout no-bg>
        <div class="el-drawer-header" slot="header">
          <el-button type="primary" size="mini" icon="el-icon-view" @click="viewLine">标准曲线</el-button>
          <el-button type="primary" size="mini" icon="el-icon-refresh" @click="refreshPage">刷新</el-button>
        </div>
        <div class="el-drawer-content">
          <el-table
              stripe
              size="mini"
              header-row-class-name="header-primary"
              height="100%"
              :data="list"
              @select="tblSelect"
              @select-all="tblSelect">
            <el-table-column
                type="selection"
                width="55">
            </el-table-column>
            <el-table-column
                prop="monvolstd"
                label="标称电压(V)"
                min-width="150"
                :resizable="false"
                align="center">
            </el-table-column>
            <el-table-column
                prop="moncapstd"
                label="标称容量(AH)"
                min-width="150"
                :resizable="false"
                align="center">
            </el-table-column>
            <el-table-column
                prop="battproducer"
                label="电池品牌"
                min-width="150"
                :resizable="false"
                align="center"
                sortable>
            </el-table-column>
            <el-table-column
                prop="battmodel"
                label="电池型号"
                min-width="150"
                :resizable="false"
                align="center">
            </el-table-column>
            <el-table-column
                prop="hourRate"
                label="小时率"
                min-width="150"
                :resizable="false"
                align="center">
            </el-table-column>
          </el-table>
        </div>
        <div class="flex-page-footer" slot="footer">
          <el-pagination
              size="mini"
              :current-page="page.pageCurr"
              :page-sizes="[1 , 10, 20, 30, 50, 100]"
              :page-size="page.pageSize"
              layout="total, sizes, prev, pager, next, jumper"
              :total="page.pageAll"
              @current-change="currentChange"
              @size-change="sizeChange"></el-pagination>
        </div>
      </flex-layout>
    </el-drawer>
  </flex-layout>
</template>
 
<script>
import LineChart from "@/components/chart/LineChart";
 
export default {
  name: "standardLine",
  components: {LineChart},
  chartOption() {
    return {
      title: {
        show: true,
        text: "标准曲线(V)",
        x: "center",
        textStyle: {
          fontSize: "14"
        }
      },
      tooltip: {
        trigger: 'axis',
        axisPointer: { // 坐标轴指示器,坐标轴触发有效
          type: 'line' // 默认为直线,可选为:'line' | 'shadow'
        },
        appendToBody: true,
      },
      grid: {
        left: '1%',
        right: '1%',
        bottom: '2%',
        containLabel: true
      },
      series: [{
        name: '单体电压',
        data: []
      }],
    }
  },
  data() {
    return {
      drawer: false,
      list: [],
      charts: ['chart1'],
      selectList: [],
      page: {
        pageCurr: 1,
        pageSize: 10,
        pageAll: 0,
      },
    }
  },
  methods: {
    searchData() {
      let searchParams = this.page;
      let loading = this.$layer.loading();
      this.$apis.dataTest.history.searchStandardLines(searchParams).then(res=>{
        // 关闭等待框
        this.$layer.close(loading);
        // 格式化数据
        let rs = JSON.parse(res.data.result);
        let data = [];
        if(rs.code == 1) {
          data = rs.data;
          let _data = data[data.length-1];
          // 设置数据总数
          this.page.pageAll = _data.num;
        }else {
          this.page.pageCurr = 1;
          this.page.pageAll = 0;
        }
        this.list = data.map(item=>{
          item.hourRate = (item.note?(1/item.note).toHold(2):0)+"C";
          return item;
        });
      }).catch(error=>{
        // 关闭等待框
        this.$layer.close(loading);
        console.log(error);
      });
    },
    currentChange(value) {
      this.page.pageCurr = value;
      this.searchData();
    },
    sizeChange(value) {
      this.page.pageCurr = 1;
      this.page.pageSize = value;
      this.searchData();
    },
    resize() {
      let charts = this.charts;
      for(let i=0; i<charts.length; i++) {
        let chart = this.$refs[charts[i]][0];
        if(chart) {
          chart.resize();
        }
      }
    },
    setChartOption(list) {
      this.charts = [];
      this.$nextTick(()=>{
        let options = list.map((item1, key)=>{
          let id = 'chart'+key+'Num';
          this.charts.push(id);
 
          let chartOption = this.$options.chartOption();
          let title = "单体电压(V)";
          chartOption.series[0].data = item1.map(item2=>{
            let hourRate = (item2.note?(1/item2.note).toHold(2):0)+"C";
            title = "标称电压:"+item2.monvolstd+"V; 标称容量:"+item2.moncapstd+"AH; 电池品牌:"
                +item2.battproducer+"; 电池型号:"+item2.battmodel;
            return [item2.test_cap, item2.mon_vol]
          });
          chartOption.title.text = title;
          return {
            id: id,
            option: chartOption
          }
        });
        // 设置图表数据
        this.$nextTick(()=>{
          options.map(item=>{
            this.$refs[item.id][0].setOption(item.option);
          });
        });
      });
 
      //this.$refs.standardLine.setOption(chartOption);
    },
    refreshPage() {
      // 清空图表
 
      // 查询数据
      this.searchData();
    },
    tblSelect(data) {
      this.selectList = data;
    },
    viewLine() {
      let searchParams = this.selectList;
      this.searchStandarLine(searchParams, 0, []);
    },
    searchStandarLine(searchParams, index, list) {
      if(searchParams.length>4) {
        this.$layer.msg('最多选择4条进行查看');
        return;
      }
      if(searchParams.length == 0) {
        this.$layer.msg("请选择要查看的标准曲线");
        return;
      }
      // 获取到全部标准曲线后生成标准曲线
      if(searchParams.length<=index) {
        this.drawer = false;
        this.setChartOption(list);
        return;
      }
      let searchParam = searchParams[index];
      searchParam.vol_type = 1;
      this.$apis.dataTest.history.searchStandardLine(searchParam).then(res=>{
        let rs = JSON.parse(res.data.result);
        if(rs.code == 1) {
          list.push(rs.data);
        }
        // 查询
        this.searchStandarLine(searchParams, ++index, list);
      }).catch(error=>{
        // 查询
        this.searchStandarLine(searchParams, ++index, list);
      });
    },
  },
  mounted() {
    // 初始化图表
    setTimeout(() => {
      this.$nextTick(() => {
        this.resize();
      });
    }, 100);
 
    // 查询表格数据
    this.searchData();
 
    window.addEventListener('resize', this.resize);
  },
  destroyed() {
    window.removeEventListener('resize', this.resize);
  }
}
</script>
 
<style scoped>
.chart-tools-wrapper {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 10;
}
 
.el-drawer-content {
  height: 100%;
}
.flex-content-wrapper {
  display: flex;
  flex-direction: column;
  height: 100%;
}
.flex-content-item {
  flex: 1;
}
</style>