<%@ 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"/>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <select class="select" id="isJd">
        <option value="" selected = "selected">是否解冻</option>
        <option value="1">已解冻</option>
        <option value="0">冻结中</option>
    </select>
    <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 isJd = $("#isJd").val();
                myGrid.setGridParam({postData:{keyword:keyword,isJd:isJd ,page:1},
                    url : '${contextPath}/ssdb/jdPoint/getPoint',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}/ssdb/jdPoint/getPoint",
                datatype : "json",
                mtype:'POST',//设置http方式为post以解决乱码问题
                height : 450,
                colNames : ['订单号', '订单申请日期',
                    '标的','保费','积分','订单状态','解冻状态','律师姓名','律师电话','操作'],
                colModel : [{
                    name : 'orderId',
                    index : 'orderId',
                    width : 150,
                    search : false,
                    editable : false,
                    //sorttype : 'date'
                },{
                    name : 'createDate',
                    index : 'createDate',
                    width : 200,
                    search : false,
                    editable : false,
                    //sorttype : 'date'
                },{
                    name : 'sqbd',
                    index : 'sqbd',
                    width : 100,
                    search : false,
                    editable : false,
                    //sorttype : 'date'
                },{
                    name : 'bf',
                    index : 'bf',
                    width : 100,
                    search : false,
                    editable : false,
                    //sorttype : 'date'
                },{
                    name : 'points',
                    index : 'points',
                    width : 100,
                    search : false,
                    editable : false,
                    //sorttype : 'date'
                },{
                    name : 'orderState',
                    index : 'orderState',
                    width : 100,
                    search : false,
                    editable : false,
                    //sorttype : 'date'
                },{
                    name : 'isDj',
                    index : 'isDj',
                    width : 100,
                    search : false,
                    editable : false,
                    //sorttype : 'date'
                },{
                    name : 'lawyerName',
                    index : 'lawyerName',
                    width : 100,
                    search : false,
                    editable : false,
                    //sorttype : 'date'
                },{
                    name : 'phone',
                    index : 'phone',
                    width : 120,
                    search : false,
                    editable : false,
                    //sorttype : 'date'
                },{	name : 'type',
                    index : 'type',
                    label : '操作',
                    width : 230,
                    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 : "createDate",
                sortorder : "desc",
                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) {
                var template = null;
                if (cell.isDj == "冻结中" && cell.orderState == "已配送") {
                    template = "<button data-toggle='modal' onclick='toBlack(\""+cell.orderId+"\")'  class='btn btn-minier btn-danger'>解冻积分</button>";
                }else if (cell.isDj == "冻结中"  && cell.orderState == "已出函"){
                    template = "<button data-toggle='modal' onclick='toPreBlackA(\""+cell.orderId+"\")'  class='btn btn-minier btn-danger'>解冻积分</button>";
                }else if (cell.isDj == "冻结中"  && cell.orderState == "已付款"){
                    template = "<button data-toggle='modal' onclick='toPreBlackB(\""+cell.orderId+"\")'  class='btn btn-minier btn-danger'>解冻积分</button>";
                }else if (cell.isDj == "已解冻" ){
                    template = "<button data-toggle='modal' onclick='toWhite(\""+cell.orderId+"\")'  class='btn btn-minier btn-primary'>冻结积分</button>";
                }else {
                    template = "订单没有完成，不能解冻！！";
                }
                return template;
            };


        });
    });


    //已出函询问解冻积分
    function toPreBlackA(orderId) {
        var r = confirm("订单状态为已出函，确定要解冻么？");
            if(r){
                toBlack(orderId)
            }
    }
    //已付款询问解冻积分
    function toPreBlackB(orderId) {
        var r = confirm("订单状态为已付款（待出函），确定要解冻么？");
        if(r){
            toBlack(orderId)
        }
    }
    //解冻积分
    function toBlack(orderId) {
        var r = prompt("确定把积分解冻么？可以添加一些备注哦（没有直接点确定）");
            toBlackList(orderId , r);
    }
    function toBlackList(orderId , r) {
        $.ajax({
            dataType : "json",
            url : "${contextPath}/ssdb/jdPoint/toJd",
            type : "post",
            data : {
                'orderId' : orderId,
                'bz':r
            },
            complete : function(ret) {
                var ret = eval("(" + ret.responseText + ")");
                alert(ret.isSucc);
                myGrid.trigger("reloadGrid");

            }
        });
    }
    //冻结积分
    function toWhite(orderId) {
        var r = prompt("确定把积分冻结么？可以添加一些备注哦（没有直接点确定）");
        toWhiteList(orderId , r);
    }
    function toWhiteList(orderId , r) {
        $.ajax({
            dataType : "json",
            url : "${contextPath}/ssdb/jdPoint/toDj",
            type : "post",
            data : {
                'orderId' : orderId,
                'bz':r
            },
            complete : function(ret) {
                var ret = eval("(" + ret.responseText + ")");
                alert(ret.isSucc);
                myGrid.trigger("reloadGrid");

            }
        });

    }

</script>