<%@ 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" />

<style>
    #MyDiv{
        position: absolute;
        top: 50px;
        left: 320px;
        display: none;
    }
</style>

<div style="background: rgba(1,1,2,0.05)">
    <br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <input type="text" class="input-md" placeholder="搜索关键字" id="keyword"/>
    <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>&nbsp;&nbsp;
    <button type="button" onclick="choose_fp()" class="btn btn-purple btn-sm" id="chooseFenpei">
        选择分配方式
    </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 -->

<div  id="MyDiv" class="modal-dialog white_content">
    <div class="modal-content">
        <div class="modal-header no-padding">
            <div class="table-header">
                <button onclick="CloseDiv()" type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    <span  class="white">&times;</span>
                </button>
                选择客服
            </div>
        </div>
        <div class="modal-body" style="overflow-y: scroll;">
            <div id="mod-add-tip" class="red clearfix"></div>
            <div class="form-group">
                <label for="getKefuList">为订单<span id="oid"></span>选择客服</label>
                <div id="getKefuList" ></div>
            </div>
           <div class="modal-footer no-margin-top">
                <div class="text-center">
                    <button onclick="javasrcipt:fenpei() " id="mod-add-submit" type="button" class="btn btn-sm btn-primary">
                        <i class="ace-icon fa fa-floppy-o bigger-160"></i>
                        保存
                    </button>
                    <button  onclick="CloseDiv()" class="btn btn-sm" data-dismiss="modal">
                        <i class="ace-icon fa fa-share bigger-160"></i>
                        取消
                    </button>
                </div>
            </div>
        </div><!-- /.modal-content -->

    </div><!-- /.modal-dialog -->

</div>

<div id="modal-refund-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>
                    选择分配方式
                </div>
            </div>
            <div class="modal-body" style="overflow-y: scroll;">
                <div class="form-group" style="margin-left: 30px;">
                    <label for="fp"></label>
                    <select id="fp">
                        <option value="">请选择</option>
                        <option value="true">自动分配</option>
                        <option value="false">手动分配</option>
                    </select>
                </div>
            </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="toChoose();">
                        确定
                    </button>
                    <button class="btn btn-sm" data-dismiss="modal">
                        取消
                    </button>
                </div>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</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 keyword =encodeURI(encodeURI($("#keyword").val()));
                var isJd = $("#isJd").val();
                myGrid.setGridParam({postData:{keyword:keyword ,page:1},
                    url : '${contextPath}/ssdb/gendan/getSoudong',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/gendan/getSoudong",
                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 : 'loginName',
                    index : 'loginName',
                    width : 150,
                    search : false,
                    editable : false,
                    //sorttype : 'date'
                },{
                    name : 'courtName',
                    index : 'courtName',
                    width : 100,
                    search : false,
                    editable : false,
                    //sorttype : 'date'
                },{
                    name : 'phone',
                    index : 'phone',
                    width : 100,
                    search : false,
                    editable : false,
                    //sorttype : 'date'
                },{
                    name : 'lawyerName',
                    index : 'lawyerName',
                    width : 100,
                    search : false,
                    editable : false,
                    //sorttype : 'date'
                },{
                    name : 'bf',
                    index : 'bf',
                    width : 100,
                    search : false,
                    editable : false,
                    //sorttype : 'date'
                },{
                    name : 'documentaryUser',
                    index : 'documentaryUser',
                    width : 100,
                    search : false,
                    editable : false,
                    //sorttype : 'date'
                },{	name : 'type',
                    index : 'type',
                    label : '操作',
                    width : 230,
                    editable : false,
                    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 = "<button data-toggle='modal' onclick='toFenpei(\""+cell.orderId+"\")'  class='btn btn-minier btn-default'>点击分配</button>";
                return template;
            };
        });
    });
    function CloseDiv() {
        $("#MyDiv").hide();
    }
    function fenpei() {
        var orderId = $("#oid").html();
        var duser = $("#fenpei").val();
        $.ajax({
            dataType : "json",
            url : "${contextPath}/ssdb/gendan/fenpei",
            data :{"orderId":orderId,
                "documentaryUser":duser,},
            type : "post",
            complete : function(ret) {
                var ret = eval("(" + ret.responseText + ")");
                alert(ret.isOk);
                $("#MyDiv").hide();
                myGrid.trigger("reloadGrid");
            }
        });
    }
    function toFenpei(orderId) {
        $("#MyDiv").show();
        $("#oid").html(orderId);
        $.ajax({
            dataType : "json",
            url : "${contextPath}/ssdb/gendan/getKefuList",
            type : "get",
            complete : function(ret) {
                var ret = eval("(" + ret.responseText + ")");
                //alert(ret);
                var res = "<select id='fenpei' class=\"select form-control  \">";
                //console.log(ret);
                for (var i = 0 ; i < ret.length; i++){
                    res +="<option value="+ret[i]+">" +ret[i] + "</option>";
                }
                res += "</select>";
                //document.getElementById("kefuList").innerHTML =ret;
                    $("#getKefuList").html(res);
            }
        });
    }

    function choose_fp() {
        $("#modal-refund-body").modal("toggle");
        $.ajax({
            dataType : "json",
            url : "${contextPath}/ssdb/gendan/getfp",
            type : "get",
            complete : function(ret) {
                console.log(ret);
                var ret = eval("(" + ret.responseText + ")");
                console.log(ret.message);
                $("#fp").val(ret.message);
            }
        });
    }

    function toChoose() {
        var fp = $("#fp").val();
        $.ajax({
            dataType : "json",
            url : "${contextPath}/ssdb/gendan/changeFp",
            data :{"fp":fp,},
            type : "get",
            complete : function(ret) {
                var ret = eval("(" + ret.responseText + ")");
                alert(ret.message);
                $("#modal-refund-body").modal("toggle");
            }
        });
    }


</script>