<%@ 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/ui.jqgrid.css" />

<div class="row">
	<div class="col-xs-12">
	
				<div class="dropdown">
					关键字:<input id="keyword" class="input-medium search-query" type="text" /> 
			<button id="searchd" type="submit" class="btn" onClick="searchd">搜索</button>
			
		<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 -->

<!-- page specific plugin scripts -->
<script type="text/javascript">
	var myGrid = null;
	var scripts = [ null, "${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";

    		// resize to fit page size
    		$(window).on("resize.jqGrid", function() {
    			$(grid_selector).jqGrid("setGridWidth", $(".page-content").width());
    		})
    		// resize on sidebar collapse/expand
    		var parent_column = $(grid_selector).closest("[class*='col-']");
    		$(document).on("settings.ace.jqGrid", function(ev, event_name, collapsed) {
    			if (event_name === "sidebar_collapsed" || event_name === "main_container_fixed") {
    				// setTimeout is for webkit only to give time for DOM changes and then redraw!!!
    				setTimeout(function() {
    					$(grid_selector).jqGrid("setGridWidth", parent_column.width());
    				}, 0);
    			}
    		});
    		
    		$(document).keydown(function(event) {
				var key = window.event ? event.keyCode : event.which;
				if (key == 13) {
					$("#searchd").click();
				}
			});
    		
    		$("#searchd").click(function(){
				var keyword = $("#keyword").val();
		    	myGrid.setGridParam({postData:{'keyword':keyword},url : '${contextPath}/sys/lawyerIncome/getLawyerIncome'}).trigger('reloadGrid');
		   	});
    		
    		myGrid=	jQuery(grid_selector).jqGrid({
    			subGrid : false,
    			url : "${contextPath}/sys/lawyerIncome/getLawyerIncome",//
    			datatype : "json",
    			height : 450,
    			colNames : ["时间", "律师名", "订单号", "订单金额", "收入金额", "当事人公司", "当事人姓名"],
    			colModel : [{
    				name : "createDate",
    				index : "createDate",
    				label : "时间",
    				width : 150,
    				sorttype : "date",
    				search : false
    			}, {
    				name : "lawyer_realName",
    				index : "lawyer_realName",
    				label : "律师名",
    				width : 80,
    				search : false
    			}, {
    				name : "id",//contactIdentity
    				index : "id",
    				label : "订单号",
    				width : 150,
    				searchoptions : {sopt : ["cn"]},
    			}, {
    				name : "moneySell",// author
    				index : "moneySell",
    				label : "订单金额",
    				width : 110,
    				search : false,
    			}, {
    				name : "moneyPay",
    				index : "moneyPay",
    				label : "收入金额", /*  company contactName */
    				width : 110,
    				search : false
    			}, {
    				name : "company_name",
    				index : "company_name",
    				label : "当事人公司",/* lawyer realName */
    				width : 200,
    				search : false,
    			}, {
    				name : "contactName",
    				index : "contactName",
    				label : "当事人姓名 ",
    				width : 110,
    				search : false
    			}],
    			//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,
    			//toppager : true,
    			multiselect : false,
    			//multikey : "ctrlKey",
    	        multiboxonly : true,
    			loadComplete : function() {
    				var table = this;
    				setTimeout(function(){
    					styleCheckbox(table);
    					updateActionIcons(table);
    					updatePagerIcons(table);
    					enableTooltips(table);
    				}, 0);
    			},
    			editurl : "${contextPath}/sys/order/operateOrderBase"
    			//caption : "用户管理列表",
    			//autowidth : true,
    			/**
    			grouping : true, 
    			groupingView : { 
    				 groupField : ["name"],
    				 groupDataSorted : true,
    				 plusicon : "fa fa-chevron-down bigger-110",
    				 minusicon : "fa fa-chevron-up bigger-110"
    			},
    			*/
    		});
    		
    		$(window).triggerHandler("resize.jqGrid");
    		
    		// it causes some flicker when reloading or navigating grid
    		// it may be possible to have some custom formatter to do this as the grid is being created to prevent this
    		// or go back to default browser checkbox styles for the grid
    		function styleCheckbox(table) {
    			/**
    			 * $(table).find("input:checkbox").addClass("ace") .wrap("<label />") .after("<span class="lbl align-top" />") $(".ui-jqgrid-labels th[id*="_cb"]:first-child")
    			 * .find("input.cbox[type=checkbox]").addClass("ace") .wrap("<label />").after("<span class="lbl align-top" />");
    			 */
    		}

    		// unlike navButtons icons, action icons in rows seem to be hard-coded
    		// you can change them like this in here if you want
    		function updateActionIcons(table) {
    			/**
    			 * var replacement = { "ui-ace-icon fa fa-pencil" : "ace-icon fa fa-pencil blue", "ui-ace-icon fa fa-trash-o" : "ace-icon fa fa-trash-o red", "ui-icon-disk" : "ace-icon fa fa-check green", "ui-icon-cancel" :
    			 * "ace-icon fa fa-times red" }; $(table).find(".ui-pg-div span.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]); })
    			 */
    		}

    		// replace icons with FontAwesome icons like above
    		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"
    			});
    		}

    		// var selr = jQuery(grid_selector).jqGrid("getGridParam","selrow");

    		$(document).one("ajaxloadstart.page", function(e) {
    			$(grid_selector).jqGrid("GridUnload");
    			$(".ui-jqdialog").remove();
    		});
		});
	});
</script>
