<section class="content-header">
    <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i> 首页</a></li>
        <li class="active">系统日志列表</li>
    </ol>
</section>
<!-- Main content -->
<section class="content">
    <div class="jax-box">
    	<form id="formSearch" class="form-inline form-search">
            <div class="form-group">
				<label>关键字: </label>
				<input type="text" id="s_description" class="form-control" placeholder="这里输入关键字">
			</div>
			<div class="form-group">
				<label>日志类型: </label>
     			<select id="s_type" class="form-control">
     				<option value="-1"></option>
                    <option value="1">系统管理</option>
                    <option value="2">登录日志</option>
                    <option value="3">字典管理</option>
                    <option value="4">案例管理</option>
                </select>
			</div>
            <div class="form-group">
                <div class="col-md-1 col-sm-3" style="text-align:left;">
                    <button type="button" id="btn_query" class="btn btn-info">查 询</button>
                </div>
			</div>
        </form>
    </div>
    
    <div class="jax-box jax-box-table">
        <div id="toolbar" class="btn-group">
            <shiro:hasPermission name="syslog">
            <button id="btn_batch_delete" type="button" class="btn btn-danger">
                <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>批量删除
            </button>
            </shiro:hasPermission>
        </div>
        <table id="table"></table>
    </div>
</section>

<script type="text/javascript">
    var delFlag = "[[${@perms.hasPerm('syslog')}]]";
    var columns = [
        {checkbox: true },
       	{field: 'createtime', title: '创建时间', align : "center"},
       	{field: 'typeName', title: '日志类型', align : "left"},
        {field: 'operator', title: '操作者', align : "left"},
        {field: 'ipaddr', title: 'IP地址', align : "left"},
        {field: 'description', title: '描述', align : "center"},
        {field : 'operation', title : '操作', align : "left", width: '102px', formatter: function(value, row, index) {
        	let delHtml = delFlag=="true" ? '&nbsp;<a class="table-btn table-btn-danger" href="javascript:void(0)" onclick="deleteAction('+row.id+',1)">删除</a>' : '';
			return delHtml;
       }}
	];
    var options={
        id:"#table",
        url: '[[@{/console/syslog/list}]]',
        columns:columns,
        toolbar: '#toolbar',
        showRefresh: true,
        queryParams : queryParams
    }
    Core.initTable(options);
	
	//查询参数
    function queryParams(params) {
        let temp = {
            limit : params.limit, //页面大小
            offset : params.offset, //页码
            description: $("#s_description").val(),
            type: $("#s_type").val()
        };
        return temp;
    }

	/*删除*/
    function deleteAction(ids,num){
    	var msg = num>1 ? "确定删除选中的"+num+"条记录？" : "确定删除该记录？";
        Core.confirm(msg, function () {
            Core.postAjax("[[@{/console/syslog/delete}]]",{"ids":ids},function (data) {
                if(data.ret==0){
                	layer.msg('删除成功！');
                    Core.refreshTable("#table");
                }else{
	                layer.msg(data.msg);
                }
            },"POST");
        })
	}

	$(function () {
		/*查询*/
        $("#btn_query").click(function(){
            Core.refreshTable("#table");
        });

        /*批量删除*/
        $("#btn_batch_delete").click(function(){
        	var checkedRows= Core.selectMutiData("#table");
            if(checkedRows){
	            var ids = "";
	            $.each(checkedRows, function (i, item) {
	                ids += (item.id + ",");
	            })
	            if(ids.length > 0)ids = ids.substring(0, ids.length - 1);
	            deleteAction(ids, checkedRows.length);
            }
        });

	});
</script>