<%@ 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)">
    <span style="font-size: 20px;" id="pkTime">无</span>
    &nbsp;<button id="sePkTime" onclick="getSysuser()" type="button" class="btn" >设置PK时间</button>
    <div>小组排名：</div>
</div>

<div class="row">
    <div >
        <div class="col-xs-7" >
            <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  class="col-xs-12"  style="background: rgba(1,1,2,0.05)">
        <span>&nbsp;</span>
        <div>客户经理排名：</div>
        <span>&nbsp;</span>
    </div>
    <div>
        <div class="col-xs-10" >
            <table id="grid-table1"></table>
            <div id="grid-pager1"></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>

<div id="modal-add-body" class="modal fade" tabindex="-1" data-backdrop="static">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header no-padding">
                    <div class="table-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                            <span class="white">&times;</span>
                        </button>
                        设置PK时间
                    </div>
                </div>
                <div class="modal-body" style="overflow-y: scroll;">
                    <div id="mod-add-tip" class="red clearfix"></div>
                    <div class="form-group" style="margin-left: 30px;">
                        <label for="add-pkStart" class="control-label">开始时间：</label>
                        <input type="text" id="add-pkStart">
                    </div>
                    <div class="form-group" style="margin-left: 30px;">
                        <label for="add-pkEnd" class="control-label">结束时间：</label>
                        <input type="text" id="add-pkEnd">
                    </div>
                    <div>
                        <p><span style="color: rgba(0,0,0,0.44);font-size: 12px">(若不设置PK时间,开始、结束时间填 0)</span></p>
                    </div>
                <div class="modal-footer no-margin-top">
                    <div class="text-center">
                        <button id="mod-add-success" type="button" class="btn btn-sm btn-primary"
                                onclick="setPkTime();">
                            确定
                        </button>
                        <button class="btn btn-sm" data-dismiss="modal">
                            取消
                        </button>
                    </div>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
    </div>
</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 grid_selector1 = "#grid-table1";
            var pager_selector = "#grid-pager";
            var pager_selector1 = "#grid-pager1";

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

            $(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}/ssdb/manager/getPkGroup",
                datatype : "json",
                mtype:'POST',//设置http方式为post以解决乱码问题
                colNames : ['排名','小组','人均付款保费','团队人员'],
                colModel : [{
                    name : 'num',
                    index : 'num',
                    width : 100,
                    search : false,
                    editable : false,
                    //sorttype : 'date'
                },{
                    name : 'groupName',
                    index : 'groupName',
                    width : 150,
                    search : false,
                    editable : false,
                    //sorttype : 'date'
                },{
                    name : 'avgBf',
                    index : 'avgBf',
                    width : 150,
                    search : false,
                    editable : false,
                    //sorttype : 'date'
                },{
                    name : 'groupNum',
                    index : 'groupNum',
                    width : 150,
                    search : false,
                    editable : false,
                    //sorttype : 'date'
                }],
                // sortname : "groupName",
                // sortorder : "asc",
                viewrecords : true,
                rowNum : 5,
                rowList : [ 5, 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);
                }
            });

            myGrid=	jQuery(grid_selector1).jqGrid({
                subGrid : false,
                url : "${contextPath}/ssdb/manager/getPkPeople",
                datatype : "json",
                mtype:'POST',//设置http方式为post以解决乱码问题
                colNames : ['排名','客户经理','付款保费'],
                colModel : [{
                    name : 'num',
                    index : 'num',
                    width : 150,
                    search : false,
                    editable : false,
                    //sorttype : 'date'
                },{
                    name : 'manager',
                    index : 'manager',
                    width : 170,
                    search : false,
                    editable : false,
                    //sorttype : 'date'
                },{
                    name : 'bf',
                    index : 'bf',
                    width : 200,
                    search : false,
                    editable : false,
                    //sorttype : 'date'
                }],
                // sortname : "groupName",
                // sortorder : "asc",
                viewrecords : true,
                rowNum : 50,
                rowList : [ 50, 100, 300 ],
                pager : pager_selector1,
                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 getPkTime() {
        $.ajax({
            dataType : "json",
            url : "${contextPath}/ssdb/manager/getPkTime",
            type : "post",
            complete : function(ret) {
                var ret = eval("(" + ret.responseText + ")");
                console.log(ret);
                $("#pkTime").html("PK时间是 " + ret.pkStart + " 至 " + ret.pkEnd);
            }
        });
    }

    getPkTime();

    function getSysuser(orderId) {
        $.ajax({
            dataType : "json",
            url : "${contextPath}/ssdb/manager/getSysuserRole",
            type : "post",
            complete : function(ret) {
                var ret = eval("(" + ret.responseText + ")");
                if (ret.succ === "false"){
                    $("#add-pkStart").attr('disabled',true);
                    $("#add-pkEnd").attr('disabled',true);
                    preSetPkTime(orderId);
                }else{
                    preSetPkTime(orderId);
                }
            }
        });
    }
    function preSetPkTime() {
        $("#modal-add-body").modal("toggle");
    }

    function setPkTime() {
        var pkStrat = $("#add-pkStart").val();
        var pkEnd = $("#add-pkEnd").val();
        $.ajax({
            dataType : "json",
            url : "${contextPath}/ssdb/manager/setPkTime",
            type : "post",
            data : {
                'pkStrat' : pkStrat,
                'pkEnd' : pkEnd,
            },
            complete : function(ret) {
                var ret = eval("(" + ret.responseText + ")");
                console.log(ret.message);
                alert(ret.message);
                getPkTime();
                $("#modal-add-body").modal("toggle");
                jQuery("#grid-table").trigger("reloadGrid");
                jQuery("#grid-table1").trigger("reloadGrid");
            }
        });
    }



</script>