<%@ page import="com.fadu.app.util.SystemCache" %>
<%@ 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  class="well well-sm">
    <select class="select" id="dateSection">
                <option value="0">今日</option>
                <option value="1">本周</option>
                <option value="2">本月</option>
                <option value="3">上月</option>
                <option value="4">今年</option>
    </select>
    <input type="text" class="input-sm" placeholder="选择开始日期" id="startTime" />
    <input type="text" class="input-sm"	placeholder="选择结束日期" id="endTime" />

    <button type="button" class="btn btn-primary btn-sm" id="searchd">
        筛选
    </button>
</div>


<div class="row" >
    <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 -->


<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 dateSection = $("#dateSection").val();
                var startTime = $("#startTime").val();
                var endTime = $("#endTime").val();
                myGrid.setGridParam({postData:{dateSection:dateSection,startTime:startTime,
                        endTime:endTime},
                    url : '${contextPath}/ssdb/report/getSsdbOrderReport',page:1}).trigger('reloadGrid');
            });

            $('#startTime').datepicker({
                language: 'zh-CN',
                pickTime: false,
                todayBtn: true,
                autoclose: true,
                minView: '2',
                forceParse: false,
                format:"yyyy-mm-dd"
            });
            $('#endTime').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/report/getSsdbOrderReport",
                datatype : "json",
                mtype:'POST',//设置http方式为post以解决乱码问题
                colNames : ['订单来源','订单提交数','付款订单数','订单成交率','提交保费','付款保费','保费成交率'],
                colModel : [{
                    name : 'orderCategory',
                    index : 'orderCategory',
                    width : 150,
                    search : false,
                    editable : false,
                    formatter : orderCategoryFormatter
                },{
                    name : 'subOrderNumber',
                    index : 'subOrderNumber',
                    width : 130,
                    search : false,
                    editable : false,
                    hidden : false,
                },{
                    name : 'payOrderNumber',
                    index : 'payOrderNumber',
                    width : 130,
                    search : false,
                    editable : false,
                    hidden : false,
                },{
                    name : 'orderRate',
                    index : 'orderRate',
                    width : 130,
                    search : false,
                    editable : false,
                },{
                    name : 'subBf',
                    index : 'subBf',
                    width : 120,
                    search : false,
                    editable : false,
                    formatter :subBfFormatter
                },{
                    name : 'payBf',
                    index : 'payBf',
                    width : 150,
                    search : false,
                    editable : false,
                    formatter :payBfFormatter
                },{
                    name : 'bfRate',
                    index : 'bfRate',
                    width : 100,
                    search : false,
                    editable : false,
                }],
                sortname : "orderCategory",
                sortorder : "desc",
                viewrecords : true,
                rowNum : -1,
               // rowList : [ 30, 50, 100 ],
               // 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 orderCategoryFormatter(cellvalue, options, cell) {
                var template = cellvalue ;
                if (cell.orderCategory == '0') {
                    template = '暂未分类';
                }
                if (cell.orderCategory == '1') {
                    template = 'APP';
                }
                if (cell.orderCategory == '2') {
                    template = '微信';
                }
                if (cell.orderCategory == '3') {
                    template = '渠道';
                }
                if (cell.orderCategory == '9') {
                    template = '汇总';
                }
                return template;
            }
            function subBfFormatter(cellvalue, options, cell) {
                return fomatFloat(cell.subBf,2);
            }
            function payBfFormatter(cellvalue, options, cell) {
                return fomatFloat(cell.payBf,2);
            }
            function fomatFloat(src,pos){
                return Math.round(src*Math.pow(10, pos))/Math.pow(10, pos);
            }
        });
    });

</script>