whychdw
2019-12-03 4b308edb97d55d834bba88754e4a755b677e2b64
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
'use strict';
 
/**
 * 首页模块
 * 默认模块名: main
 * @return {[object]}  [ 返回一个对象 ]
 */
loader.define({
    data: {
        vm: ''
    },
    loaded: function loaded(require, exports, module) {
        // 引入vue
        this.vm = new Vue({
            el: getPageRoot(module),
            data: {
                tabs: {
                    active: 'menu',
                    menu: 4,
                    warning: 0,
                    charge: 0,
                    discharge: 0
                },
                tbls: {
                    warning: {
                        timer: new Timeout(),
                        name: '告警信息',
                        height: 300,
                        noData: '暂无告警数据',
                        page: {
                            PageSize: 10,
                            PageCurr: 1,
                            PageAll: 0
                        },
                        data: []
                    },
                    charge: {
                        timer: new Timeout(),
                        name: '充电电池组信息',
                        height: 300,
                        noData: '暂无充电电池组',
                        data: []
                    },
                    discharge: {
                        timer: new Timeout(),
                        name: '放电电池组信息',
                        height: 300,
                        noData: '暂无放电电池组',
                        data: []
                    }
                },
                routes: [{
                    path: '/monitor-data',
                    url: '../monitor-data/monitor-data.html'
                }, {
                    path: '/batt-info-set',
                    url: '../batt-info-set/batt-info-set.html'
                }, {
                    path: '/history-data',
                    url: '../history-data/history-data.html'
                }]
            },
            methods: {
                setTabsActive: function setTabsActive(str) {
                    this.tabs.active = str;
                },
                startReadBattDiscInfo: function startReadBattDiscInfo() {
                    var self = this;
                    this.tbls.discharge.timer.start(function () {
                        self.readBattDiscInfo();
                    }, 4000);
                },
                readBattDiscInfo: function readBattDiscInfo() {
                    //  读取放电信息
                    if (typeof DeviceService != 'undefined') {
                        DeviceService.readBattDiscInfo();
                    } else {
                        this.setBattDiscInfo({
                            code: 1,
                            data: [{
                                battinf: {
                                    num: 1,
                                    BattGroupName: '电池组1',
                                    BattGroupName1: '电池组'
                                },
                                state: {
                                    testStartTime: '2019-11-23 14:48:00',
                                    testTimelong: 20,
                                    groupvol: 10,
                                    groupcurr: 5
                                }
                            }]
                        });
                        // 开启计时器
                        this.tbls.discharge.timer.open();
                    }
                },
                setBattDiscInfo: function setBattDiscInfo(res) {
                    console.log(res);
                    // 对数据进行处理
                    this.tbls.discharge.data = this.formaterTestData(res);
                    // 统计个数
                    this.tabs.discharge = res.data.length;
                },
                startReadBattCharInfo: function startReadBattCharInfo() {
                    var self = this;
                    this.tbls.charge.timer.start(function () {
                        self.readBattCharInfo();
                    }, 4000);
                },
                readBattCharInfo: function readBattCharInfo() {
                    //  读取充电信息
                    if (typeof DeviceService != 'undefined') {
                        DeviceService.readBattCharInfo();
                    } else {
                        this.setBattCharInfo({
                            code: 1,
                            data: [{
                                battinf: {
                                    num: 2,
                                    BattGroupName: '电池组2',
                                    BattGroupName1: '电池组'
                                },
                                state: {
                                    testStartTime: '2019-11-23 14:48:00',
                                    testTimelong: 30,
                                    groupvol: 11,
                                    groupcurr: 4
                                }
                            }, {
                                battinf: {
                                    num: 5,
                                    BattGroupName: '电池组5',
                                    BattGroupName1: '电池组'
                                },
                                state: {
                                    testStartTime: '2019-11-23 14:50:40',
                                    testTimelong: 30,
                                    groupvol: 11,
                                    groupcurr: 4
                                }
 
                            }]
                        });
                        // 开启计时器
                        this.tbls.charge.timer.open();
                    }
                },
                setBattCharInfo: function setBattCharInfo(res) {
                    console.log(res);
                    // 对数据进行处理
                    this.tbls.charge.data = this.formaterTestData(res);
                    // 统计个数
                    this.tabs.charge = res.data.length;
                },
                formaterTestData: function formaterTestData(res) {
                    var rs = [];
                    if (res.code == 1) {
                        var data = res.data;
                        for (var i = 0; i < data.length; i++) {
                            var _data = data[i];
                            var tmp = {
                                num: _data.battinf.num,
                                BattGroupName: _data.battinf.BattGroupName,
                                BattGroupName1: _data.battinf.BattGroupName1,
                                testStartTime: new Date(_data.state.testStartTime).format('yyyy-MM-dd hh:mm:ss'),
                                testTimelong: formatSeconds(_data.state.testTimelong),
                                groupvol: _data.state.groupvol,
                                groupcurr: _data.state.groupcurr
                            };
                            rs.push(tmp);
                        }
                    }
                    return rs;
                },
                startSearchAlarmInfo: function startSearchAlarmInfo() {
                    var self = this;
                    this.tbls.warning.timer.start(function () {
                        self.searchAlarmInfo();
                    }, 4000);
                },
                searchAlarmInfo: function searchAlarmInfo() {
                    // 查询实时告警信息
                    var self = this;
                    var page = this.tbls.warning.page;
                    // 构造查询条件
                    var searchParams = {
                        alm_cleared_type: 0,
                        page: page
                    };
                    console.log(searchParams);
                    // 判断是否为手机端
                    if (typeof Battalram_dataService != "undefined") {
                        Battalram_dataService.serchByCondition(JSON.stringify(searchParams));
                    } else {
                        this.setAlarmInfo({
                            code: 1,
                            cmd_type: 0,
                            data: [{
                                num: 1,
                                note: '电池组1',
                                MonNum: 1,
                                alm_start_time: '2019-12-3 00:00:00',
                                alm_id: 119001,
                                alm_signal_id: 2,
                                alm_value: 39.7,
                                page: {
                                    PageAll: 40
                                }
                            }]
                        });
                        // 开启计时器
                        this.tbls.warning.timer.open();
                    }
                },
                setAlarmInfo: function setAlarmInfo(res) {
                    // 设置实时告警信息
                    console.info(res);
                    if (res.code == 1) {
                        var page = this.tbls.warning.page;
                        // 设置数据
                        var data = [];
                        for (var i = 0; i < res.data.length; i++) {
                            var _data = res.data[i];
                            var tmp = {};
                            var number = i + 1 + (page.PageCurr - 1) * page.PageSize;
                            tmp.number = number; // 编号
                            tmp.note = _data.note; // 电池组名称
                            tmp.alm_name = getTextByVal(_data.alm_id, battAlarmTypes); // 告警名称
                            tmp.alm_type = getTextByVal(_data.alm_signal_id, almSignalId); // 告警类型
                            tmp.MonNum = _data.MonNum; // 单体编号
                            tmp.alm_value = _data.alm_value + getTextByUnit(_data.alm_id, battAlarmTypes); // 告警值
                            tmp.alm_start_time = _data.alm_start_time; // 告警开始时间
                            data.push(tmp);
                        }
                        this.tbls.warning.data = data;
                        // 设置分页
                        this.tbls.warning.page.PageAll = res.data[res.data.length - 1].page.PageAll;
                    } else {
                        // 设置数据
                        this.tbls.warning.data = [];
                        // 设置分页
                        this.tbls.warning.page.PageAll = 0;
                    }
                    //console.log(res);
                },
                // 设置当前页
                warningCurrentChange: function warningCurrentChange(curr) {
                    this.tbls.warning.page.PageCurr = curr;
                    // 查询电池告警信息
                    this.startSearchAlarmInfo();
                },
                startTimers: function startTimers() {
                    // 启动页面的所有计时器
                    // 查询放电信息
                    this.startReadBattDiscInfo();
 
                    // 查询充电测试信息
                    this.startReadBattCharInfo();
 
                    // 查询告警
                    this.startSearchAlarmInfo();
                },
                stopTimers: function stopTimers() {
                    // 停止页面的所有计时器
                    // 告警中
                    this.tbls.warning.timer.stop();
                    // 充电中
                    this.tbls.charge.timer.stop();
                    // 放电中
                    this.tbls.discharge.timer.stop();
                },
                routerTo: function routerTo(path) {
                    var routes = this.routes;
                    var url = "";
                    // 遍历
                    for (var i = 0; i < routes.length; i++) {
                        var route = routes[i];
                        if (route.path == path) {
                            url = route.url;
                        }
                    }
                    // 跳转
                    router.load({
                        url: url,
                        param: {
                            random: Math.random().toFixed(2)
                        },
                        reload: true
                    });
                },
                setTblsHt: function setTblsHt() {
                    var totalHt = this.$refs.main.offsetHeight;
                    this.tbls.warning.height = totalHt - 168;
                    this.tbls.charge.height = totalHt - 136;
                    this.tbls.discharge.height = totalHt - 136;
                }
            },
            mounted: function mounted() {
                var self = this;
                this.setTblsHt();
 
                // 后台触发事件查询所有的电池组放电信息
                window['DeviceServicereadBattDiscInfocalljs'] = function (res) {
                    // 设置电池信息
                    self.setBattDiscInfo(res);
                    // 开启计时器
                    self.tbls.discharge.timer.open();
                };
 
                // 后台触发事件查询所有的电池组充电信息
                window['DeviceServicereadBattCharInfocalljs'] = function (res) {
                    // 设置电池信息
                    self.setBattCharInfo(res);
                    // 开启计时器
                    self.tbls.charge.timer.open();
                };
 
                // 查询告警信息
                window['Battalram_dataServiceserchByConditioncalljs'] = function (res) {
                    self.setAlarmInfo(res);
                    // 开启计时器
                    self.tbls.warning.timer.open();
                };
            },
            destroyed: function destroyed() {}
        });
    },
    show: function show() {
        // 开启计时器
        this.vm.startTimers();
        //bui.alert('show');
    },
    hide: function hide() {
        // 关闭计时器
        this.vm.stopTimers();
    },
    destroyed: function destroyed() {
        this.vm.$destroy();
    }
});