<%@ 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{
        display: none;
        position: absolute;
        top: 0px;
        left: 300px;
        z-index: 666;
    }
</style>

<div style="background: rgba(1,1,2,0.05)">
    <br>
    关键字:<input id="keyword" placeholder="输入关键字搜索" class="input-medium search-query" type="text"/>
&nbsp;&nbsp;
    筛选日期：<input type="text" class="input-sm" placeholder="开始日期"  id="startDate"/>
    <input type="text" class="input-sm" placeholder="结束日期"  id="endDate"/>
    &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 -->

<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>
        <br>
        <br>
        <div id="pic">

        </div>

    </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 = $("#keyword").val();
                var startDate = $("#startDate").val();
                var endDate = $("#endDate").val();
                myGrid.setGridParam({postData:{startDate:startDate ,endDate:endDate,keyword:keyword ,page:1},
                    url : '${contextPath}/ads/vip/getAdsComplain',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}/ads/vip/getAdsComplain",
                datatype : "json",
                mtype:'POST',//设置http方式为post以解决乱码问题
                colNames : ['id','用户名','用户电话','投诉日期','投诉内容', '操作'],
                colModel : [{
                    name : 'id',
                    index : 'id',
                    width : 300,
                    search : false,
                    editable : false,
                    hidden:true
                    //sorttype : 'date'
                },{
                    name : 'userName',
                    index : 'userName',
                    width : 200,
                    search : false,
                    editable : false,
                    //sorttype : 'date'
                },{
                    name : 'phone',
                    index : 'phone',
                    width : 200,
                    search : false,
                    editable : false,
                    //sorttype : 'date'
                },{
                    name : 'createDate',
                    index : 'createDate',
                    width : 250,
                    search : false,
                    editable : false,
                    //sorttype : 'date'
                },{
                    name : 'content',
                    index : 'content',
                    width : 450,
                    search : false,
                    editable : false,
                    //sorttype : 'date'
                },{	name : 'type',
                    index : 'type',
                    label : '操作',
                    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 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='showPic(\""+cell.id+"\")' class='btn btn-minier btn-default'>查看图片</button>";
                return template;
            };

        });
    });
    function showPic(id) {
        $("#pic").html("")
        $.ajax({
            dataType : "json",
            url : "${contextPath}/ads/vip/getComplainPic",
            type : "post",
            data : {
                'id' : id
            },
            complete : function(ret) {
                console.log(ret);
                var ret = eval("(" + ret.responseText + ")");
                var all = "";
                if (ret !== 0){
                    for (var i = 0 ; i < ret.length;i++){
                        all += "<a href='"+ret[i]+"' target='newPic'>" +
                            "<img src='"+ret[i]+"' width='200px' height='200px'/>" +
                            "<a/>"
                    }
                    $("#pic").html(all)
                }else{
                    $("#pic").html("")
                }
            }
        });
        $("#MyDiv").show();
    }

    function CloseDiv() {
        $("#MyDiv").hide();
    }

</script>

