lxw
2020-07-11 9db52f2f2dd3665fe9da1ae5657e0167c3a34d40
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
;(function($, window, document, gl, undefined) {
    // 首页饼状图
    gl.namespace('Index.Pie');
    
    var pieType = [
         {
            name: '机房停电'
            ,cla: 'repair-pie'
         },
         {
             name: '机房续航能力'
                 ,cla: 'endur-pie'
         },
         {
             name: '电池状态'
             ,cla: 'brdn-pie'
         },
         {
             name: '电池告警率'
             ,cla: 'warn-pie' 
         },
         {
             name: '单体容量健康率'
             ,cla: 'health-pie'
         }
    ];
    
    // 将pieType绑定到Index.Pie命名空间下
    gl.Index.Pie.pieType = pieType;
    
    // 查询饼状图状态返回需要显示饼状图
    function pieStatus() {
        // 设置一个同步查询返回一个div.pie-item-list
        var pieItems;
        $.ajax({
            type: 'post'
            ,async: false
            ,url: 'Echarts_usrAction!serchByCondition'
            ,data: null
            ,dataType: 'json'
            ,success: function(res) {
                var rs = JSON.parse(res.result);
                //console.log(rs);
                if(rs.code == 1) {
                    var data = rs.data[0];
                    var rsStatus = formaterPieStauts(data);
                    pieItems = getPieList(rsStatus);
                }else {
                    pieItems = getPieList([1, 1, 1, 1]);
                }
            }
        });
        //console.log(pieItems);
        return pieItems;
    }
    
    // 将pieStatus绑定到Index.Pie命名空间下
    gl.Index.Pie.pieStatus = pieStatus;
    
    // 根据数组返回
    function getPieList(arr) {
        var pieItems = $('<div class="pie-item-list"></div>');
        for(var i=0; i<arr.length; i++) {
            if(arr[i] == 1) {
                var cla = pieType[i].cla;
                var pieItem = $('<div class="'+cla+' module"></div>');
                pieItems.append(pieItem);
            }
            
        }
        return pieItems;
    }
    
    // 将getPieList绑定到Index.Pie命名空间下
    gl.Index.Pie.getPieList = getPieList;
    
    // 构造更新饼状图参数
    function formaterPieStauts(obj) {
        var rs = [];
        // 遍历pieType的类型
        for(var i=0; i<pieType.length; i++) {
            var num = i+1;
            var key = 'echarts'+num+'_enable';
            rs.push(obj[key]);
        }
        return rs;
    }
    
    // 将getPieList绑定到Index.Pie命名空间下
    gl.Index.Pie.formaterPieStauts = formaterPieStauts;
})(jQuery, window, document, GLOBAL);