riku
2024-04-26 5efebb555efd984f3dd35de83e465cd53aaf8175
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
function ElectrictyUtil(options) {
  this.electricDataList = []
  this.defaultIndex = ['1', '2', '5', '6']// 表格默认展示因子
  // 图表数据
  this.chartData = {
    values: [],
    status: []
  }
  // 当前显示的下标
  this.checkOptions = ['1']// 电流值
  this.checkOptions2 = ['1']// 设备状态
  // 显示模式, 0: 显示电流值;1:显示装置运行状态
  this.mode = 0
 
  this.xAxis = []
  this.lineChart = options.lineChart
  this.chartSlider = options.chartSlider
  this.pageSize = options.pageSize
 
  this.factorMode = 'type3'// 监测因子对应模式
 
  // 多选框选项1
  this.options1 =  [{
      label: "产线喷漆房-电流",
      value: "1"
  }, 
  {
      label: "废气净化装置-电流",
      value: "2"
  }]
 
  // 多选框选项1
  this.options2 = [{
    label: "产线喷漆房-运行状态",
    value: "1"
  }, {
    label: "废气净化装置-运行状态",
    value: "2"
  }]
}
 
ElectrictyUtil.prototype = {
 
  init: function () {
 
    this.initChart()
    this.initTable()
  },
 
  initChart: function (){
    // 2.初始化监测因子复选框
    $('#history_chart_factorbox').empty()
    CheckBox.newCheckBox('history_chart_factorbox', this.options1, ['1'], this.onCheckLineChart.bind(this))
    // 3.创建初始折线图
    this.lineChartOption = FChart.genLineChart(this.lineChart, this.xAxis, [], false)
 
    this.chartData.values = []
    this.chartData.status = []
    // 电流值折线图
    for (let i = 0; i < this.options1.length; i++) {
      const o = this.options1[i]
      this.chartData.values.push({
        name: o.label,
        type: 'line',
        data: [],
        showAllSymbol: true,
        animationDelay: function(idx) {
          return idx * 10;
        },
        show: this.checkOptions.indexOf(o.value) != -1
      })
    }
    // 装置状态折线图
    for (let i = 0; i < this.options2.length; i++) {
      const o = this.options2[i]
      this.chartData.status.push({
        name: o.label,
        type: 'line',
        data: [],
        showAllSymbol: true,
        animationDelay: function(idx) {
          return idx * 10;
        },
        show: this.checkOptions2.indexOf(o.value) != -1
      })
    }
 
    var that = this
    $('#electrcity_status').on('click', function () {
      var op = that.options1
      var checks = that.checkOptions
      if (this.checked) {
        that.mode = 1
        op = that.options2
        checks = that.checkOptions2
      } else {
        that.mode = 0
        op = that.options1
        checks = that.checkOptions
      }
      $('#history_chart_factorbox').empty()
      CheckBox.newCheckBox('history_chart_factorbox', op, checks, that.onCheckLineChart.bind(that))
      that.refreshChart()
    })
  },
 
  onCheckLineChart: function (obj) {
    var index = parseInt(obj.value) - 1
    if (this.mode == 0) {
      this.chartData.values[index].show = obj.checked
    } else {
      this.chartData.status[index].show = obj.checked
    }
 
    var checkOp = this.checkOptions
    if (this.mode == 0) {
      checkOp = this.checkOptions
    } else {
      checkOp = this.checkOptions2
    }
    if (obj.checked) {
      checkOp.push(obj.value)
    } else {
      var i = checkOp.indexOf(obj.value)
      if (i != -1) {
        checkOp.splice(i, 1)
      }
    }
 
    this.refreshChart()
  },
 
  refreshChartCheckBox: function (type) {
    switch (type) {
      case 0:
        this.options1 =  [{
            label: "产线喷漆房-电流",
            value: "1"
        }, {
            label: "废气净化装置-电流",
            value: "2"
        }]      
        this.options2 = [{
          label: "产线喷漆房-运行状态",
          value: "1"
        }, {
          label: "废气净化装置-运行状态",
          value: "2"
        }]
        break;
      case 1:
        this.options1 =  [{
            label: "产线风机-电流",
            value: "1"
        }, {
            label: "废气净化装置-电流",
            value: "2"
        }]      
        this.options2 = [{
          label: "产线风机-运行状态",
          value: "1"
        }, {
          label: "废气净化装置-运行状态",
          value: "2"
        }]
        break;
      default:
        break;
    }
    // 初始化监测因子复选框
    this.mode = 0
    $('#electrcity_status').prop('checked', false)
    $('#history_chart_factorbox').empty()
    CheckBox.newCheckBox('history_chart_factorbox', this.options1, this.checkOptions, this.onCheckLineChart.bind(this))
  },
 
  refreshChart: function () {
    var that = this
    var series = this.chartData.values
    var label = undefined
    if (this.mode == 0) {
      series = this.chartData.values
    } else {
      series = this.chartData.status
      label = true
    }
    this.lineChartOption = FChart.genLineChart(this.lineChart, this.xAxis, series, false, undefined, function (value) {
      if (label) {
        if (value == 0) {
          return '待机'
        } 
        else if (value == 1) {
          return '低负荷运行'
        }
        else if (value == 2) {
          return '运行'
        }
        else if (value == 3) {
          return '超负荷'
        } else {
          return '待机'
        } 
      } else {
        return value
      }
    })
    this.chartSlider.setOnDragCallback(function(p) {
        if (p != that.lastProgress) {
          that.progress = p
          FChart.lineChartOnPage2({
            chart: that.lineChart,
            option: that.lineChartOption,
            progress: p,
            size: that.pageSize
          })
        }
      })
  },
 
  setPage: function (pageSize) {
    this.pageSize = pageSize
    FChart.lineChartOnPage2({
      chart: this.lineChart,
      option: this.lineChartOption,
      progress: this.progress,
      size: this.pageSize
    })
  },
 
  /**
   * 用电量数据格式化,转换为两种格式
   * 1. 所有设备的各项电流值
   * 2. 所有设备的运行状态
   */
  setData: function (electricDataList) {
    this.electricDataList = electricDataList
    this.xAxis = []
    this.chartData.values.forEach(v => {
      v.data = []
    })
    this.chartData.status.forEach(s => {
      s.data = []
    })
    electricDataList.forEach(d => {
      this.xAxis.push(d.time)
      this.chartData.values[0].data.push(d.d1Avg)
      this.chartData.values[1].data.push(d.d2Avg)
      // this.chartData.values[0].data.push(d.d1eA)
      // this.chartData.values[1].data.push(d.d1eB)
      // this.chartData.values[2].data.push(d.d1eC)
      // this.chartData.values[3].data.push(d.d2eA)
      // this.chartData.values[4].data.push(d.d2eB)
      // this.chartData.values[5].data.push(d.d2eC)
      this.chartData.status[0].data.push(d.d1Status)
      this.chartData.status[1].data.push(d.d2Status)
    })
  },
 
  initTable: function() {
    CheckBox.newCheckBox('history_table_factorbox', Util.selectOptions3[this.factorMode], this.defaultIndex, this.onCheckTable.bind(this))
  },
  onCheckTable: function(obj) {
    Table.onChangeTh(obj.value, obj.checked)
  },
 
  refreshTable: function() {
    Table.table('history_table', this.electricDataList, this.factorMode, {}, function(trC, d, indexs) {
      var td = $('<td></td>')
      td.append(d.time.split(' ')[1])
      trC.append(td)
 
      td = $('<td></td>')
      td.append(d.d1StatusName)
      td.prop("index", '1')
      trC.append(td)
      if (indexs.indexOf("1") != -1) {
          td.show("fast")
      } else {
          td.hide("fast")
      }
      td = $('<td></td>')
      td.append(d.d1Avg)
      td.prop("index", '2')
      trC.append(td)
      if (indexs.indexOf("2") != -1) {
          td.show("fast")
      } else {
          td.hide("fast")
      }
      // td = $('<td></td>')
      // td.append(d.d1eB)
      // trC.append(td)
      // if (indexs.indexOf("3") != -1) {
      //     td.show("fast")
      // } else {
      //     td.hide("fast")
      // }
      // td = $('<td></td>')
      // td.append(d.d1eC)
      // trC.append(td)
      // if (indexs.indexOf("4") != -1) {
      //     td.show("fast")
      // } else {
      //     td.hide("fast")
      // }
 
      td = $('<td></td>')
      td.append(d.d2StatusName)
      td.prop("index", '5')
      trC.append(td)
      if (indexs.indexOf("5") != -1) {
          td.show("fast")
      } else {
          td.hide("fast")
      }
      td = $('<td></td>')
      td.append(d.d2Avg)
      td.prop("index", '6')
      trC.append(td)
      if (indexs.indexOf("6") != -1) {
          td.show("fast")
      } else {
          td.hide("fast")
      }
      // td = $('<td></td>')
      // td.append(d.d2eB)
      // trC.append(td)
      // if (indexs.indexOf("7") != -1) {
      //     td.show("fast")
      // } else {
      //     td.hide("fast")
      // }
      // td = $('<td></td>')
      // td.append(d.d2eC)
      // trC.append(td)
      // if (indexs.indexOf("8") != -1) {
      //     td.show("fast")
      // } else {
      //     td.hide("fast")
      // }
    }, this.defaultIndex)
    $('#table_data_count').text('数据量:' + this.electricDataList.length + '个,单页:200个')
  },
}