<%include ../layout/second_menu.html %>
<div class="panel-content">
    <div class="panel-title">
        <div class="title-main">
            <h2><%= secondMenu[action].title %></h2>
        </div>
    </div>
    <div class="content-wrap">
        <div class="c-header">
            <!--办事处筛选-->
            <div class="btn-group">
                <button type="button" class="btn btn-default dropdown-toggle btn-sm" data-toggle="dropdown"
                        aria-haspopup="true" aria-expanded="false">
                    办事处：<span><%= filter.office === undefined ? '所有' : filter.officeName %></span> <span class="caret"></span>
                </button>
                <ul class="dropdown-menu selector">
                    <li><a href="javascript:void(0);" data-value="all">所有</a></li>
                    <% for (let category of categoryList) { %>
                    <li><a href="javascript:void(0);" data-value="<%= category.id %>"><%= category.name %></a></li>
                    <% } %>
                </ul>
                <input type="hidden" id="office_select" value="<%= filter.office %>" />
            </div>
            <div class="btn-group">
                <button type="button" class="btn btn-default dropdown-toggle btn-sm" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                    权限组：<span><%= filter.permission === undefined ? '所有' : (filter.permission === '0' ? '未分配' : filter.permissionGroupName) %></span> <span class="caret"></span>
                </button>
                <ul class="dropdown-menu selector">
                    <li><a href="javascript:void(0);" data-value="all">所有</a></li>
                    <li><a href="javascript:void(0);" data-value="0">未分配</a></li>
                    <% for (let pg of permissionGroupList) { %>
                    <li><a href="javascript:void(0);" data-value="<%= pg._id %>"><%= pg.name %></a></li>
                    <% } %>
                </ul>
                <input type="hidden" id="permission_select" value="<%= filter.permission %>" />
            </div>
        </div>
        <div class="c-body">
            <table class="table">
                <thead>
                <tr>
                    <th>姓名(CLD)</th>
                    <th>办事处</th>
                    <th>权限组</th>
                    <th>状态</th>
                    <th width="100">操作</th>
                </tr>
                </thead>
                <tbody>
                <% managerList.forEach(function(manager) { %>
                <tr>
                    <td><%= manager.username %></td>
                    <td><%= manager.officeName %></td>
                    <td><a href="#updatea" class="edit_group" data-id="<%= manager._id %>" data-name="<%= manager.permissionName %>" data-permission="<%= manager.permission %>" data-toggle="modal" data-target="#group"><% if (manager.permission !== '') { %><%= manager.permissionName %><% } else { %>未分配<% } %></a></td>
                    <% if (manager.can_login === 1) { %>
                    <td>正常</td>
                    <% } else { %>
                    <td class="text-danger"><i class="glyphicon glyphicon-minus-sign"></i> 停用</td>
                    <% } %>
                    <td><% if (manager.can_login === 1) { %><a href="/manager/modify/<%= manager._id %>/0" class="text-danger">停用</a><% } else { %><a href="/manager/modify/<%= manager._id %>/1" class="text-success">启用</a><% } %></td>
                </tr>
                <% }) %>
                </tbody>
            </table>
            <nav aria-label="Page navigation">
                <%include ../layout/page.html %>
            </nav>
        </div>
    </div>
</div>
<script type="text/javascript">
    let permissionGroupList = <%- permissionGroupList2 %>;
</script>
<script type="text/javascript" src="/web/users/js/manager.js"></script>
<div class="modal fade" id="edit-account" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">编辑账号</h4>
            </div>
            <div class="modal-body">
                <div class="form-group">
                    <label>权限</label>
                    <div class="checkbox">
                        <label>
                            <input type="checkbox" name="permission[]" data-permission="user"> 用户管理
                        </label>&nbsp;
                        <label>
                            <input type="checkbox" name="permission[]" data-permission="notify"> 通知管理
                        </label>&nbsp;
                        <label>
                            <input type="checkbox" name="permission[]" data-permission="stdBillsmain"> 清单规则编辑器
                        </label>&nbsp;
                        <label>
                            <input type="checkbox" name="permission[]" data-permission="rationRepository"> 定额编辑器
                        </label>&nbsp;
                        <label>
                            <input type="checkbox" name="permission[]" data-permission="report"> 报表模板
                        </label>
                    </div>
                </div>
                <div class="form-group">
                    <label>禁止登录</label>
                    <div class="checkbox">
                        <label>
                            <input type="checkbox" name="can_login"> 是
                        </label>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" id="save-manager">确定</button>
            </div>
        </div>
    </div>
</div>
<!-- 更新账号 -->
<div class="modal fade" id="updatea" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">CLD账号更新成功</h4>
            </div>
            <div class="modal-body">
                <p>更新了2个账号：张三、王五</p>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">好的</button>
            </div>
        </div>
    </div>
</div>
<!-- 权限组 -->
<div class="modal fade" id="group" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel2">权限组：<span id="group_name">销售权限</span></h4>
            </div>
            <form method="post" action="/manager/group/save">
            <div class="modal-body">
                <p>该组包含以下权限：</p>
                <p id="group_permission_name">用户管理,通知管理,工具,后台管理</p>
                <div class="form-group">
                    <label class="title">更换组</label>
                    <input type="hidden" value="" id="manager_id" name="manager_id">
                    <select class="form-control" name="permission" id="group_permission">
                        <option value="0">未分配</option>
                        <% for (let pg of permissionGroupList) { %>
                        <option value="<%= pg._id %>"><%= pg.name %></option>
                        <% } %>
                    </select>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="submit" class="btn btn-primary">确认修改</button>
            </div>
            </form>
        </div>
    </div>
</div>