<%@ 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" />
<br>
<div style="background: rgba(1,1,2,0.05)">
    筛选日期：<input type="text" class="input-sm" placeholder="开始日期"  id="startDate"/>
    <input type="text" class="input-sm" placeholder="结束日期"  id="endDate"/>
    &nbsp;<button id="searchd" type="button" class="btn" >搜索</button>
</div>
<div class="row">
    <div >
        <div class="col-xs-6" >
            <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 -->
</div>

<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 startDate = $("#startDate").val();
                var endDate = $("#endDate").val();
                myGrid.setGridParam({postData:{startDate:startDate,endDate:endDate,page:1},
                    url : '${contextPath}/ssdb/manager/getManaOrder',page:1}).trigger('reloadGrid');
            });


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

            $('#startDate').datepicker({
                language: 'zh-CN',
                pickTime: false,
                todayBtn: true,
                autoclose: true,
                minView: '2',
                forceParse: false,
                format:"yyyy-mm-dd"
            });
            $('#endDate').datepicker({
                language: 'zh-CN',
                pickTime: false,
                todayBtn: true,
                autoclose: true,
                minView: '2',
                forceParse: false,
                format:"yyyy-mm-dd"
            });


            myGrid=	jQuery(grid_selector).jqGrid({
                subGrid : false,
                url : "${contextPath}/ssdb/manager/getManaOrder",
                datatype : "json",
                mtype:'POST',//设置http方式为post以解决乱码问题
                colNames : ['客户经理','提交单量','提交保费','付款单量','付款保费'],
                colModel : [{
                    name : 'manager',
                    index : 'manager',
                    width : 150,
                    search : false,
                    editable : false,
                    //sorttype : 'date'
                },{
                    name : 'submitCount',
                    index : 'submitCount',
                    width : 200,
                    search : false,
                    editable : false,
                    //sorttype : 'date'
                },{
                    name : 'submitBf',
                    index : 'submitBf',
                    width : 200,
                    search : false,
                    editable : false,
                    //sorttype : 'date'
                    formatter : submitBfFormatter
                },{
                    name : 'payedCount',
                    index : 'payedCount',
                    width : 200,
                    search : false,
                    editable : false,
                    //sorttype : 'date'
                },{
                    name : 'payedBf',
                    index : 'payedBf',
                    width : 200,
                    search : false,
                    editable : false,
                    //sorttype : 'date'
                    formatter : payedBfFormatter
                }],
                sortname : "groupName",
                sortorder : "asc",
                viewrecords : true,
                rowNum : 50,
                rowList : [ 50, 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 submitBfFormatter(cellvalue, options, cell) {
                var bf = parseInt(cellvalue);
                return bf;
            };
            function payedBfFormatter(cellvalue, options, cell) {
                var bf = parseInt(cellvalue);
                return bf;
            };

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


        });
    });




</script>
