username@email.com
2021-06-03 904fb460b9359fe92e00ce25804d96c8a52bb513
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
@using DTO;
@{
    ViewBag.Title = "Search";
    Layout = "~/Views/Shared/_Layout_Content.cshtml";
    var listRole = ViewBag.listRole == null ? new List<PltRoleDTO>() : (List<PltRoleDTO>)ViewBag.listRole;//获取所有角色
    var listType = ViewBag.listType == null ? new List<CodeDataEntity>() : (List<CodeDataEntity>)ViewBag.listType;//获取人员类型
    var dicTypeUser = ViewBag.dicTypeUser == null ? new Dictionary<string, List<PltUserDTO>>() : (Dictionary<string, List<PltUserDTO>>)ViewBag.dicTypeUser;//获取所有人员类型相关的人员列表
    var dicUserRole = ViewBag.dicUserRole == null ? new Dictionary<string, List<string>>() : (Dictionary<string, List<string>>)ViewBag.dicUserRole;//获取所有角色相关人员
}
<link href="~/css/font-awesome.min.css" rel="stylesheet">
<link href="~/css/plugins/iCheck/custom.css" rel="stylesheet">
<link href="~/css/animate.min.css" rel="stylesheet">
<link href="~/css/style.min.css" rel="stylesheet">
<style>
    #add {
        margin-left: 30%;
    }
 
    .ibox-title {
        margin-top: 0;
    }
</style>
<div style="width:20%;height:100%;float:left;">
    <div id="tree">
        <ul class="list-group rolesearch" style="margin-bottom:0px;">
            <li class="list-group-item" style="font-weight: bold;text-align: center;">角色列表</li>
            <li class="list-group-item">
                <div class="row">
                    <div class="col-lg-12">
                        <div class="input-group" style="width:100%">
                            <input type="text" class="form-control" placeholder="检索角色名称" id="rolesearch">
                            <!-- /btn-group -->
                        </div>
                    </div>
                </div>
            </li>
        </ul>
        <ul class="list-group" id="listrole" style="overflow-y:scroll;">
            @foreach (var item in listRole)
            {
                <li class="list-group-item node-tree" data-roleid="@item.Id" data-name="@item.RoleName" style="cursor:pointer;" data-nodeid="0">
                    <span class="icon"><i class="glyphicon glyphicon-globe"></i></span>@item.RoleName
                </li>
            }
 
        </ul>
    </div>
</div>
<div style="width:80%;height:100%;float:right;background-color:black;">
    <div class="ibox-title">
        <div class="row">
            <div class="col-sm-3 col-md-3" style="padding-left: 40px; padding-top:6px;">
                <div class="allchk">
                    <label>
                        <div class="icheckbox_square-green" style="position: relative;">
                            <input style="position: absolute; opacity: 0;" type="checkbox" value="">
                            <ins class="iCheck-helper" style="background: rgb(255, 255, 255); margin: 0px; padding: 0px; border: 0px; border-image: none; left: 0%; top: 0%; width: 100%; height: 100%; display: block; position: absolute; opacity: 0;"></ins>
                        </div> <i></i> 全选
                    </label>
                </div>
            </div>
            <div class="col-sm-9" style="text-align:center;">
                <div class="col-sm-8">
                    <h3>人员列表</h3>
                </div>
                <div class="col-sm-4">
                    <div class="input-group">
                        <input type="text" class="form-control" placeholder="请输入姓名" id="usersearch">
                        <!-- /btn-group -->
                    </div>
                </div>
 
            </div>
        </div>
    </div>
    <div id="userlist" class="ibox-content" style="overflow-y:scroll;">
        <div class="row">
            @foreach (var item in listType)
            {
                <div class="col-sm-12 col-md-12">
                    <div class="checkbox i-checks parentchk" data-pageid="@item.CodeSn">
                        <label style="font-weight:bold;">
                            <div class="icheckbox_square-green" data-pageid="@item.CodeSn" style="position: relative;">
                                <input style="position: absolute; opacity: 0;" type="checkbox" value="">
                                <ins class="iCheck-helper" style="background: rgb(255, 255, 255); margin: 0px; padding: 0px; border: 0px; border-image: none; left: 0%; top: 0%; width: 100%; height: 100%; display: block; position: absolute; opacity: 0;"></ins>
                            </div> <i></i> @item.Comments
                        </label>
                    </div>
                </div>
 
                if (dicTypeUser.ContainsKey(item.CodeSn) && dicTypeUser[item.CodeSn].Count > 0)
                {
                    foreach (var mUser in dicTypeUser[item.CodeSn])
                    {
                        <div class="col-sm-3 col-md-3">
                            <div class="checkbox i-checks user">
                                <label>
                                    <div class="icheckbox_square-green" data-pageid="@mUser.Id" data-parentid="@mUser.UserType" style="position: relative;">
                                        <input style="position: absolute; opacity: 0;" type="checkbox" value="">
                                        <ins class="iCheck-helper" style="background: rgb(255, 255, 255); margin: 0px; padding: 0px; border: 0px; border-image: none; left: 0%; top: 0%; width: 100%; height: 100%; display: block; position: absolute; opacity: 0;"></ins>
                                    </div> <i></i><span class="uname">@mUser.UserName</span>
                                </label>
                            </div>
                        </div>
                    }
                }
            }
        </div>
    </div>
