1
81041
2019-06-20 ab3c4acf83f54f8449ca8664c4a2bb79bd30f297
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
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
<style scoped>
    .graph-container {
        background-color: #FFFFFF;
    }
</style>
<template>
    <div data-name="data-group-info" class="page">
        <!-- Top Navbar -->
        <div class="navbar">
            <div class="navbar-inner">
                <div class="left">
                    <a href="#" class="link back">
                        <i class="icon f7-icons">chevron_left</i>
                    </a>
                </div>
                <div class="title center">电池组统计分析查询</div>
                <div class="right">
                    <a href="#" class="link toggle-my-modal" data-href="#myModal">
                        <i class="icon f7-icons">menu</i>
                    </a>
                </div>
            </div>
        </div>
        <!-- Additional "tabbar-labels" class -->
        <div class="toolbar tabbar-labels toolbar-bottom">
            <div class="toolbar-inner">
                <a href="#tab-1" class="tab-link tab-link-active">
                    <!-- Different icons for iOS and MD themes -->
                    <i class="icon f7-icons">keyboard_fill</i>
                    <span class="tabbar-label">数据表格</span>
                </a>
                <a href="#tab-2" class="tab-link">
                    <!-- Different icons for iOS and MD themes -->
                    <i class="icon f7-icons">graph_square_fill</i>
                    <span class="tabbar-label">数据折线图</span>
                </a>
            </div>
        </div>
        <!-- Scrollable page content -->
        <div class="page-content" id="vContent">
              <div class="tabs">
                  <div class="tab tab-active" id="tab-1">
                      <div class="card data-table data-table-collapsible data-table-init">
                        <div class="card-content">
                            <table>
                                <thead>
                                    <tr>
                                        <th class="numeric-cell" v-for="thead in dataTbl.theads" v-bind:key="thead">${thead}</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <tr v-for="(item, key) in dataTbl.tbody">
                                        <td class="numeric-cell" v-bind:data-collapsible-title="dataTbl.theads[0]">${item.data.BattGroupIdPlus}</td>
                                        <td class="numeric-cell" v-bind:data-collapsible-title="dataTbl.theads[1]">${item.data.StationName}</td>
                                        <td class="numeric-cell" v-bind:data-collapsible-title="dataTbl.theads[2]">${item.data.BattGroupName}</td>
                                        <td class="numeric-cell" v-bind:data-collapsible-title="dataTbl.theads[3]">${item.tmodel.data[0].test_starttime}</td>
                                        <td class="numeric-cell" v-bind:data-collapsible-title="dataTbl.theads[4]">节能放电</td>
                                        <td class="numeric-cell" v-bind:data-collapsible-title="dataTbl.theads[5]">${item.tmodel.data[0].test_curr.toFixed(1)}</td>
                                        <td class="numeric-cell" v-bind:data-collapsible-title="dataTbl.theads[6]">${formatSeconds(item.tmodel.data[0].test_timelong)}</td>
                                        <td class="numeric-cell" v-bind:data-collapsible-title="dataTbl.theads[7]">${item.tmodel.data[0].test_cap.toFixed(1)}</td>
                                        <td class="numeric-cell" v-bind:data-collapsible-title="dataTbl.theads[8]">${item.tmodel.data[0].min_monnum}</td>
                                        <td class="numeric-cell" v-bind:data-collapsible-title="dataTbl.theads[9]">${item.tmodel.data[0].min_monvol}</td>
                                        <td class="numeric-cell" v-bind:data-collapsible-title="dataTbl.theads[10]">${item.tmodel.data[0].group_vol.toFixed(0)}</td>
                                        <td class="numeric-cell" v-bind:data-collapsible-title="dataTbl.theads[11]">${item.tmodel.data[0].mon_vol.toFixed(0)}</td>
                                        <td class="numeric-cell" v-bind:data-collapsible-title="dataTbl.theads[12]">${getCapPer(item.tmodel.data[0].group_vol, item.data.MonCapStd)}</td>
                                        <td class="numeric-cell" ></td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>
                  </div>
                  <div class="tab" id="tab-2">
                      <div class="graph-container" id="battDataLineGraph">
                         <div class="graph"></div>
                     </div>
                  </div>
              </div>
        </div>
        <!-- 左侧面板 -->
           <div class="my-modal" id="myModal">
               <div class="my-modal-rel">
                   <div class="my-modal-bg my-modal-close"></div>
                   <div class="my-modal-container">
                       <div class="my-modal-rel">
                           <div class="my-modal-header">
                               <div class="title center">条件筛选</div>
                           </div>
                           <div class="my-modal-content">
                               <div class="list no-margin">
                                   <ul>
                                       <li>
                                           <div class="item-content item-input">
                                               <div class="item-inner">
                                                   <div class="item-title item-label">电池组名称</div>
                                                   <div class="item-input-wrap">
                                                       <select v-model="modal.binf.BattGroupId">
                                                              <option v-for="item in battGroup.res" v-bind:value="item.value">${item.text}</option>
                                                       </select>
                                                   </div>
                                               </div>
                                           </div>
                                       </li>
                                       <li>
                                           <div class="item-content item-input">
                                               <div class="item-inner">
                                                   <div class="item-title item-label">电池测试时间段(起始)</div>
                                                   <div class="item-input-wrap">
                                                       <input type="text" placeholder="" 
                                                           readonly="readonly" 
                                                           v-model="tmp.record_time"
                                                           id="recordTime"/>
                                                   </div>
                                               </div>
                                           </div>
                                       </li>
                                       <li>
                                           <div class="item-content item-input">
                                               <div class="item-inner">
                                                   <div class="item-title item-label">电池测试时间段(结束)</div>
                                                   <div class="item-input-wrap">
                                                       <input type="text" 
                                                           placeholder="" 
                                                           readonly="readonly" 
                                                           v-model="tmp.record_time1"
                                                           id="recordTime1"/>
                                                   </div>
                                               </div>
                                           </div>
                                       </li>
                                   </ul>
                               </div>
                           </div>
                           <div class="my-modal-footer">
                               <div class="row">
                                   <button class="col button button-fill" v-on:click="searchData()">确定</button>
                                   <button class="col button button-fill color-orange my-modal-close">关闭</button>
                               </div>
                           </div>
                       </div>
                   </div>
               </div>
           </div>
    </div>
