<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta name="decorator" content="base"/>
    <link rel="stylesheet" href="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" href="${ctxPlugin}/static/css/reset.css" media="all">
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card layui-form">
        <div class="layui-tab layui-tab-brief">
            <ul class="layui-tab-title">
                <sfTags:pagePermission authFlag="WJGL_WJGL_PJSZL_T" html='<li class="layui-this sf-tab"><a href="${ctx}/notification/fileManagement">文件管理</a></li>'/>

            </ul>
        </div>

        <div class="layui-card-body">
            <table class="layui-hide " id="test-table-reload" lay-filter="test-table-reload"></table>
        </div>
    </div>

</div>

<div  id="toolbarDemo" class="layui-form-item layui-hide">
    <sfTags:pagePermission authFlag="PLATEM_WJGL_XZ_B" html='<button class="layui-btn layui-btn-sm" id="addBtn" lay-event="add"><i class="layui-icon layui-icon-add-1"></i>新增</button>'/>
    <sfTags:pagePermission authFlag="PLATEM_WJGL_SC_B" html='<button class="layui-btn layui-btn-sm" id="delBtn" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</button>'/>
</div>

<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.js"></script>


<script type="text/javascript">
    layui.config({
        base: '${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'tableExt', 'jquery', 'layer'], function(){
        var tableExt = layui.tableExt;
        var layer = layui.layer;
        var $ = layui.jquery;

        tableExt.render({
            elem: '#test-table-reload'
            , height: 'full-80'
            ,toolbar : '#toolbarDemo'
            ,defaultToolbar : false
            ,url: '${ctx}/notification/ajaxTechnicalData?type=2'
            , page: true
            , limits: [20, 50, 100]
            , limit: 20
            ,cols: [[
                {type: 'numbers', title: '序号'}
                , {field: 'id', type: 'checkbox'}
                ,{field:'href', title: '文件标题' , align : 'center', templet: function(d){
                    return '<a target="_blank" class="layui-table-opt-link" href="${commonStaticImgPath}'+d.href+'">'+d.name+'</a>'
                }}
                ,{field:'description', title: '文件描述', align : 'center',width: 600}
                ,{field:'create_time', title: '创建时间', align : 'center'}
            ]]
            ,page:true
        });

        var table = tableExt.getLayTable();

        //监听行工具事件
        table.on('toolbar(test-table-reload)', function(obj){
            if(obj.event === 'add'){
                layer.open({
                    title:'新增文件',
                    type: 2,
                    area: ["45%", "60%"],
                    fixed: false,
                    content: '${ctx}/notification/fileManagementForm',
                    end:function(){
                        location.reload();
                    }
                })
            }
            if(obj.event === 'del'){
                var delData = table.checkStatus("test-table-reload");
                var ids = [];
                if (delData.data.length < 1) {
                    layer.msg("请勾选一条择待处理数据！", {icon: 2});
                    return;
                }
                var datas = delData.data;
                $.each(datas, function(i, d) {
                    ids.push(d.id);
                });
                layer.confirm('真的删除所选文件吗？',{icon: 3}, function(index){
                    $.post('${ctx}/notification/delTechnicalData', {id: ids.join(",")}, function(result){
                        if("ok" == result){
                            layer.msg("删除成功！", {icon: 1});
                            table.reload('test-table-reload');
                            /*   obj.del();
                               layer.close(index);*/
                        }else{
                            layer.msg("删除失败");
                        }
                    });
                });
            }

        });

        var active = {
            reload: function(){
                table.reload('test-table-reload', {
                    where: {
                        name: $('#form-name').val()
                    }
                });
            }
        };

        $('#searchBtn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });


    });


</script>
</body>
</html>