</div>
<div class="ibox-content" id="top" style="z-index:100; position:fixed;height:50px;left:0px; width:100%;bottom:0;text-align: right; padding-top:8px;">
    <div class="" style="float:right;" data-bootstro-width="500px" data-bootstro-content="功能按钮:“停用”,“保存”,“新增”等操作">
 
        <a style=" " class="btn btn-success" onclick="SaveUserRole()">
            <i class="glyphicon glyphicon-ok"></i>&nbsp;&nbsp;<span class="bold">保存设置</span>
        </a>
    </div>
</div>
<script>
    var sJson = '@Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(dicUserRole))';
    var dicUserRole = eval('(' + sJson + ')');
    $(function () {
        $('#userlist').css('height', document.body.clientHeight - 85);
        $('#listrole').css('height', document.body.clientHeight - $('.rolesearch').height()-50);
        $('.allchk').bind('click', function () {
            if ($(this).find('.icheckbox_square-green').hasClass('checked')) {
                $(this).find('.icheckbox_square-green').removeClass('checked');
                $('.i-checks .icheckbox_square-green').removeClass('checked');
            }
            else {
                $(this).find('.icheckbox_square-green').addClass('checked');
                $('.i-checks .icheckbox_square-green').addClass('checked');
            }
            return false;
        });
 
 
        $('.parentchk').bind('click', function () {
            $(this).find('.icheckbox_square-green').toggleClass('checked');
            var nparentid = $(this).attr('data-pageid');
            if ($(this).find('.icheckbox_square-green').hasClass('checked')) {
                $('div[data-parentid="' + nparentid + '"]').addClass('checked');
            }
            else {
                $('div[data-parentid="' + nparentid + '"]').removeClass('checked');
            }
            return false;
        });
 
        $('.user').bind('click', function () {
            $(this).find('.icheckbox_square-green').toggleClass('checked');
            var nparentid = $(this).find('.icheckbox_square-green').attr('data-parentid');
            if (nparentid && $(this).find('.icheckbox_square-green').hasClass('checked')) {
                $('.parentchk').find('div[data-pageid="' + nparentid + '"]').addClass('checked');
            }
            return false;
        });
 
        $('#usersearch').bind('keyup', function () {
            var sname = $.trim($('#usersearch').val());
            $.each($('.user'), function (i, r) {
                if (sname == '')
                {
                    $(this).parent().show();
                }
                else
                {
                    var sn = $.trim($(this).find('.uname').text());
                    if (sn.indexOf(sname) >= 0) {
                        $(this).parent().show();
                    }
                    else {
                        var n = $(this).find('.checked').attr('data-pageid');
                        if (n && n != undefined && n > 0) {
                            $(this).parent().show();
                        }
                        else {
                            $(this).parent().hide();
                        }
                    }
                }
            });
        });
 
        $('.node-tree').bind('click', function () {
            var nRoleID = $(this).attr('data-roleid');
            var aryUserRole = dicUserRole[nRoleID];
            $('.icheckbox_square-green').removeClass('checked');
            if (aryUserRole != null && aryUserRole.length > 0) {
                $.each(aryUserRole, function (i, r) {
                    $('.user').find('.icheckbox_square-green[data-pageid="' + r + '"]').addClass('checked');
                    var nparentid = $('.user').find('.icheckbox_square-green[data-pageid="' + r + '"]').attr('data-parentid');
                    if (nparentid && $('.user').find('.icheckbox_square-green[data-pageid="' + r + '"]').hasClass('checked')) {
                        $('.parentchk').find('div[data-pageid="' + nparentid + '"]').addClass('checked');
                    }
                });
            }
            $('.node-tree').removeClass('text-navy');
            $(this).addClass('text-navy');
        });
 
        $('#rolesearch').bind('keyup', function () {
            var sRoleName = $.trim($(this).val());
            if (sRoleName == '') {
                $('.node-tree').show();
            }
            else {
                $('.node-tree').each(function () {
                    var sName = $(this).attr('data-name');
                    if (sName.indexOf(sRoleName) != -1) {
                        $(this).show();
                    }
                    else {
                        $(this).hide();
                    }
                });
            }
        });
    });
 
    var SaveUserRole = function () {
        var nRoleID = $('#tree .text-navy').attr('data-roleid');
        var aryUserId = [];
        $('.user').find('.checked').each(function () {
            var nPageid = $(this).attr('data-pageid');
            aryUserId.push(nPageid);
        });
        var error = "";
        if (aryUserId.length == 0) {
            toastr.warning("请选择人员");
            return;
        }
        if (nRoleID == undefined || parseInt(nRoleID) == 0) {
            toastr.warning("请选择角色");
            return;
        }
 
        var mUserRole = {
            roleid: nRoleID,
            usersid: aryUserId.join(',')
        };
        $.ajax({
            url: "/PltUserRole/Save",
            data: mUserRole,
            dataType: 'json',
            type: 'Post',
            success: function (data) {
                if (data.Result) {
                    dicUserRole[nRoleID] = aryUserId;
                    toastr.success("保存成功");
                }
                else {
                    toastr.warning(data.Message);
                }
            },
            error: function () {
 
            },
            complete: function () {
 
            }
        });
 
    }
</script>