<div class="panel-content">
    <div class="panel-title fluid">
        <div class="title-main">
            <% for (let menu of userMenu) { %>
            <% if (menu.title === secondMenu[action].title) { %>
            <%= menu.title %>
            <% } else { %>
            <a href="<%= menu.url %>" class="btn btn-primary btn-link" style="margin-left: 0;margin-right: 12px"><%= menu.title %></a>
            <% } %>
            <% } %>
            <!--<h2><%= secondMenu[action].title %><a href="/user/testUser" class="btn btn-primary btn-link">测试用户</a></h2>-->
        </div>
    </div>
    <div class="content-wrap">
        <div class="c-header">
            <form class="form-inline" method="get" action="" id="searchUser">
                <!--最近使用定额-->
                <div class="btn-group">
                    <button type="button" class="btn btn-default dropdown-toggle btn-sm" data-toggle="dropdown"
                            aria-haspopup="true" aria-expanded="false">
                       最近使用费用定额：<lable><%= compilationMap[filter.latestUsed] === undefined ? '所有' : compilationMap[filter.latestUsed].name %></lable>  <span class="caret"></span>
                    </button>
                    <ul class="dropdown-menu selector">
                        <li><a  data-value="">所有</a></li>
                        <% for(let compilation of compilationList){ %>
                        <li><a  data-value="<%= compilation._id.toString()%>"><%= compilation.name %></a></li>
                        <% } %>
                    </ul>
                    <input type="hidden" name="latestUsed" value="<%= filter.latestUsed%>" />
                </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">
                        已升级费用定额：<lable><%= compilationMap[filter.upGrade] === undefined ? '所有' : compilationMap[filter.upGrade].name %></lable>  <span class="caret"></span>
                    </button>
                    <ul class="dropdown-menu selector">
                        <li><a  data-value="">所有</a></li>
                        <% for(let compilation of compilationList){ %>
                        <li><a  data-value="<%= compilation._id.toString()%>"><%= compilation.name %></a></li>
                        <% } %>
                    </ul>
                    <input type="hidden" name="upGrade" value="<%= filter.upGrade%>" />
                </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">
                        最新注册：<lable><%= filter.regtimeMsg === undefined ? '所有' : filter.regtimeMsg %></lable><span class="caret"></span>
                    </button>
                    <ul class="dropdown-menu selector">
                        <li><a  data-value="0">所有</a></li>
                        <li><a  data-value="1">最近24小时</a></li>
                        <li><a  data-value="2">最近3天</a></li>
                        <li><a  data-value="3">最近7天</a></li>
                        <li><a  data-value="4">最近30天</a></li>
                    </ul>
                    <input type="hidden" name="regtime" value="<%= filter.regtime%>" />
                </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">
                        最近登录：<lable><%= filter.loginMsg === undefined ? '所有' : filter.loginMsg %></lable><span class="caret"></span>
                    </button>
                    <ul class="dropdown-menu selector">
                        <li><a  data-value="0">所有</a></li>
                        <li><a  data-value="1">最近24小时</a></li>
                        <li><a  data-value="2">最近3天</a></li>
                        <li><a  data-value="3">最近7天</a></li>
                        <li><a  data-value="4">最近30天</a></li>
                    </ul>
                    <input type="hidden" name="loginTime" value="<%= filter.loginTime%>" />
                </div>
                <!--结果-->
                <div class="btn-group">
                    &nbsp;共 <%= total %> 条结果
                </div>
                <!--搜索-->
                <div class="btn-group pull-right">
                    <div class="input-group">
                        <input type="text" name="keyword" class="form-control input-sm" value="<%= filter.keyword === undefined ? '' : filter.keyword %>" placeholder="手机/邮箱/姓名/公司">
                        <span class="input-group-btn">
                        <button class="btn btn-default btn-sm" type="submit">
                            <i class="glyphicon glyphicon-search"></i>
                        </button>
                    </span>
                    </div>
                </div>
            </form>
        </div>
        <div class="c-body">
            <table class="table">
                <thead>
                <tr>
                    <th width="350">注册手机/邮箱</th>
                    <th>姓名</th>
                    <th>企业名称</th>
                    <th>企业地区</th>
                    <th>最近使用费用定额</th>
                    <th>在线时长(<%= filter.loginMsg === undefined ? '所有' : filter.loginMsg %>)</th>
                    <th width="180">注册时间 / 最近登录</th>
                    <% if (manager.superAdmin == 1) { %>
                    <th>操作</th>
                    <% }%>
                    <!--<th>详细</th>-->
                </tr>
                </thead>
                <tbody>
                <% userList.forEach(function (user){ %>
                <tr>
                    <td><%= user.mobile %><br><%= user.email %></td>
                    <td><%= user.real_name %></td>
                    <td><%= user.company %></td>
                    <td><%= model.province[user.province] %></td>
                    <td><%= compilationMap[user.latest_used]?compilationMap[user.latest_used].name:""%></td>
                    <td><a onclick="getOnlineInfo('<%= user._doc.filter%>')" href="#time-detail" data-toggle="modal" data-target="#time-detail"><%= user._doc.online_times %></a></td>
                    <td><%= moment(user.create_time).format('YYYY-MM-DD HH:mm:ss') %><br><%= user.latest_login?moment(user.latest_login).format('YYYY-MM-DD HH:mm:ss'):"" %></td>
                    <% if (manager.superAdmin == 1) { %>
                    <td>
                        <a onclick='deleteUser("<%= user._id.toString()%>")' data-toggle="modal" data-target="#delUser" class="btn text-danger" style="padding: 0px">删除</a>
                        <a href="#update" data-toggle="modal" data-target="#update" class="btn" onclick='getUserUpgradeInfo("<%= user._id.toString()%>")'>升级</a>
                    </td>
                    <% }%>
                    <!--<td><a role="button" data-toggle="modal" data-target="#view" onclick='getUserInfo("<%= user._id.toString()%>")'>详细</a></td>-->
                    <!--<td><a href="#update" data-toggle="modal" data-target="#update" onclick='getUserUpgradeInfo("<%= user._id.toString()%>")'>升级</a></td>-->
                </tr>
                <% }) %>
                </tbody>
            </table>
            <nav aria-label="Page navigation">
                <%include ../layout/page.html %>
            </nav>
        </div>
    </div>
