wuxw
2020-02-16 9ba9007d5c1b9eb83ab9407e2b3596d0f2d0ad66
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
(function(vc){
 
    vc.extends({
        data:{
            addPrivilegeInfo:{
                _currentPgId:'',
                _pName:'',
                name:'',
                description:'',
                errorInfo:'',
                _noAddPrivilege:[],
                selectPrivileges:[]
            }
        },
        watch: { // 监视双向绑定的数据数组
            addPrivilegeInfo: {
                handler(){ // 数据数组有变化将触发此函数
                    if(vc.component.addPrivilegeInfo.selectPrivileges.length == vc.component.addPrivilegeInfo._noAddPrivilege.length){
                        document.querySelector('#quan').checked = true;
                    }else {
                        document.querySelector('#quan').checked = false;
                    }
                },
                deep: true // 深度监视
            }
        },
         _initMethod:function(){
 
         },
         _initEvent:function(){
             vc.component.$on('addPrivilege_openPrivilegeModel',function(_params){
                $('#addPrivilegeModel').modal('show');
                vc.component.addPrivilegeInfo._currentPgId = _params.pgId;
                //查询没有添加的权限
                vc.component.listNoAddPrivilege();
            });
        },
        methods:{
            listNoAddPrivilege:function(){
                vc.component.addPrivilegeInfo._noAddPrivilege=[];
                var param = {
                    params:{
                        pgId:vc.component.addPrivilegeInfo._currentPgId,
                        pName:vc.component.addPrivilegeInfo._pName
                    }
                }
                vc.http.get(
                            'addPrivilege',
                            'listNoAddPrivilege',
                             param,
                             function(json,res){
                                //vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
                                if(res.status == 200){
                                    vc.component.addPrivilegeInfo._noAddPrivilege = JSON.parse(json);
                                    return ;
                                }
                                vc.component.addPrivilegeInfo.errorInfo = json;
                             },
                             function(errInfo,error){
                                console.log('请求失败处理');
 
                                vc.component.addPrivilegeInfo.errorInfo = errInfo;
                             });
            },
            addPrivilegeToPrivilegeGroup:function(){
 
                vc.component.addPrivilegeInfo.errorInfo = "";
                var _selectPrivileges = vc.component.addPrivilegeInfo.selectPrivileges;
 
                if(_selectPrivileges.length < 1){
                    vc.toast("请先选择权限");
                    return ;
                }
                var _pIds = [];
                for(var selectIndex = 0;selectIndex < _selectPrivileges.length;selectIndex ++){
                    var _pId = {
                        pId: _selectPrivileges[selectIndex]
                    };
                    _pIds.push(_pId);
                }
                var _objData = {
                    pgId:vc.component.addPrivilegeInfo._currentPgId,
                    pIds:_pIds
                };
                vc.http.post(
                    'addPrivilege',
                    'addPrivilegeToPrivilegeGroup',
                    JSON.stringify(_objData),
                    {
                        emulateJSON:true
                     },
                     function(json,res){
                        //vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
                        if(res.status == 200){
                            //关闭model
                            vc.component.listNoAddPrivilege();
                            $('#addPrivilegeModel').modal('hide');
                            vc.component.$emit('privilege_loadPrivilege',vc.component.addPrivilegeInfo._currentPgId);
                            return ;
                        }
                        vc.component.addPrivilegeInfo.errorInfo = json;
                     },
                     function(errInfo,error){
                        console.log('请求失败处理');
 
                        vc.component.addPrivilegeInfo.errorInfo = errInfo;
                     });
            },
            checkAll:function(e){
                    var checkObj = document.querySelectorAll('.checkItem'); // 获取所有checkbox项
                    if(e.target.checked){ // 判定全选checkbox的勾选状态
                        for(var i=0;i<checkObj.length;i++){
                            if(!checkObj[i].checked){ // 将未勾选的checkbox选项push到绑定数组中
                                vc.component.addPrivilegeInfo.selectPrivileges.push(checkObj[i].value);
                            }
                        }
                    }else { // 如果是去掉全选则清空checkbox选项绑定数组
                        vc.component.addPrivilegeInfo.selectPrivileges = [];
                    }
            }
        }
    });
 
})(window.vc);