</template>
<script>
    return {
        data: function() {
            var params = this.$route.params;
            var cView = app.views.current;
            var paramsUrl = getUrlStr({
                province: params.province,
                city: params.city,
                county: params.county,
                home: params.home,
                fbsid: params.fbsid,
                stationid: params.stationid
            });
            return {
                params: params,
                myModal: '',
                vue: {
                    vContent: ''
                },
                page: {
                    baseUrl: '/data/'+paramsUrl,
                    pages: {
                        pageSize:10,                 //每页的行数
                        pageCurr:1,                  //当前页码数
                        pageAll:0,
                    }
                },
                lineGraph: ''
            };
        },
        on: {
            pageInit:function() {
                var pageThis = this;
                var params = this.params;
                var today = new Date().format('yyyy-MM-dd');
                // 定义vue内容
                var vContent = this.vue.vContent = new Vue({
                    el: '#vContent',
                    delimiters: ['${', '}'],
                    data: {
                        tmp: {
                            record_time: "2000-01-01",
                            record_time1: today
                        },
                        modal: {
                            page:{
                                pageCurr: 1,
                                pageSize: 50,
                            },
                            binf:{
                                StationName1: params.province,
                                StationName2: params.city,
                                StationName5: params.county,
                                StationName: params.home,
                                BattGroupId: 0,
                                BattProducer: null,
                                MonVolStd: null,
                                MonCapStd: null,
                                BattGroupName1: null,
                                BattProductDate: "2000-01-01 00:00:00",
                                BattProductDate1: today+' 23:59:59',
                                BattInUseDate: "2000-01-01 00:00:00",
                                BattInUseDate1: today+' 23:59:59',
                            },
                            uinf:{
                                UName: null
                            },
                            tdata:{
                                test_type: 3,
                                record_time: "2000-01-01 00:00:00",
                                record_time1: today+' 23:59:59',
                                test_starttype: 3,
                            },
                            mainf:{
                                remark: 100,
                                maint_done_time: "2000-01-01 00:00:00",
                                maint_done_time1: today+' 23:59:59'
                            }
                        },
                        myModal: '',
                        dataTbl: {
                            theads: ['电池组ID-序号', '机房名称', '电池组名称', '测试日期', '测试类型', '测试电流',
                                     '测试时长(H:M:S)', '测试容量(AH)', '最低单体编号', '最低单体电压(V)', '实际容量(AH)',
                                     '剩余容量(AH)', '容量百分比'],
                            tbody: []
                        },
                        battGroupData: []
                    },
                    created: function() {
                        var vm = this;
                        bus.$on('searchData', function(data) {
                            vm.modal = data;
                            vm.searchData();
                        });
                    },
                    watch:{
                        tmp: {
                            handler: function(nName, oName) {
                                console.log(nName);
                                console.log(oName);
                            },
                            deep: true
                        }
                    },
                    methods: {
                        searchData: function() {
                            var searchParams = this.modal;
                            var _self = this;
                            var lineGraphOpts={
                                lname: [],
                                name: [],
                                xData: [],
                                seriesData: []
                            };
                            $.ajax({
                                type: 'post',
                                async: true,
                                url: 'Batt_Maint_DealarmAction_serchLow',
                                data: 'result='+JSON.stringify(searchParams),
                                dataType: 'json',
                                beforeSend: function() {
                                    app.preloader.show();
                                    _self.dataTbl.tbody=[];
                                },
                                success: function(res) {
                                    var rs = JSON.parse(res.result);
                                    // 初始化折线图配置
                                    lineGraphOpts.seriesData = [];
                                    lineGraphOpts.lname = [];
                                    lineGraphOpts.xData = [];
                                    lineGraphOpts.name = [];
                                    
                                    if(rs.code == 1 && rs.data.length>0) {
                                        var data = rs.data;
                                        var battgroupid = 0;
                                        var order_num = 0;
                                        var xData = [];
                                        var battData = new Array();
                                        for(var i=0; i<data.length; i++) {
                                            var _data = data[i];
                                            if(_data.tmodel.code == 0){
                                                continue;
                                            }
                                            // 设置数据
                                            if(battgroupid != data[i].data.BattGroupId){
                                                order_num = 0;
                                                battData = new Array();        // 初始化battData
                                                battgroupid = data[i].data.BattGroupId;
                                                lineGraphOpts.lname.push(data[i].data.BattGroupId);
                                                lineGraphOpts.name.push(data[i].data.BattGroupName);
                                                lineGraphOpts.seriesData.push(battData);
                                            }
                                            order_num++;
                                            for(var j = 0;j<data[i].tmodel.data.length;j++){
                                                var _temp = [];        // 存储测试时间和实际容量
                                                var tmodel = data[i].tmodel.data[j];
                                                _data.data.BattGroupIdPlus = _data.data.BattGroupId+"-"+(order_num);
                                                
                                                // 添加测试时间和实际容量
                                                _temp.push(tmodel.test_starttime)
                                                _temp.push(tmodel.group_vol.toFixed(0));
                                                battData.push(_temp);
                                                // 添加所有的时间点
                                                xData.push(tmodel.test_starttime);
                                            }
                                        }
                                        lineGraphOpts.xData = _self.unique(xData).sort(function(a,b){
                                                                  var d1=new Date(a.replace(/-/g,"/"));
                                                                  var d2=new Date(b.replace(/-/g,"/"));
                                                                return d1-d2;
                                                            });
                                        _self.dataTbl.tbody = data;
                                        _self.myModal.hide();
                                        lineGraph.setOption(lineGraphOpts, $('#vContent'));
                                    }else {
                                        // Create center toast
                                        var toastCenter = app.toast.create({
                                            text: '未查询到结果',
                                            position: 'center',
                                            closeTimeout: 2000,
                                        });
                                        toastCenter.open();
                                    } 
                                },
                                complete: function() {
                                    app.preloader.hide();
                                }
                            });
                        },
                        getCapPer(vol, MonCapStd) {    // 容量百分比
                            return (vol*100/MonCapStd).toFixed(0)+"%"
                        },
                        unique: function(arr) {
                            var result = [], hash = {};
                            for (var i = 0, elem; (elem = arr[i]) != null; i++) {
                                if (!hash[elem]) {
                                    result.push(elem);
                                    hash[elem] = true;
                                }
                            }
                            return result;
                        }
                    }
                });
                
                
                var myModalVm = new Vue({
                    el: '#myModal',
                    delimiters: ['${', '}'],
                    data: {
                        tmp: {
                            record_time: "2000-01-01",
                            record_time1: today
                        },
                        modal: {
                            page:{
                                pageCurr: 1,
                                pageSize: 50,
                            },
                            binf:{
                                StationName1: params.province,
                                StationName2: params.city,
                                StationName5: params.county,
                                StationName: params.home,
                                BattGroupId: 0,
                                BattProducer: null,
                                MonVolStd: null,
                                MonCapStd: null,
                                BattGroupName1: null,
                                BattProductDate: "2000-01-01 00:00:00",
                                BattProductDate1: today+' 23:59:59',
                                BattInUseDate: "2000-01-01 00:00:00",
                                BattInUseDate1: today+' 23:59:59',
                            },
                            uinf:{
                                UName: null
                            },
                            tdata:{
                                test_type: 3,
                                record_time: "2000-01-01 00:00:00",
                                record_time1: today+' 23:59:59',
                                test_starttype: 3,
                            },
                            mainf:{
                                remark: 100,
                                maint_done_time: "2000-01-01 00:00:00",
                                maint_done_time1: today+' 23:59:59'
                            }
                        },
                        myModal: '',
                        battGroup: {
                            url: 'BattInfAction!serchBattByStation',
                            data: {
                                StationName1: params.province,
                                StationName2: params.city,
                                StationName5: params.county,
                                StationName: params.home,
                                StationId: params.stationid
                            },
                            res: []
                        },
                    },
                    created: function() {
                        var vm = this;
                        this.searchBattGroup();     // 查询电池组名称
                    },
                    methods: {
                        // 查询电池组列表
                        searchBattGroup: function() {
                            var vm = this;
                            var battGroup = this.battGroup;
                            $.ajax({
                                type: 'post',
                                async: true,
                                url: battGroup.url,
                                data: 'json='+JSON.stringify(battGroup.data),
                                dataType: 'json',
                                success: function(res) {
                                    var rs = JSON.parse(res.result);
                                    if(rs.code == 1) {
                                        var data = rs.data;
                                        var firData = {
                                            value: '0',
                                            text: '全部(共'+data.length+'种)'
                                        }
                                        for(var i=0; i<data.length; i++) {
                                            var _data = data[i];
                                            _data.value = _data.BattGroupId,
                                            _data.text = _data.BattGroupName
                                        }
                                        data.unshift(firData);
                                        battGroup.res = data;
                                    }else {
                                        battGroup.res = [{
                                            value: '0',
                                            text: '全部(共0种)'
                                        }];
                                    }
                                }
                            });
                        },
                        searchData: function() {
                            var searchParams = this.modal;
                            bus.$emit('searchData', searchParams);
                        }
                    }
                });
                
                // 自定义左侧面板
                var myModal = this.myModal = new MyModal('#myModal');
                vContent.myModal = myModal;
                myModal.show();
                
                var lineGraph = this.lineGraph = new LineEcharts2('battDataLineGraph', 'vContent');
                // 测试时间段
                var recordTime = app.calendar.create({
                    inputEl: '#recordTime',
                    monthNames: monthNames,
                    monthNamesShort: monthNamesShort,
                    dayNames: dayNames,
                    dayNamesShort: dayNamesShort,
                    footer: true,
                    toolbarCloseText: '确定',
                    on:{
                        change: function(calendar, value) {
                            var date = value[0].format('yyyy-MM-dd');
                            vContent.modal.tdata.record_time = date+' 00:00:00'
                        }
                    }
                });
                var recordTime1 = app.calendar.create({
                    inputEl: '#recordTime1',
                    monthNames: monthNames,
                    monthNamesShort: monthNamesShort,
                    dayNames: dayNames,
                    dayNamesShort: dayNamesShort,
                    footer: true,
                    toolbarCloseText: '确定',
                    on:{
                        change: function(calendar, value) {
                            var date = value[0].format('yyyy-MM-dd');
                            vContent.modal.tdata.record_time1 = date+' 23:59:59'
                        }
                    }
                    
                });
                
                $('a[href=#tab-2]').click(function() {
                    lineGraph.resize();
                });
            }
        }
    }
</script>