<!DOCTYPE html>
<html lang="en">
<head>
<%include("/common/_head.html"){}%>
    <title>黑名单管理 -飞趣</title>
<style>
</style>
</head>
<body>
<%
var user = c.currentUser(request, servlet.response);
var isLogin = false;
if(user != null){
isLogin=true;
}
include("/common/_headwithlogin.html",{user:user,isLogin:isLogin}){}
%>
<div class="layui-container fly-marginTop topToFix c-user-main">
    <%include("/common/_user_menu.html",{user:user}){}%>
        <div class="c-panel fly-panel-user detail-box">
            <div class="layui-row layui-col-space20">
                <div class="layui-col-md12">
                    <div class="layui-tab">
                        <ul class="layui-tab-title">
                            <li class="layui-this">Banner管理</li>
                            <li>黑名单管理</li>
                            <li>访问IP管理</li>
                        </ul>
                        <div class="layui-tab-content">
                            <div class="layui-tab-item layui-show">
                                <form class="layui-form layui-form-pane" action="" method="post">
                                    <input type="hidden" name="id" value="-1">
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">图片标题</label>
                                        <div class="layui-input-block">
                                            <input type="text" name="title" required  lay-verify="required" placeholder="请输入要加入banner的图片标题" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">图片地址</label>
                                        <div class="layui-input-block">
                                            <input type="text" name="imgUrl" required  lay-verify="required" placeholder="请输入要加入banner的图片地址" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">banner的跳转地址</label>
                                        <div class="layui-input-block">
                                            <input type="text" name="href" required  lay-verify="required" placeholder="请输入banner的跳转地址" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <div class="layui-input-block">
                                            <button class="layui-btn" alert="true" lay-submit lay-filter="bannerForm">加入banner</button>
                                        </div>
                                    </div>
                                </form>
                                <table class="layui-table">
                                    <colgroup>
                                        <col width="150">
                                        <col width="200">
                                        <col>
                                    </colgroup>
                                    <thead>
                                    <tr>
                                        <th>标题</th>
                                        <th>图片</th>
                                        <th>href</th>
                                        <th>操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <%for(var b in beauties){%>
                                    <tr lay-data="${b.imgUrl!}">
                                        <td>${b.title}</td>
                                        <td><a href="/beauty/${b.id}"> <img src="${b.imgUrl!}"></a></td>
                                        <td> <a href="${b.href!}">${b.href!}</a></td>
                                        <td> <a href="#" class="layui-btn layui-btn-danger removeFromBanner">移除banner</a></td>
                                    </tr>
                                    <%}%>
                                    </tbody>
                                </table>

                            </div>
                            <div class="layui-tab-item">
                                <form class="layui-form layui-form-pane" action="/blackList/manage/add" method="post">
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">黑名单IP</label>
                                        <div class="layui-input-block">
                                            <input type="text" name="ip" required  lay-verify="required" placeholder="请输入要加入黑名单的IP" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <div class="layui-input-block">
                                            <button class="layui-btn" alert="true" lay-submit lay-filter="*">加入黑名单</button>
                                        </div>
                                    </div>
                                </form>
                                <table  id="blackListManage" class="layui-table">
                                    <thead>
                                    <tr>
                                        <td>IP</td>
                                        <td>操作</td>
                                    </tr>
                                    </thead>
                                    <tbody class="blackListTableBody">
                                    <%if(isNotEmpty(ips)){%>
                                    <%for(var ip in ips){%>
                                    <tr lay-data="${ip}">
                                        <td>${ip}</td>
                                        <td><button class="layui-btn layui-btn-danger layui-btn-sm del">删除</button></td>
                                    </tr>
                                    <%}%>
                                    <%}%>
                                    </tbody>
                                </table>
                            </div>
                            <div class="layui-tab-item">
                                <div class="layui-inline"> <!-- 注意：这一层元素并不是必须的 -->
                                    <input type="text" class="layui-input" id="test1">
                                </div>
                                <table class="layui-table">
                                    <colgroup>
                                        <col width="150">
                                        <col width="200">
                                        <col>
                                    </colgroup>
                                    <thead>
                                    <tr>
                                        <th>IP</th>
                                        <th>访问次数</th>
                                        <th>访问地址</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <%for(var kv in visitIps){%>
                                    <tr>
                                        <td>${kv.ip}</td>
                                        <td>${kv.visitNum}</td>
                                        <td>${kv.visitArea}</td>
                                    </tr>
                                    <%}%>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
</div>
<%include("/common/_footor.html"){}%>
</body>
<%include("/common/_scripts.html",{user:user}){}%>
<script>
    layui.use(['table','fly','laydate','element','form'], function() {
        var table=layui.table
            ,fly=layui.fly,laydate=layui.laydate,element=layui.element,form = layui.form;
        $('.del').on('click',function () {
            var $tr = $(this).parents('tr');
            var ip = $tr.attr('lay-data');
            fly.json('/blackList/manage/remove',{ip:ip},function (res) {
                layer.msg('移除黑名单成功！');
                $tr.fadeOut(1000);
            })
        })
        $('.removeFromBanner').on('click',function () {
            var imgUrl = $(this).parents('tr').attr('lay-data');
            layer.confirm('真将这幅图片从banner上移除么', function(index){
                fly.json('/beauty/manage/addOrDelBanner?type=del',{imgUrl:imgUrl},function (res) {
                    layer.msg('移除成功！');
                });
                layer.close(index);
            });

        })
        laydate.render({
            elem: '#test1' //指定元素
            ,done: function(value, date, endDate){
                console.log(value); //得到日期生成的值，如：2017-08-18
                location.href='/blackList/manage?queryDate='+value

            }
        });

        form.on('submit(bannerForm)', function(data){
            layer.confirm('确定提交这幅图片加到banner上么', function(index){
                fly.json('/beauty/manage/addOrDelBanner?type=add',data.field,function (res) {
                    layer.msg('加入成功！');
                });
                layer.close(index);
            });
            return false
        });

    });
</script>

</html>