</div>


<!-- 弹窗查看用户详情-->
<div class="modal fade" id="view" 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">
                <table class="table table-bordered">
                    <tbody id="userInfoTable">
                    </tbody>
                </table>
            </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="update" 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">
                <table class="table table-bordered">
                    <tbody id="upgrade_table">
                    </tbody>
                </table>
            </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="delUser" data-backdrop="static" style="display: none;" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">删除确认</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">×</span>
                </button>
            </div>
            <div class="modal-body">
                <h5 class="text-danger">删除用户的同时会删除项目数据和用户补充人材库、定额库等数据，且无法恢复，确认是否删除？</h5>
                <input type="hidden" id="userID">
                <input type="hidden" id="delCount">
            </div>
            <div class="modal-footer">
                <a id="deleteConfirm" href="javascript:void(0);" class="btn btn-danger" >确认</a>
                <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
            </div>
        </div>
    </div>
</div>

<!-- 弹窗在线时长-->
<div class="modal fade" id="time-detail" 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">
                <table class="table table-bordered" id = 'time-detail-table'>
                    <tr><th>日期/时间</th><th>在线时长</th></tr>
                    <!--<tr><th>日期/时间</th><th>在线时长</th></tr>
                    <tr><td>04-10</td><td>2小时10分钟</td></tr>
                    <tr><td>04-09</td><td>1小时7分钟</td></tr>
                    <tr><td>04-08</td><td>2小时35分钟</td></tr>-->
                </table>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
    let compilationList = JSON.parse('<%- compilationString %>');
    let adminName = '<%- adminName %>';
</script>
<script type="text/javascript" src="/web/users/js/user.js"></script>
