mrzcc
2020-02-17 e64197421cf28099935f71f193989a3394d47fe0
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
/**
 入驻小区
 **/
(function (vc) {
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROWS = 10;
    var ALL_ROWS = 100;
    vc.extends({
        data: {
            orgManageInfo: {
                orgs: [],
                total: 0,
                records: 1,
                currentSelectOrgId:"-1",
                moreCondition: false,
                showBelongCommunity:false,
                orgName: '',
                headOrg: [],
                branchOrg: [],
                orgTree: [],
                currentBelongCommunityId:'',
                conditions: {
                    orgId: '',
                    orgName: '',
                    communityId: '',
                    orgLevel: '',
                    parentOrgId: '',
                }
            }
        },
        watch: {
            "orgManageInfo.conditions.headOrgId": {//深度监听,可监听到对象、数组的变化
                handler(val, oldVal) {
                    vc.component._getOrgsByOrgLevel(DEFAULT_PAGE, DEFAULT_ROWS, 2, val);
 
                    vc.component.orgManageInfo.conditions.parentOrgId = val;
 
                    vc.component.orgManageInfo.conditions.branchOrgId = '';
 
                    vc.component._listOrgs(DEFAULT_PAGE, DEFAULT_ROWS);
 
                },
                deep: true
            },
            "orgManageInfo.conditions.branchOrgId": {//深度监听,可监听到对象、数组的变化
                handler(val, oldVal) {
                    if (val == '') {
                        vc.component.orgManageInfo.conditions.parentOrgId = vc.component.orgManageInfo.conditions.headOrgId;
                    } else {
                        vc.component.orgManageInfo.conditions.parentOrgId = val;
                    }
                    vc.component._listOrgs(DEFAULT_PAGE, DEFAULT_ROWS);
                },
                deep: true
            }
        },
        _initMethod: function () {
            //只查 查询总公司级组织
            vc.component.orgManageInfo.orgTree = [];
            vc.component._listOrgTrees(vc.component.orgManageInfo.orgTree, '1', '', function () {
                vc.component._loadBranchOrgTrees();
            });
            vc.component._getOrgsByOrgLevel(DEFAULT_PAGE, DEFAULT_ROWS, 1, '');
 
 
        },
        _initEvent: function () {
 
            vc.on('orgManage', 'listOrg', function (_param) {
                //vc.copyObject(_param, vc.component.orgManageInfo.conditions);
                vc.component._listOrgs(DEFAULT_PAGE, DEFAULT_ROWS);
                vc.component.orgManageInfo.orgTree = [];
                vc.component._listOrgTrees(vc.component.orgManageInfo.orgTree, '1', '', function () {
                    vc.component._loadBranchOrgTrees();
                });
            });
            vc.on('pagination', 'page_event', function (_currentPage) {
                vc.component._listOrgs(_currentPage, DEFAULT_ROWS);
            });
            vc.on('orgManage','onBack',function(_param){
                 vc.component.orgManageInfo.showBelongCommunity = false;
            })
 
        },
        methods: {
            _refreshOrgTree: function () {
                $('#orgTree').treeview({
                    data: vc.component.orgManageInfo.orgTree,
                    selectedBackColor: '#1ab394'
                });
                $('#orgTree').on('nodeSelected', function (event, data) {
                    console.log(event,data);
                    vc.component.orgManageInfo.currentSelectOrgId = data.orgId;
                    vc.component.orgManageInfo.conditions.orgLevel = (parseInt(data.orgLevel) + 1);
                    vc.component.orgManageInfo.conditions.parentOrgId = data.orgId;
                    vc.component.orgManageInfo.currentBelongCommunityId = data.belongCommunityId;
                    vc.component._listOrgs(DEFAULT_PAGE, DEFAULT_ROWS);
                });
//                if(vc.component.orgManageInfo.currentSelectOrgId == '-1'){
//                    console.log('是否进入');
//                    $('#orgTree').treeview("selectNode", [0]);
//                }
            },
            _loadBranchOrgTrees: function () {
                //默认查询分公司组织信息
                vc.component._listOrgTrees(vc.component.orgManageInfo.orgTree[0].nodes,
                    '2',
                    vc.component.orgManageInfo.orgTree[0].orgId,
                    function (_tmpOrgs) {
                        vc.component._refreshOrgTree();
                    });
            },
            _listOrgTrees: function (_nodes, _orgLevel, _parentOrgId, _callback) {
                var param = {
                    params: {
                        page: DEFAULT_PAGE,
                        row: ALL_ROWS,
                        orgLevel: _orgLevel,
                        parentOrgId: _parentOrgId
                    }
                };
                //发送get请求
                vc.http.get('orgManage',
                    'list',
                    param,
                    function (json, res) {
                        var _tmpOrgs = JSON.parse(json).orgs;
                        _tmpOrgs.forEach(function (_item) {
                            var _selected = false;
                            var _currentSelectOrgId = vc.component.orgManageInfo.currentSelectOrgId;
                            if(_currentSelectOrgId == '-1' && _orgLevel == 1){
                                _selected = true;
                                vc.component.orgManageInfo.currentSelectOrgId = _item.orgId;
                                vc.component.orgManageInfo.conditions.orgLevel = (parseInt(_item.orgLevel) + 1);
                                vc.component.orgManageInfo.conditions.parentOrgId = _item.orgId;
                                vc.component.orgManageInfo.currentBelongCommunityId = _item.belongCommunityId;
                                vc.component._listOrgs(DEFAULT_PAGE, DEFAULT_ROWS);
                            }else if(_item.orgId == vc.component.orgManageInfo.currentSelectOrgId){
                                _selected = true;
                            }
                            _nodes.push({
                                orgId: _item.orgId,
                                orgLevel: _orgLevel,
                                text: _item.orgLevelName + '|' + _item.orgName,
                                belongCommunityId:_item.belongCommunityId,
                                href: function (_item) {
                                },
                                state:{
                                    selected:_selected
                                },
                                tags: [0],
                                nodes: []
                            });
                            _callback();
                        });
                    }, function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _listOrgs: function (_page, _rows) {
 
                vc.component.orgManageInfo.conditions.page = _page;
                vc.component.orgManageInfo.conditions.row = _rows;
                var param = {
                    params: vc.component.orgManageInfo.conditions
                };
 
                //发送get请求
                vc.http.get('orgManage',
                    'list',
                    param,
                    function (json, res) {
                        var _orgManageInfo = JSON.parse(json);
                        vc.component.orgManageInfo.total = _orgManageInfo.total;
                        vc.component.orgManageInfo.records = _orgManageInfo.records;
                        vc.component.orgManageInfo.orgs = _orgManageInfo.orgs;
                        vc.emit('pagination', 'init', {
                            total: vc.component.orgManageInfo.records,
                            currentPage: _page
                        });
                    }, function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _openAddOrgModal: function () {
                vc.emit('addOrg', 'openAddOrgModal', {
                    parentOrgId: vc.component.orgManageInfo.conditions.parentOrgId,
                    orgLevel: vc.component.orgManageInfo.conditions.orgLevel,
                    belongCommunityId: vc.component.orgManageInfo.currentBelongCommunityId
                });
            },
            _openEditOrgModel: function (_org) {
                vc.emit('editOrg', 'openEditOrgModal', _org);
            },
            _openDeleteOrgModel: function (_org) {
                vc.emit('deleteOrg', 'openDeleteOrgModal', _org);
            },
            _openBeyondCommunity:function(_org){
                vc.component.orgManageInfo.showBelongCommunity = true;
                vc.emit('orgCommunityManageInfo', 'openOrgCommunity',_org);
            },
            _queryOrgMethod: function () {
                vc.component._listOrgs(DEFAULT_PAGE, DEFAULT_ROWS);
 
            },
            _moreCondition: function () {
                if (vc.component.orgManageInfo.moreCondition) {
                    vc.component.orgManageInfo.moreCondition = false;
                } else {
                    vc.component.orgManageInfo.moreCondition = true;
                }
            },
 
            _getOrgsByOrgLevel: function (_page, _rows, _orgLevel, _parentOrgId) {
 
                var param = {
                    params: {
                        page: _page,
                        row: _rows,
                        orgLevel: _orgLevel,
                        parentOrgId: _parentOrgId
                    }
                };
 
                //发送get请求
                vc.http.get('orgManage',
                    'list',
                    param,
                    function (json, res) {
                        var _orgManageInfo = JSON.parse(json);
                        if (_orgLevel == 1) {
                            vc.component.orgManageInfo.headOrg = _orgManageInfo.orgs;
                        } else {
                            vc.component.orgManageInfo.branchOrg = _orgManageInfo.orgs;
                        }
                    }, function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            }
 
 
        }
    });
})(window.vc);