whychdw
2019-08-31 74d8534a366850995e2403ebe4af58097eb67843
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
/**
 * 电池信息监控模块
 * 默认模块名: battery
 * @return {[object]}  [ 返回一个对象 ]
 */
loader.define({
    data: {
        vm: ''
    },
    loaded: function(require,exports,module) {
        var bs = bui.store({
            scope: 'page',
            data: {}
        });
 
        /**
         * 规定params={battGroupId:'',battGroupName: '', devId: ''}
         */
        var params = router.getPageParams();
        var vm = this.vm = new Vue({
            el: bs.$el[0],
            data: {
                params: params,
                title: '未知',
                rtState: {
                    batt_test_type: '',     // 电池状态
                    group_vol: '',          // 组端电压
                    group_curr: '',         // 组端电流
                    batt_test_cap: '',      // 测试容量
                    batt_test_recordtime: '',   // 更新日期
                    batt_test_tlong: 0,     // 测试时长
                },
                tbls: {
                    monList: {
                        columns: [
                            {
                                title: '单体',
                                key: 'key1',
                            },
                            {
                                title: '电压(V)',
                                key: 'key2',
                            },
                            {
                                title: '内阻(mΩ)',
                                key: 'key3',
                            },
                            {
                                title: ' ',
                                key: 'key4',
                                width: 8,
                                className: 'split-td',
                            },
                            {
                                title: '单体',
                                key: 'key5',
                            },
                            {
                                title: '电压(V)',
                                key: 'key6',
                            },
                            {
                                title: '内阻(mΩ)',
                                key: 'key7',
                            },
                            {
                                title: ' ',
                                key: 'key8',
                                width: 8,
                                className: 'split-td',
                            },
                            {
                                title: '单体',
                                key: 'key9',
                            },
                            {
                                title: '电压(V)',
                                key: 'key10',
                            },
                            {
                                title: '内阻(mΩ)',
                                key: 'key11',
                            }
                        ],
                        data: []
                    }
                },
                options: {
                    monVol:{    // 单体电压
                        title: new Title(),
                        option: {
                            title: {
                                subtext: '',
                                x: 'center',
                            },
                            xAxis: {
                                type: 'category',
                                data: []
                            },
                            yAxis: {
                                type: 'value',
                                name: '单位(V)',
                                min: 0,
                                max: 10
                            },
                            series: [{
                                name: '电压',
                                type: 'bar',
                                data: []
                            }]
                        }
                    },
                    monRes: {   // 单体内阻
                        title: new Title(),
                        option: {
                            title: {
                                subtext: '',
                                x: 'center',
                            },
                            xAxis: {
                                type: 'category',
                                data: []
                            },
                            yAxis: {
                                type: 'value',
                                name: '单位(mΩ)',
                                min: 0,
                                max: 10
                            },
                            series: [{
                                name: '内阻',
                                type: 'bar',
                                data: []
                            }]
                        }
                    },
                    monTmp: {   // 单体内阻
                        title: new Title(),
                        option: {
                            title: {
                                subtext: '',
                                x: 'center',
                            },
                            xAxis: {
                                type: 'category',
                                data: []
                            },
                            yAxis: {
                                type: 'value',
                                name: '单位(℃)',
                                min: 0,
                                max: 10
                            },
                            series: [{
                                name: '温度',
                                type: 'bar',
                                data: []
                            }]
                        }
                    },
                    monSer: {   // 单体内阻
                        title: new Title(),
                        option: {
                            title: {
                                subtext: '',
                                x: 'center',
                            },
                            xAxis: {
                                type: 'category',
                                data: []
                            },
                            yAxis: {
                                type: 'value',
                                min: 0,
                                max: 10
                            },
                            series: [{
                                name: '电导',
                                type: 'bar',
                                data: []
                            }]
                        }
                    }
                }
            },
            methods: {
                searchRtState: function() {
                    var self = this;
                    var json = JSON.stringify({
                        BattGroupId: self.params.battGroupId
                    });
                    // 查询后台
                    ajax({
                        type: 'post',
                        async: true,
                        url: 'Batt_rtstateAction!serchByCondition',
                        data: 'json='+json,
                        dataType: 'json',
                        success: function(res) {
                            var rs = JSON.parse(res.result);
                            if(rs.code == 1) {
                                var data = rs.data[0];
                                // console.log(data);
                                self.rtState = data;
                            }
                        }
                    });
                },
                searchRtData: function() {
                    var self = this;
                    var json = JSON.stringify({
                        BattGroupId: self.params.battGroupId
                    });
                    // 查询后台
                    ajax({
                        type: 'post',
                        async: true,
                        url: 'Batt_rtdataAction!serchByCondition',
                        data: 'json='+json,
                        dataType: 'json',
                        success: function(res) {
                            var rs = JSON.parse(res.result);
                            // console.log(rs);
                            if(rs.code == 1) {
                                var data = rs.data;
                                console.log(data);
                                self.setOptions(data);
                            }
                        }
                    });
                },
                setOptions: function(data) {
                    // 遍历data的值
                    var monNum = [];        // 单体编号
                    var monVol = [];        // 单体电压
                    var monRes = [];        // 单体内阻
                    var monTmp = [];        // 单体温度
                    for(var i=0; i<data.length; i++) {
                        var _data = data[i];
                        monNum.push('#'+_data.mon_num);
                        monVol.push(_data.mon_vol);
                        monRes.push(_data.mon_res);
                        monTmp.push(_data.mon_tmp);
                    }
                    // 单体电压
                    this.options.monVol.option.xAxis.data = monNum;
                    this.options.monVol.option.series[0].data = monVol;
 
                    // 单体内阻
                    this.options.monRes.option.xAxis.data = monNum;
                    this.options.monRes.option.series[0].data = monRes;
 
                    // 单体温度
                    this.options.monTmp.option.xAxis.data = monNum;
                    this.options.monTmp.option.series[0].data = monTmp;
 
                    this.updateGraph();
                },
                // 更新图谱
                updateGraph: function() {
                    // 更新单体电压
                    this.$refs['monVolBar'].setOption(this.options.monVol.option);
 
                    // 更新单体内阻
                    this.$refs['monResBar'].setOption(this.options.monRes.option);
 
                    // 更新单体温度
                    this.$refs['monTmpBar'].setOption(this.options.monTmp.option);
 
                    // 更新单体电导
                    // this.$refs['monSerBar'].setOption(this.options.monSer.option);
                },
            },
            computed: {
                getTitle: function() {
                    var title = this.params.battGroupName?this.params.battGroupName: '未知';
                    return title;
                },
                getTestTimeLong: function() {
                    var testTimeLong = this.rtState.batt_test_tlong;
                    return formatSeconds(testTimeLong);
                },
                getBattState: function() {
                    // 获取电池信息
                    var test_type = this.rtState.batt_test_type;
                    var state = getBattstate(test_type);
                    return state;
                }
            },
            mounted() {
                // 脚本都需要在这里执行
                var uiTab = bui.tab({
                    id:"#uiTab"
                });
 
                // 显示图表
                this.updateGraph();
                // 查询电池组状态
                this.searchRtState();
                // 查询电池组信息
                this.searchRtData();
            },
        });
    },
    destroyed() {
        // 销毁vue实例
        this.vm.$destroy();
    },
});