@using MineTec.ProManager.Admin.ViewResources
@using MineTec.ProManager.Authorization
@{
    ViewBag.CurrentPageName = PageNames.AuditLogs;
    var startDate = DateTime.Now.AddDays(-6).ToString("yyyy-MM-dd");
    var endDate = DateTime.Now.AddDays(+1).ToString("yyyy-MM-dd");
}

<div class="layui-card">
    <div class="layui-card-body">
        <form class="layui-form" action="">
            <div class="layui-form-item">
                <label class="layui-form-label">控制器</label>
                <div class="layui-input-inline">
                    <input type="text" name="serviceName" placeholder="请输入控制器名称" autocomplete="off" class="layui-input">
                </div>
                <label class="layui-form-label">开始日期</label>
                <div class="layui-input-inline">
                    <input type="text" name="startDate" id="startDate" lay-verify="date" placeholder="请选择开始日期" autocomplete="off" class="layui-input">
                </div>
                <label class="layui-form-label">截止日期</label>
                <div class="layui-input-inline">
                    <input type="text" name="endDate" id="endDate" lay-verify="date" placeholder="请选择截止日期" autocomplete="off" class="layui-input">
                </div>
                <button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="auditlog-query">
                    <i class="layui-icon layui-icon-search"></i>
                    查询
                </button>
                <button type="reset" class="pear-btn pear-btn-md">
                    <i class="layui-icon layui-icon-refresh"></i>
                    重置
                </button>
            </div>
        </form>
    </div>
</div>

<div class="layui-card">
    <div class="layui-card-body">
        <table id="auditlog-table" lay-filter="auditlog-table"></table>
    </div>
</div>

<script type="text/html" id="auditlog-executionTime">
    {{layui.util.toDateString(d.executionTime, 'yyyy-MM-dd HH:mm:ss')}}
</script>

@section scripts{
    <script type="text/javascript">
        layui.use(['abp', 'laydate', 'form', 'table'], function () {
            var $ = layui.$;
            var abp = layui.abp;
            var laydate = layui.laydate;
            var form = layui.form;
            var table = layui.table;

            //开始日期
            laydate.render({
                elem: '#startDate',
                value: '@startDate'
            });

            //截止日期
            laydate.render({
                elem: '#endDate',
                value: '@endDate'
            });
            form.render();

            form.on('submit(auditlog-query)', function(data){
                table.reload('auditlog-table', {
                    where: data.field,
                    page: {
                        curr: 1
                    }
                })
		        return false;
		    });

		    table.render({
		        elem: '#auditlog-table',
		        url: "@Url.Action("GetAuditLogList", "AuditLogs")",
                page: true,
                where: {
                    "startDate": "@startDate",
                    "endDate": "@endDate"
                },
                height: 'full-150',
                parseData: function (res) {
                    return {
                        "code": res.result.code, //解析接口状态
                        "msg": res.result.msg, //解析提示文本
                        "count": res.result.count, //解析数据长度
                        "data": res.result.data //解析数据列表
                    };
                },
                response: {
                    statusCode: 200 //规定成功的状态码，默认：0
                },
		        cols: [
		            [
		                {title: 'ID', field: 'id', align:'center', width:100},
		                {title: '控制器', field: 'serviceName', align:'center', width:250},
		                {title: '方法', field: 'methodName', align:'center', width:200},
		                {title: '参数', field: 'parameters', align:'center'},
					    {title: '执行时间', field: 'executionTime', align:'center',width:200, templet:"#auditlog-executionTime"},
					    {title: '执行耗时', field: 'executionDuration', align:'center',width:100},
		            ]
		        ],
		        skin: 'line',
		        toolbar: 'true',
		        defaultToolbar: [{
		            layEvent: 'refresh',
		            icon: 'layui-icon-refresh',
		        }, 'filter', 'print', 'exports']
            });

            table.on('toolbar(auditlog-table)', function(obj){
		        if(obj.event === 'refresh'){
		            window.refresh();
		        }
		    });

            window.refresh = function(){
		        table.reload('auditlog-table');
		    }
        });
    </script>
}

