mrzcc
2020-03-05 c755c5057d903c7fc69ccbb3ca80ffa8b95cf09d
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
(function(vc){
    vc.extends({
        propTypes: {
            emitListener:vc.propTypes.string,
            emitFunction:vc.propTypes.string
        },
        data:{
            addOrgCommunityInfo:{
                communitys:[],
                communityName:'',
                orgId:'',
                orgName:'',
                selectCommunitys:[],
                index:0,
            }
        },
        watch: { // 监视双向绑定的数据数组
            checkData: {
                handler(){ // 数据数组有变化将触发此函数
                    if(vc.component.addOrgCommunityInfo.selectCommunitys.length == vc.component.addOrgCommunityInfo.communitys.length){
                        document.querySelector('#quan').checked = true;
                    }else {
                        document.querySelector('#quan').checked = false;
                    }
                },
                deep: true // 深度监视
            }
        },
        _initMethod:function(){
        },
        _initEvent:function(){
            vc.on('addOrgCommunity','openAddOrgCommunityModal',function(_param){
                vc.component._refreshChooseOrgInfo();
                $('#addOrgCommunityModel').modal('show');
                vc.copyObject(_param,vc.component.addOrgCommunityInfo);
                vc.component._loadAllCommunityInfo(1,10,'');
            });
 
            vc.on('addOrgCommunity','paginationPlus', 'page_event', function (_currentPage) {
                vc.component._listOrgCommunitys(_currentPage, DEFAULT_ROWS);
            });
 
            vc.on('resourceStoreSelectModule', 'onIndex', function(_index){
                vc.component.viewStaffInfo.index = _index;
            });
        },
        methods:{
            _loadAllCommunityInfo:function(_page,_row,_name){
                var param = {
                    params:{
                        page:_page,
                        row:_row,
                        name:_name,
                        orgId:vc.component.addOrgCommunityInfo.orgId
                    }
                };
 
                //发送get请求
                vc.http.get('addOrgCommunity',
                    'list',
                    param,
                    function(json){
                        var _communityInfo = JSON.parse(json);
                        vc.component.addOrgCommunityInfo.communitys = _communityInfo.communitys;
                        vc.emit('addOrgCommunity','paginationPlus', 'init', {
                            total: _communityInfo.records,
                            currentPage: _page
                        });
                    },function(){
                        console.log('请求失败处理');
                    }
                );
            },
            addOrgCommunity:function(_org){
                var _selectCommunitys = vc.component.addOrgCommunityInfo.selectCommunitys;
                var _tmpCommunitys = vc.component.addOrgCommunityInfo.communitys;
                if(_selectCommunitys.length <1){
                    vc.toast("请选择隶属小区");
                    return ;
                }
                var _communitys = [];
                for(var _selectIndex = 0 ;_selectIndex <_selectCommunitys.length ;_selectIndex ++){
                    for(var _communityIndex =0; _communityIndex < _tmpCommunitys.length;_communityIndex++){
                        if(_selectCommunitys[_selectIndex] == _tmpCommunitys[_communityIndex].communityId){
                            _communitys.push({
                                communityId:_tmpCommunitys[_communityIndex].communityId,
                                communityName:_tmpCommunitys[_communityIndex].name
                            });
                        }
                    }
                }
                var _objData = {
                    orgId:vc.component.addOrgCommunityInfo.orgId,
                    orgName:vc.component.addOrgCommunityInfo.orgName,
                    communitys:_communitys
                }
                vc.http.post('addOrgCommunity',
                    'save',
                    JSON.stringify(_objData),
                    {
                        emulateJSON: true
                    },
                    function(json,res){
                        $('#addOrgCommunityModel').modal('hide');
                        if(res.status == 200){
                            vc.emit($props.emitListener,$props.emitFunction,{
                            });
                            return ;
                        }
                        vc.toast(json);
                    },function(){
                        console.log('请求失败处理');
                    }
                );
                $('#addOrgCommunityModel').modal('hide');
            },
            queryCommunitys:function(){
                vc.component._loadAllCommunityInfo(1,10,vc.component.addOrgCommunityInfo.communityName);
            },
            _refreshChooseOrgInfo:function(){
                vc.component.addOrgCommunityInfo={
                    communitys:[],
                    communityName:'',
                    orgId:'',
                    orgName:'',
                    selectCommunitys:[]
                };
            },
            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.addOrgCommunityInfo.selectCommunitys.push(checkObj[i].value);
                        }
                    }
                }else { // 如果是去掉全选则清空checkbox选项绑定数组
                    vc.component.addOrgCommunityInfo.selectCommunitys = [];
                }
            }
        }
 
    });
})(window.vc);