<%--
  Created by IntelliJ IDEA.
  User: zwy
  Date: 2019/12/27
  Time: 14:12
  To change this template use File | Settings | File Templates.
--%>
<%@ 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)">
    筛选日期：<input type="text" class="input-sm" placeholder="开始日期"  id="startDate"/>
    <input type="text" class="input-sm" placeholder="结束日期"  id="endDate"/>
    &nbsp;&nbsp;&nbsp;
    关键字:<input id="keywords" placeholder="输入关键字" class="input-medium search-query" type="text" />
    &nbsp;&nbsp;&nbsp;
    <select id='status'>
        <option selected value="" >所有订单</option>
        <option value="0" >申请中</option>
        <option value="1" >已取消</option>
        <option value="2" >已通过</option>
        <option value="3" >已退款</option>
    </select>
    &nbsp;&nbsp;&nbsp;
    <button id="searchd" type="button" class="btn" >搜索</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 startDate = $("#startDate").val();
                var endDate = $("#endDate").val();
                var keywords = $("#keywords").val();
                var status = $("#status").val();
                myGrid.setGridParam({postData:{startDate:startDate ,endDate:endDate,
                        keywords:keywords,status:status,page:1},
                    url : '${contextPath}/fs/deposit/getDepositRecord',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}/fs/deposit/getDepositRecord",
                datatype : "json",
                mtype:'POST',//设置http方式为post以解决乱码问题c
                colNames : ['lawyerId','提交时间','律师姓名','保证金金额', '手机号','申请状态','操作'],
                colModel : [{
                    name : 'lawyerId',
                    index : 'lawyerId',
                    width : 10,
                    search : false,
                    editable : false,
                    hidden : true
                    //sorttype : 'date'
                },{
                    name : 'createDate',
                    index : 'createDate',
                    width : 180,
                    search : false,
                    editable : false,
                    //sorttype : 'date'
                },{
                    name : 'lawyerName',
                    index : 'lawyerName',
                    width : 200,
                    search : false,
                    editable : false,
                    //sorttype : 'date'
                },{
                    name : 'deposit',
                    index : 'deposit',
                    width : 150,
                    search : false,
                    editable : false,
                    //sorttype : 'date'
                },{
                    name : 'phone',
                    index : 'phone',
                    width : 200,
                    search : false,
                    editable : false,
                    //sorttype : 'date'
                },{
                    name : 'status',
                    index : 'status',
                    width : 200,
                    search : false,
                    editable : false,
                    //sorttype : 'date'
                },{
                    name : 'type',
                    index : 'type',
                    width : 300,
                    editable : false,
                    search : false,
                    sortable : false,
                    fixed:true,
                    formatter : optionFormatter
                }],
                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 optionFormatter(cellvalue, options, cell) {
                console.log(cell);
                var template = "&nbsp;<button data-toggle='modal' onclick='passOrCancelDeposit(\""+cell.lawyerId+"\",\""+1+"\")' class='btn btn-minier btn-yellow'><i class='ace-icon fa fa-hdd-o '></i>通过</button>";
                template += "&nbsp;&nbsp;&nbsp;<button data-toggle='modal' onclick='passOrCancelDeposit(\""+cell.lawyerId+"\",\""+0+"\")' class='btn btn-minier btn-info'><i class='ace-icon fa fa-hdd-o '></i>取消</button>";
                return template;
            }

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


        });
    });
    function passOrCancelDeposit(lawyerId,operation) {
        console.log(lawyerId);
        console.log(operation);
        $.ajax({
            dataType : "json",
            url : "${contextPath}/fs/deposit/passOrCancelDeposit",
            type : "post",
            data : {
                'lawyerId' : lawyerId,
                'type' : operation,
            },
            complete : function(ret) {
                var ret = eval("(" + ret.responseText + ")");
                alert(ret.message);
                console.log(ret);
            }
        });
    }

</script>


