2
13693261870
2022-09-16 653761a31dfeb50dd3d007e892d69c90bf0cdafc
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
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" xmlns:layout="http://www.w3.org/1999/xhtml" layout:decorator="MasterPage/Layout.Empty">
<head>
    <link rel="stylesheet" th:href="@{${pubzyWebRoot} + 'zTree/css/metroStyle/metroStyle.css'}" />
    <script th:src="@{${pubzyWebRoot} + 'zTree/js/jquery.ztree.all.min.js'}"></script>
    <meta charset="UTF-8" />
    <style type="text/css">
        .row {
            margin-left: 0;
            margin-right: 0;
        }
 
        .loaddiv {
            height: 92%;
            width: 100%;
            overflow: auto;
            z-index: 2;
            position: absolute;
            top: 35px;
            text-align: center;
            background-color: #ffffff;
            opacity: 0.75;
        }
 
        .form-control {
            padding: 0.3rem !important;
        }
 
        #menuTree_1_switch, #menuTree_1_check, #menuTree_1_a {
            display: none!important;
        }
 
        #menuTree_1_ul {
            padding-left: 0px!important;
        }
 
        .ztree li span.button.chk.checkbox_false_part{
            background-position:-5px -5px;
        }
 
        .ztree li span.button.chk.checkbox_false_part_focus{
            background-position:-5px -5px;
        }
 
        .ztree li span.button.chk.checkbox_true_part{
            background-position:-26px -5px;
        }
 
        .ztree li span.button.chk.checkbox_true_part_focus{
            background-position:-26px -5px;
        }
    </style>
    <script type="text/javascript" th:inline="javascript">
        /*<![CDATA[*/
        var backstageWebRoot = [[${backstageWebRoot}]];
        var userid = [[${userid}]];
        var userIds = [[${userIds}]];
        var unitIds = [[${unitIds}]];
        /*]]>*/
        var zTree;
        /**
         * zTree配置
         */
        var setting = {
            view: {
                selectedMulti: false
            },
            check: {
                enable: true,
                chkStyle: "checkbox"
            },
            data: {
                simpleData: {
                    enable: true
                }
            }
        };
 
        jQuery(function () {
            //加载菜单树
            loadGeRenTree("spellfirst");
        });
 
        //加载个人推荐树
        function loadGeRenTree(type) {
            $.ajax({
                type: "GET",
                url: backstageWebRoot + "api/org/user/queryListOrderByType/" + type + "/" + userid,
                dataType: 'text',
                success: function(r){
                    var data = eval(r);
                    $("#menuTree").show();
                    $("#menuUnitTree").hide();
                    var zNodes = {id: 0, name: "个人推荐", pId: -1, isParent: true, checked: false, children: data};
                    zTree = $.fn.zTree.init($("#menuTree"), setting, zNodes);
                    var node = zTree.getNodes()[0];
                    zTree.selectNode(node);
                    zTree.expandNode(node);
                    //初始化勾选已推荐用户
                    if(userIds != "") {
                        var arr = userIds.split(',');
                        for (var i = 0; i < arr.length; i++) {
                            var nodes = zTree.getNodesByParam("id", arr[i], null);
                            if (nodes.length > 0) {
                                for (var j = 0; j < nodes.length; j++) {
                                    zTree.checkNode(nodes[j], true, true);
                                }
                            }
                        }
                    }
                    hideDiv();
                },
                error:function (e) {
                    console.log(e)
                }
            });
        }
 
        //加载单位推荐树
        function loadUnitTree() {
            $.ajax({
                type: "Get",
                url: backstageWebRoot + "api/org/unit/queryAllList",
                dataType: 'text',
                success: function(r){
                    var data = eval(r);
                    var setting = {
                        data: {
                            simpleData: {
                                enable: true,
                                idKey: "id",
                                pIdKey: "parentid",
                                rootPId: -1,
                            },
                            key: {
                                url:"nourl",
                                name:"name"
                            },
                        },
                        check: {
                            enable: true,
                            chkStyle: "checkbox",
                            chkboxType:{"Y":"","N":""}
                        },
                        callback:{
                            beforeCheck:beforeCheck
                        }
                    };
                    function beforeCheck(treeId,treeNode){
                        console.log(treeId)
                        console.log(treeNode)
                    }
                    $("#menuTree").hide();
                    $("#menuUnitTree").show();
                    zTree = $.fn.zTree.init($("#menuUnitTree"), setting, data);
                    var node = zTree.getNodeByParam("id", 0);
                    zTree.selectNode(node);
                    // var zNodes = {id: 0, name: "单位推荐", pId: -1, isParent: true, checked: false, children: data};
                    // zTree = $.fn.zTree.init($("#menuTree"), setting, zNodes);
                    // var node = zTree.getNodes()[0];
                    // zTree.selectNode(node);
                    // zTree.expandNode(node);
                    //初始化勾选已推荐单位
                    if(unitIds != "") {
                        var arr = unitIds.split(',');
                        for (var i = 0; i < arr.length; i++) {
                            var nodes = zTree.getNodesByParam("id", arr[i], null);
                            if (nodes.length > 0) {
                                for (var j = 0; j < nodes.length; j++) {
                                    zTree.checkNode(nodes[j], true, true);
                                }
                            }
                        }
                    }
                    hideDiv();
                },
                error:function (e) {
                    console.log(e)
                }
            });
        }
 
        //隐藏加载遮罩
        function hideDiv() {
            $("#divonload").hide();
        }
 
        //切换推荐类型
        function changeType(obj) {
            $("#divonload").show();
            if(obj.value == 0) {
                $("#ZSFS").show();//显示展示方式
                $("#ShowType").val("spellfirst");//默认个人方式展示
                loadGeRenTree("spellfirst");
            } else {
                $("#ZSFS").hide();//显示展示方式
                loadUnitTree();
            }
        }
 
        //切换展示方式
        function changeTree(obj) {
            $("#divonload").show();
            loadGeRenTree(obj.value);
        }
        
        //确定
        function clickNodes() {
            var resourceid = $("#resourceid").val();
            var TJLX = $("#TJLX").val();
            var nodes = zTree.getCheckedNodes();
            var idStr = [];
            for(var i = 0; i < nodes.length; i++) {
                if(nodes[i].isParent == false || TJLX == 1) {
                    idStr.push(nodes[i].id);
                }
            }
            if(idStr.length == 0) {
                alert("请选择要推荐的用户或单位!");
            } else {
                $.ajax({
                    url: "/res/resApplyRecommend/ResourceRecommend",
                    data: {resourceid: resourceid, RecommendType: TJLX, idStr: idStr.join("|")},
                    success: function (result) {
                        console.log(result)
                        var data = eval("(" + result + ")");
                        if (data.success) {
                            userIds = data.userIds;
                            unitIds = data.unitIds;
                            alert("推荐成功!");
                            var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                            parent.layer.close(index);
                        } else {
                            alert("推荐失败!错误提示:" + data.msg);
                        }
                    },
                    error: function (e) {
                        alert("推荐失败!错误提示:" + e.message);
                    }
                });
            }
        }
        
        //全选
        function CheckAll() {
            zTree.checkAllNodes(true);
        }
        
        //清除
        function RemoveAll() {
            zTree.checkAllNodes(false);
        }
    </script>
