<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<c:set var="contextPath" value="${pageContext.request.contextPath}"></c:set>

<link rel="stylesheet" href="${contextPath}/static/assets/css/jquery-ui.css" />
<link rel="stylesheet" href="${contextPath}/static/assets/css/datepicker.css" />
<link rel="stylesheet" href="${contextPath}/static/assets/css/ui.jqgrid.css" />

<div style="background: rgba(1,1,2,0.05)">
    <br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <input type="text" class="input-md" placeholder="搜索关键字" id="keyword"/>

    <button type="button" class="btn btn-purple btn-sm" id="searchd">
        <span class="ace-icon fa fa-search icon-on-right bigger-110"></span>
        查询
    </button>
    <br>
    <br>
</div>

<div class="row">
    <div class="col-xs-12">
        <table id="grid-table"></table>
        <div id="grid-pager"></div>
        <script type="text/javascript">
            var $path_base = "${contextPath}/static";//in Ace demo this will be used for editurl parameter
        </script>
        <!-- PAGE CONTENT ENDS -->
    </div><!-- /.col -->
</div><!-- /.row -->


<script type="text/javascript">
    var myGrid = null;
    var scripts = [ null,  "${contextPath}/static/assets/js/date-time/bootstrap-datepicker.js", "${contextPath}/static/assets/js/date-time/locales/bootstrap-datepicker.zh-CN.js", "${contextPath}/static/assets/js/jqGrid/jquery.jqGrid.js", "${contextPath}/static/assets/js/jqGrid/i18n/grid.locale-cn.js", null ]

    $('.page-content-area').ace_ajax('loadScripts', scripts, function() {
        jQuery(function ($) {

            var grid_selector = "#grid-table";
            var pager_selector = "#grid-pager";

            /*搜索框  主要对Jquery grid进行刷新 带参数刷新    */
            $("#searchd").click(function(){
                var keyword =encodeURI(encodeURI($("#keyword").val()));
                var isBlack = $("#isBlack").val();
                myGrid.setGridParam({postData:{keyword:keyword,isBlack:isBlack ,page:1},
                    url : '${contextPath}/ads/vip/getBlack',page:1}).trigger('reloadGrid');
            });

            $(document).keydown(function (event) {
                var key = window.event ? event.keyCode : event.which;
                if (key == 13) {
                    $("#searchd").click();
                }
            });


            myGrid=	jQuery(grid_selector).jqGrid({
                subGrid : false,
                url : "${contextPath}/ads/vip/getBlack",
                datatype : "json",
                mtype:'POST',//设置http方式为post以解决乱码问题
                height : 450,
                colNames : ['id','律师姓名', '律师电话','案件订单号','操作'],
                colModel : [{
                    name : 'id',
                    index : 'id',
                    width : 200,
                    search : false,
                    editable : false,
                    hidden : true,
                    //sorttype : 'date'
                },{
                    name : 'lawyerName',
                    index : 'lawyerName',
                    width : 200,
                    search : false,
                    editable : false,
                    //sorttype : 'date'
                },{
                    name : 'phone',
                    index : 'phone',
                    width : 200,
                    search : false,
                    editable : false,
                    //sorttype : 'date'
                },{
                    name : 'adsLawsuitId',
                    index : 'adsLawsuitId',
                    width : 200,
                    search : false,
                    editable : false,
                    //sorttype : 'date'
                },{	name : 'type',
                    index : 'type',
                    label : '操作',
                    width : 100,
                    editable : false,
                    search : false,
                    sortable : false,
                    fixed:true,
                    formatter : optionFormatter
                }],
                //scroll : 1, // set the scroll property to 1 to enable paging with scrollbar - virtual loading of records
                sortname : "lawyerName",
                sortorder : "asc",
                viewrecords : true,
                rowNum : 10,
                rowList : [ 10, 20, 30 ],
                pager : pager_selector,
                altRows : true,
                height:"auto",//自动根据每页条数弹性调整表格高度
                loadComplete : function() {
                    var table = this;
                    setTimeout(function(){
                        /*styleCheckbox(table);
                        updateActionIcons(table);*/
                        updatePagerIcons(table);
                        enableTooltips(table);
                    }, 0);
                }
            });

            function updatePagerIcons(table) {
                var replacement = {
                    'ui-icon-seek-first' : 'ace-icon fa fa-angle-double-left bigger-140',
                    'ui-icon-seek-prev' : 'ace-icon fa fa-angle-left bigger-140',
                    'ui-icon-seek-next' : 'ace-icon fa fa-angle-right bigger-140',
                    'ui-icon-seek-end' : 'ace-icon fa fa-angle-double-right bigger-140'
                };
                $('.ui-pg-table:not(.navtable) > tbody > tr > .ui-pg-button > .ui-icon').each(function() {
                    var icon = $(this);
                    var $class = $.trim(icon.attr('class').replace('ui-icon', ''));

                    if ($class in replacement)
                        icon.attr('class', 'ui-icon ' + replacement[$class]);
                })
            }

            function enableTooltips(table) {
                $('.navtable .ui-pg-button').tooltip({
                    container : 'body'
                });
                $(table).find('.ui-pg-div').tooltip({
                    container : 'body'
                });
            };

            function optionFormatter(cellvalue, options, cell) {
                return "<button data-toggle='modal' onclick='toWhite(\"" + cell.id + "\")'  class='btn btn-minier btn-primary'>解封</button>";
            };


        });
    });

    function toWhite(id) {
        var r = confirm("确定把他解封么？")
        if (r==true) {
            toWhiteList(id);
        }
    }
    function toWhiteList(id) {
        $.ajax({
            dataType : "json",
            url : "${contextPath}/ads/vip/toWhite",
            type : "post",
            data : {
                'id' : id
            },
            complete : function(ret) {
                var ret = eval("(" + ret.responseText + ")");

                alert(ret.message);
                myGrid.trigger("reloadGrid");

            }
        });

    }

</script>