@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Index.cshtml";
}
<script src="~/lib/jquery.ui/1.12.1/jquery-ui.min.js" charset="utf-8"></script>
<link href="~/lib/jquery.ui/1.12.1/jquery-ui.min.css" rel="stylesheet" />
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <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, maximum-scale=1">
</head>
<body>
    <div class="layuimini-container">
        <div class="layuimini-main">

            <fieldset class="table-search-fieldset layui-hide" id="searchField">
                @*<legend>搜索信息</legend>*@
                <div>
                    <form class="layui-form layui-form-pane" action="">
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label required">日期:</label>
                                <div class="layui-input-block">
                                    <select id="time_horizon" name="time_horizon" lay-verify="required">
                                        <option value="1">今天</option>
                                        <option value="2" selected>近7天</option>
                                        <option value="3">近1个月</option>
                                        <option value="4">近2个月</option>
                                    </select>
                                </div>
                            </div>
                            <div class="layui-inline">
                                <button type="submit" class="layui-btn layui-btn-primary" lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                            </div>
                        </div>
                    </form>
                </div>
            </fieldset>

            <script type="text/html" id="toolbarDemo">
                <div class="layui-btn-container" id="toolbar">
                    <button id="NF-details" name="NF-details" authorize="yes" class="layui-btn layui-btn-sm layui-btn-normal layui-hide" lay-event="details"> <i class="layui-icon">&#xe60b;</i>查看</button>
                </div>
            </script>
            <script type="text/html" id="currentTableBar">
                <a id="NF-details" authorize class="layui-btn layui-btn-xs layui-btn-normal" lay-event="details">查看</a>
            </script>
            <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
        </div>
    </div>
    <script>
        layui.use(['jquery', 'form', 'table', 'common', 'layer', 'optimizeSelectOption', 'commonTable'], function () {
            var $ = layui.jquery,
                form = layui.form,
                table = layui.table,
                layer = layui.layer,
                commonTable = layui.commonTable,
                common = layui.common;
            //加载数据
            wcLoading.close();
            //权限控制(js是值传递)
            currentTableBar.innerHTML = common.authorizeButtonNew(currentTableBar.innerHTML);
            toolbarDemo.innerHTML = common.authorizeButtonNew(toolbarDemo.innerHTML);
            commonTable.rendertable({
                elem: '#currentTableId',
                id: 'currentTableId',
                url: '/SystemSecurity/AppLog/GetGridJson',
                autoSort:true,
                cols: [[
                    { type: "radio", width: 50, fixed: 'left'},
                    { field: 'FileName', title: '文件名称', minWidth: 100, sort: true },
                    { title: '操作', width: 80, toolbar: '#currentTableBar', align: "center", fixed: 'right' }
                ]]
            });
            //select验证
            form.verify({
                required: function (value, item) {
                    var msg = "必填项不能为空";
                    value = $.trim(value);
                    var isEmpty = !value || value.length < 1;
                    // 当前验证元素是select且为空时,将页面定位至layui渲染的select处，或自定义想定位的位置
                    if (item.tagName == 'SELECT' && isEmpty) {
                        $("html").animate({
                            scrollTop: $(item).siblings(".layui-form-select").offset().top - 74
                        }, 50);
                    }
                    if (isEmpty) {
                        return msg;
                    }
                }
            });
            // 监听搜索操作
            form.on('submit(data-search-btn)', function (data) {
                commonTable.reloadtable({
                    elem: 'currentTableId',
                    curr: 1,
                    where: { timetype: data.field.time_horizon }
                });
                return false;
            });
            //行点击事件监听，控制按钮显示
            var oneList = ["NF-details"];//选择1条显示
            commonTable.tableRowClick("radio", "currentTableFilter", "currentTableId", oneList);
            /**
             * toolbar监听事件
             */
            table.on('toolbar(currentTableFilter)', function (obj) {
                var data = table.checkStatus('currentTableId').data;
                if (obj.event === 'details') {  // 监听删除操作
                    if (data.length == 0) {
                        common.modalMsg("未选中数据", "warning");
                        return false;
                    }
                    var html = "";
                    //高度宽度超出就适应屏幕
                    var _width = document.body.clientWidth > 500 ? '500px' : document.body.clientWidth - 20 + 'px';
                    var _height = document.body.clientHeight > 500 ? '500px' : document.body.clientHeight - 20 + 'px';
                    if (common.currentWindow()) {
                        _width = common.currentWindow().document.body.clientWidth > 500 ? '500px' : common.currentWindow().document.body.clientWidth - 20 + 'px';
                        _height = common.currentWindow().document.body.clientHeight > 500 ? '500px' : common.currentWindow().document.body.clientHeight - 20 + 'px';
                    }
                    common.ajax({
                        url: "/SystemSecurity/AppLog/GetFormJson",
                        dataType: "json",
                        data: { keyValue: data[0].FileName },
                        async: false,
                        success: function (data) {
                            html = "<pre class='no-padding no-margin no-top-border' style='padding: 15px'><code class='html'>" + data.data + "</code></pre>";
                            layer.open({
                                type: 1,
                                shade: 0.3,
                                title: '查看日志',
                                isOutAnim: true,//关闭动画
                                fix: false,
                                area: [_width, _height],
                                content: html,
                                success: function (layero, index) {
                                    $(layero).addClass("scroll-wrapper");//苹果 iframe 滚动条失效解决方式
                                },
                            });
                        }
                    });
                }
                else if (obj.event === 'TABLE_SEARCH') {
                    var _that = $("#searchField");
                    if (_that.hasClass("layui-hide")) {
                        _that.removeClass('layui-hide');
                    } else {
                        _that.addClass('layui-hide');
                    }
                    table.resize();
                }
                return false;
            });
            //toolrow监听事件
            table.on('tool(currentTableFilter)', function (obj) {
                if (obj.event === 'details') {
                    var html = "";
                    //高度宽度超出就适应屏幕
                    var _width = document.body.clientWidth > 500 ? '500px' : document.body.clientWidth - 20 + 'px';
                    var _height = document.body.clientHeight > 500 ? '500px' : document.body.clientHeight - 20 + 'px';
                    if (common.currentWindow()) {
                        _width = common.currentWindow().document.body.clientWidth > 500 ? '500px' : common.currentWindow().document.body.clientWidth - 20 + 'px';
                        _height = common.currentWindow().document.body.clientHeight > 500 ? '500px' : common.currentWindow().document.body.clientHeight - 20 + 'px';
                    }
                    common.ajax({
                        url: "/SystemSecurity/AppLog/GetFormJson",
                        dataType: "json",
                        data: { keyValue: obj.data.FileName },
                        async: false,
                        success: function (data) {
                            html = "<pre class='no-padding no-margin no-top-border' style='padding: 15px'><code class='html'>" + data.data + "</code></pre>";
                            layer.open({
                                type: 1,
                                shade: 0.3,
                                title: '查看日志',
                                isOutAnim: true,//关闭动画
                                fix: false,
                                area: [_width, _height],
                                content: html,
                                success: function (layero, index) {
                                    $(layero).addClass("scroll-wrapper");//苹果 iframe 滚动条失效解决方式
                                },
                            });
                        }
                    });
                }
                return false;
            });
        });
    </script>

</body>
</html>