<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <title>企业文件</title>
    <link rel="stylesheet" href="/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/public.css" media="all">
    <link rel="stylesheet" href="/lib/font-awesome-4.7.0/css/font-awesome.min.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <!-- 上方搜索栏 -->
        <fieldset class="table-search-fieldset">
            <legend>搜索</legend>
            <div class="layui-form layui-form-pane">
                <div class="layui-form-item">
                    <!-- 搜索【工作流名】和【权限字符】-->
                    <div class="layui-inline">
                        <label class="layui-form-label">关键词</label>
                        <div class="layui-input-inline">
                            <input type="text" id="fileName" name="fileName" autocomplete="off" class="layui-input" placeholder="请输入关键词"/>
                        </div>
                    </div>
                    <!-- 搜索按钮 -->
                    <div class="layui-inline">
                        <button type="button" class="layui-btn layui-btn-primary layui-border-green btn-role-action" data-type="search">
                            <i class="layui-icon layui-icon-search"></i> 搜 索
                        </button>
                        <button type="button" class="layui-btn layui-btn-primary layui-border-box btn-role-action" data-type="refresh">
                            <i class="layui-icon layui-icon-refresh"></i> 清 空
                        </button>
                    </div>
                </div>
            </div>
        </fieldset>
        <!-- 表格 -->

        <table class="layui-hide" id="table-data" lay-filter="table-data"></table>
    </div>
</div>

<script type="text/html" id="toolbar-table">
    <div class="layui-btn-container">
        <button style="background-color: #154d96;" class="layui-btn layui-btn-sm layuimini-btn-primary" lay-event="btn-refresh"><i class="fa fa-refresh"></i></button>
    </div>


</script>


<!-- 【行内按钮】表格每行末尾的操作按钮-->
<script type="text/html" id="table-tool">
    <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="btn-recover">恢复文件</a>

    <div class="layui-btn-group">
        <button class="layui-btn layui-btn-xs layui-btn-danger" lay-event="btn-delete"><i class="fa fa-trash-o"></i> 永久删除</button>
    </div>

</script>
<!--引入JS文件-->
<script src="/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="/js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script>
    layui.use(['table','dropdown', 'util', 'layer',], function () {
        let $ = layui.jquery,
            form = layui.form,
            dropdown = layui.dropdown,
            table = layui.table;

        let currPage = 1



        let table_data = table.render({
            even: true,
            elem: '#table-data',
            url: '/cloud/recycle/list',
            response: {statusCode: 200},
            toolbar: '#toolbar-table',
            defaultToolbar: ['filter'],
            title: '企业文件',
            height: 'full-200',
            cols: [
                [
                    {type: "checkbox", fixed: 'left',width: 50},
                    {field: 'fileImage', title: '', fixed: 'left',width: 60,align: 'center',
                        templet: function(d){
                            return '<img src="' + d.fileImage + '" style="width: 25px; height: 25px;" />';
                        }
                    },
                    {field: 'fileName', title: '文件名称', fixed: 'left'},
                    {field: 'fileFormat', title: '文件格式',width: 150},
                    {field: 'fileSize', title: '文件大小',width: 150, templet: function (d) {
                            let html = "";
                            if (d.fileSize === null) {
                                html = ""
                            }else{
                                html = d.fileSize + ` KB`
                            }
                            return html
                        }
                    },

                    {field: 'creatorName', title: '创建人',width: 150},
                    {fixed: 'right', title: '操作', align: 'center', toolbar: '#table-tool', width: 250}
                ]
            ],
            page: {
                layout: ['limit', 'count', 'prev', 'page', 'next', 'skip', 'refresh'], // 自定义分页布局
                curr: 1, // 初始当前页
                limits: [30, 50, 100,500,1000], // 自定义每页显示条数选择项
                limit: 30 // 默认每页显示条数
            },
            done: function (res, curr, count) {
                if (res.data.length === 0 && curr > 1) {
                    table_data.reload({page: {curr: curr - 1}})
                }
                currPage = curr
            }
        });
        let active = {
            search: function () {
                table_data.reload({
                    page: {curr: 1},
                    where: {
                        fileName: $('#fileName').val(),
                    }
                });
            },
            refresh: function () {
                table_data.reload({
                    page: {curr: 1},
                    where: {fileName: ""}
                });
                $('#fileName').val('')
            }
        };
        $('.btn-role-action').on('click', function () {
            let type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });



        table.on('toolbar(table-data)', function (obj) {
            let that = this;
            switch (obj.event) {
                case "btn-refresh":
                    table_data.reload()
                    break;
                case "btn-back":
                    break;
            }
        });


        table.on('tool(table-data)', function (obj) {
            let that = this;
            let data = obj.data;
            let layEvent = obj.event;
            switch (layEvent) {
                case "btn-recover":
                    layer.confirm("真的要恢复该文件 " + data.fileName + " 吗？", {
                        icon: 3, title: '删除文件确认【1/1】',
                        btn: ['确定', '取消'],
                        closeBtn: 0,
                        btn1: function (index) {
                            // 加载层
                            let index_loading = layer.load(1, {
                                shade: [0.2, '#fff'] //0.1透明度的白色背景
                            });
                            $.post("/cloud/recycle/recover", {id: data.id}, function (data2) {
                                // 关闭加载层
                                layer.close(index_loading)
                                if (data2.code === 200) {
                                    layer.msg(data2.msg, {time: 3000, icon: 1});
                                    table_data.reload();
                                } else {
                                    layer.msg(data2.msg, {time: 3000, icon: 2});
                                }
                            });
                        }
                    });

                    break;
                case "btn-delete":
                        layer.confirm("<a style='color: red'>真的要删除该文件 " + data.fileName + " 吗？删除后可在回收站恢复！</a>", {
                            icon: 3, title: '删除文件确认【1/1】',
                            btn: ['确定', '取消'],
                            closeBtn: 0,
                            btn1: function (index) {
                                // 加载层
                                let index_loading = layer.load(1, {
                                    shade: [0.2, '#fff'] //0.1透明度的白色背景
                                });
                                $.post("/cloud/recycle/foreverDelete", {id: data.id}, function (data2) {
                                    // 关闭加载层
                                    layer.close(index_loading)
                                    if (data2.code === 200) {
                                        layer.msg(data2.msg, {time: 3000, icon: 1});
                                        table_data.reload();
                                    } else {
                                        layer.msg(data2.msg, {time: 3000, icon: 2});
                                    }
                                });
                            }
                        });

                    break;

            }
        });





    });
</script>
</body>
</html>