</head>
<body>
<div layout:fragment="content" class="portlet-body form-horizontal form-bordered form-row-stripped">
    <input type="hidden" id="resourceid" th:value="${resourceid}" value="" />
    <div class="row">
        <div style="width: 100%;margin-top: 5px;">
        <div style="width: 50%;float: left;">
            <label style="float:left;width: 80px;text-align: right;line-height: 30px;">推荐类型:</label>
            <div style="margin-left: 80px;">
                <select class="form-control" id="TJLX" style="width:90px;" onchange="changeType(this);">
                    <option value="0" selected>个人推荐</option>
                    <option value="1">单位推荐</option>
                </select>
            </div>
        </div>
        <div style="width: 50%;float: right;" id="ZSFS">
            <label style="float:left;width: 80px;text-align: right;line-height: 30px;">展示方式:</label>
            <div style="line-height: 28px;margin-left: 80px;">
                <select class="form-control" id="ShowType" style="width:90px;" onchange="changeTree(this)">
                    <option value="spellfirst" selected>首字母</option>
                    <option value="unit">单位</option>
                    <option value="role">角色</option>
                </select>
            </div>
        </div>
        </div>
        <div class='my-ztree' style="width: 100%;height:365px !important;overflow:auto;">
            <ul id='menuTree' class='ztree'></ul>
            <ul id='menuUnitTree' class='ztree'></ul>
        </div>
        <div id="divonload" class="loaddiv" style="display:none;">
            <div style="margin-top: 150px;">
                <img src="/image/loading.gif" />
            </div>
        </div>
        <div style="width: 100%;height: 50px;line-height: 50px;text-align: right;padding-right: 10px;">
            <input type="button" value="确定" class="btn btn-primary" onclick="clickNodes()" />
            <input type="button" value="全选" class="btn btn-primary" onclick="CheckAll()" />
            <input type="button" value="清除" class="btn btn-primary" onclick="RemoveAll()" />
        </div>
    </div>
</div>
</body>
</html>