<%@ 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>
.hr-line-dashed {
	background-color: #ffffff;
	border-top: 1px dashed #e7eaec;
	color: #ffffff;
	height: 1px;
	margin: 20px 0;
}
</style>

<div class="well well-sm">
	<input type="text" class="input-sm" placeholder="搜索关键字" id="keyword" />
	请选择时间
	<select id="typeDate">
		<option value="">全部</option>
		<option value="0">申请立案费时间</option>
		<option value="1">申请保全费时间</option>
	</select>
	<input type="text" class="input-sm" placeholder="开始时间" id="startDate"/>
	<input type="text" class="input-sm" placeholder="结束时间" id="endDate"/>
	立案费状态
	<select id="checkStateSsf">
		<option value="">全部</option>
		<option value="0">待审核</option>
		<option value="1">审核不通过</option>
		<option value="2">待支付</option>
		<option value="3">已支付</option>
	</select>
	保全费状态
	<select id="checkStateBqf">
		<option value="">全部</option>
		<option value="0">待审核</option>
		<option value="1">审核不通过</option>
		<option value="2">待支付</option>
		<option value="3">已支付</option>
	</select>
	诉保状态
	<select id="sbfState">
		<option value="">全部</option>
		<option value="0">未委托</option>
		<option value="1">已委托</option>
	</select>
	担保费支付状态
	<select id="dbfState">
		<option value="">全部</option>
		<option value="0">待支付</option>
		<option value="1">已支付</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>	
</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="modal-table" class="modal fade" tabindex="-1"
	data-backdrop="static">
	<div class="modal-dialog" style="min-width: 650px;">
		<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" id="modal-table-body"
				style="max-height: 500px;overflow-y: scroll;">
			</div>
		</div>
	</div>
</div>

<div id="modal-edit-order" class="modal fade" tabindex="-1"
	data-backdrop="static">
	<div class="modal-dialog" style="min-width: 400px;">
		<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" id="modal-edit-order-body">
				<form id="editOrderForm" class="form-horizontal">
					<input type="hidden" name="orderId" id="mod-edit-orderId" />
					<div class="form-group" id="mod-edit-fromName-div">
						<label class="col-sm-2 control-label">立案费:</label>
						<div class="col-sm-10 text-left">
							<input type="text" id="mod-edit-ssf" class="form-control" />
						</div>
					</div>
					<div class="form-group" id="mod-edit-toName-div">
						<label class="col-sm-2 control-label">保全费:</label>
						<div class="col-sm-10 text-left">
							<input type="text" id="mod-edit-bqf" class="form-control" />
						</div>
					</div>
					<div class="form-group" id="mod-edit-serviceTerm-div">
						<label class="col-sm-2 control-label">担保费:</label>
						<div class="col-sm-10 text-left">							
							<input type="text" id="mod-edit-dbf" class="form-control" />
						</div>
					</div>
					<div class="form-group" id="mod-edit-remark-div">
						<label class="col-sm-2 control-label">追加备注:</label>
						<div class="col-sm-10 text-left">
							<input type="text" id="mod-edit-remark" class="form-control" />
						</div>
					</div>
					<div class="form-group" id="mod-edit-updateLog-div">
						<label class="col-sm-2 control-label">修改记录:</label>
						<div class="col-sm-10 text-left" id="mod-edit-updateLog">
						</div>
					</div>
				</form>
			</div>
			<div class="modal-footer no-margin-top">
				<div class="text-center">
					<button id="modal-edit-order-submit" type="button"
						class="btn btn-sm btn-primary">
						<i class="ace-icon fa fa-floppy-o bigger-160"></i> 保存
					</button>
					<button class="btn btn-sm" data-dismiss="modal">
						<i class="ace-icon fa fa-share bigger-160"></i> 取消
					</button>
				</div>
			</div>
		</div>
	</div>
</div>



<div id="modal-check" class="modal fade" tabindex="-1"
	data-backdrop="static">
	<div class="modal-dialog" style="min-width: 400px;">
		<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" id="modal-check-body">
				<form id="checkOrderForm" class="form-horizontal">
					<input type="hidden" name="orderId" id="mod-check-orderId" />
					<input type="hidden" id="mod-check-type" />
					<div class="form-group" id="mod-edit-fromName-div">
						<label class="col-sm-2 control-label">缴费单:</label>
						<div class="col-sm-10 text-left">
				            <label class="control-label text-left" id="mod-check-ssf"></label>
						</div>
					</div>	
					<div class="form-group" id="mod-edit-fromName-div">
						<label class="col-sm-2 control-label">保全单:</label>
						<div class="col-sm-10 text-left">
				            <label class="control-label text-left" id="mod-check-bqf"></label>
						</div>
					</div>
					<div class="form-group" id="mod-edit-fromName-div">
						<label class="col-sm-2 control-label">判决书:</label>
						<div class="col-sm-10 text-left">
				            <label class="control-label text-left" id="mod-check-pjs"></label>
						</div>
					</div>					
					<div class="form-group" id="mod-edit-remark-div">
						<label class="col-sm-2 control-label">审核反馈:</label>
						<div class="col-sm-10 text-left">
							<textarea rows="4" id="mod-check-logContent" class="form-control" />
						</div>
					</div>					
					<div class="form-group" id="mod-edit-updateLog-div">
					<label class="col-sm-2 control-label">审核记录:</label>
						<div class="col-sm-10 text-left" id="mod-check-log">
						</div>
					</div>
				</form>
			</div>
			<div class="modal-footer no-margin-top">
				<div class="text-center">
					<button id="modal-check-submit-y" type="button"
						class="btn btn-sm btn-primary">
						<i class="ace-icon fa fa-floppy-o bigger-160"></i> 通 过
					</button>
					<button id="modal-check-submit-n" type="button"
						class="btn btn-sm btn-primary">
						<i class="ace-icon fa fa-floppy-o bigger-160"></i> 不 通 过
					</button>
					<button class="btn btn-sm" data-dismiss="modal">
						<i class="ace-icon fa fa-share bigger-160"></i> 取 消
					</button>
				</div>
			</div>
		</div>
	</div>
</div>

<%@include file="/WEB-INF/page/back/auth.jsp"%>

<!-- page specific plugin scripts -->
<script type="text/javascript">
		var hiddenModalBody = null;
		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", "${contextPath}/static/assets/js/lazyload/jquery.lazyload.js", null ]
        $('.page-content-area').ace_ajax('loadScripts', scripts, function() {
        	// inline scripts related to this page
        	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);
        			}
        		});
        		
			$("#searchd").click(function(){
				var keyword =$("#keyword").val();
				var param = {
					'keyword':keyword,
					'typeDate':$("#typeDate").val(),
					'startDate':$("#startDate").val(),
					'endDate':$("#endDate").val(),
					'checkStateSsf':$("#checkStateSsf").val(),
					'checkStateBqf':$("#checkStateBqf").val(),
					'sbfState':$("#sbfState").val(),
					'dbfState':$("#dbfState").val()
				}
		    	myGrid.setGridParam({postData:param,url : '${contextPath}/sys/ssbOrder/getApplyFees'}).trigger('reloadGrid');
		   	});
        	myGrid = jQuery(grid_selector).jqGrid({
        			subGrid : false,
        			url : "${contextPath}/sys/ssbOrder/getApplyFees",
        			datatype : "json",
        			height : "auto",
        			mtype: 'POST',        			
        			colModel : [ {
        				name : 'adSsf',//1449829970000
        				index : 'adSsf',
        				label :  '申请立案费时间',
        				width : 120,
        				search : false,
        				editable : false,
        				formatter : formatCreateDate
        			},{
        				name : 'adBqf',
        				index : 'adBqf',
        				label : '申请保全费时间',
        				width : 120,
        				search : false,
        				editable : false,
        			},{
        				name : 'orderId',
        				index : 'orderId',
        				label : '订单号',
        				width : 120,
        				search : false,
        				editable : false,
        			},{
        				name : 'userName',
        				index : 'userName',
        				label : '用户',
        				width : 120,
        				editable : false
        			},{
        				name : 'userPhone',
        				index : 'userPhone',
        				label : '号码',
        				width : 120,
        				editable : false,
        			}, {
        				name : 'serviceTerm',
        				index :'serviceTerm',
        				label : '服务有效期',
        				width :120,
        				editable : false,
        			}, {
        				name : 'ssf',
        				index :'ssf',
        				label : '立案费',
        				width :120,
        				editable : false,
        			}, {
        				name : 'checkStateSsf',
        				index :'fwfbl',
        				label : '立案费状态',
        				width :120,
        				formatter:checkState,
        				editable : false
        			}, {
        				name : 'bqf',
        				index :'bqf',
        				label : '保全费',
        				width :120,
        				editable : false,
        			}, {
        				name : 'checkStateBqf',
        				index :'checkStateBqf',
        				label : '保全费状态',
        				width :120,
        				editable : false,
        				formatter:checkState
        			},  {
        				name : 'sbStateDesc',
        				index :'sbStateDesc',
        				label : '诉保委托状态',
        				width :120,
        				editable : false,
        			}, {
        				name : 'dbf',
        				index :'dbf',
        				label : '担保费',
        				width :120,
        				editable : false,
        			}, {
        				name : 'dbfState',
        				index :'dbfState',
        				label : '担保费支付状态',
        				editable : false,
        				formatter:checkState
        			}, {
        				name : 'remark',
        				index :'remark',
        				label : '备注',
        				editable : false,
        			},{
         				name : 'id',
         				index : '',
         				label : '操作',
         				width : 140,
         				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,
        			//toppager : true,
        			//multiselect : true,
        			//multikey : "ctrlKey",
        	        //multiboxonly : true,
        			loadComplete : function() {
        				var table = this;
        				setTimeout(function(){
        					styleCheckbox(table);
        					updateActionIcons(table);
        					updatePagerIcons(table);
        					enableTooltips(table);
        				}, 0);
        			},
        			//caption : "用户管理列表",
        			//autowidth : true,
        			/**
        			grouping : true, 
        			groupingView : { 
        				 groupField : ['name'],
        				 groupDataSorted : true,
        				 plusicon : 'fa fa-chevron-down bigger-110',
        				 minusicon : 'fa fa-chevron-up bigger-110'
        			},
        			*/
        		});
        	
	        	function checkState(cellvalue, options, rowObject){
	     			if(cellvalue==0)
						return "待审核";
	     			if(cellvalue==1)
						return "审核不通过";
	     			if(cellvalue==2)
						return "审核通过待付款";
	     			if(cellvalue==3)
						return "已付款";
					return "";
				}
	        	
	        	function formatCreateDate(cellvalue, options, rowObject){
	        		var result = "";
	        		if(cellvalue != null){
	        			var d = new Date(cellvalue);
	        			result = d.getFullYear() + '-' + formatDate(d.getMonth() + 1) + "-" + formatDate(d.getDate()) + ' ' + formatDate(d.getHours()) + ":" + formatDate(d.getMinutes()) + ":" + formatDate(d.getSeconds());
	        		}
	        		return result;
	        	}
	        	
	        	function formatDate(d){
	        		var result = "";
	        		if(d > 9){
	        			result = d.toString();
	        		}else{
	        			result = '0' + d.toString();
	        		}
	        		return result;
	        	}
	        	
	        	function formatPayType(cellvalue, options, rowObject){
	        		var result = "";
	        		if(cellvalue == 0){
	        			result = "线下转账";
	        		}else if(cellvalue == 1){
	        			result = "微信";
	        		}else if(cellvalue == 2){
	        			result = "支付宝";
	        		}
	        		return result;
	        	}

	     		function optionFormatter(cellvalue, options, cell) {
	     			var template = "<button data-toggle='modal' onclick='showdetail(\""+cell.orderId+"\")' class='btn btn-minier btn-yellow'><i class='ace-icon fa fa-hdd-o '></i>详细</button>&nbsp;|&nbsp;";
	     			template += "<button data-toggle='modal' onclick='showCheckSsf(\""+cell.orderId+"\")' class='btn btn-minier btn-yellow'><i class='ace-icon fa fa-hdd-o '></i>审立案费</button>&nbsp;|&nbsp;";
	     			template+="<br/>";
	     			template += "<button data-toggle='modal' onclick='showEditOrder(\""+cell.orderId+"\")' class='btn btn-minier btn-yellow'><i class='ace-icon fa fa-hdd-o '></i>修改</button>&nbsp;|&nbsp;";
	     			template += "<button data-toggle='modal' onclick='showCheckBqf(\""+cell.orderId+"\")' class='btn btn-minier btn-yellow'><i class='ace-icon fa fa-hdd-o '></i>审保全费</button>&nbsp;|&nbsp;";
	     			return template;
	     		}
	     		
        		$(window).triggerHandler('resize.jqGrid');// trigger window resize to make the grid get the correct size
        		// enable search/filter toolbar
        		// jQuery(grid_selector).jqGrid('filterToolbar',{defaultSearch:true,stringResult:true})
        		// jQuery(grid_selector).filterToolbar({});
        		// switch element when editing inline
        		function aceSwitch(cellvalue, options, cell) {
        			setTimeout(function() {
        				$(cell).find('input[type=checkbox]').addClass('ace ace-switch ace-switch-5').after('<span class="lbl"></span>');
        			}, 0);
        		}
        		// navButtons
        		jQuery(grid_selector).jqGrid('navGrid', pager_selector, { // navbar options
        			edit : false,
        			editicon : 'ace-icon fa fa-pencil blue',
        			add : false,
        			addicon : 'ace-icon fa fa-plus-circle purple',
        			del : false,
        			delicon : 'ace-icon fa fa-trash-o red',
        			search : false,
        			searchicon : 'ace-icon fa fa-search orange',
        			refresh : true,
        			refreshicon : 'ace-icon fa fa-refresh blue',
        			view : false,
        			viewicon : 'ace-icon fa fa-search-plus grey'
        		}, {
        			// edit record form
        			// closeAfterEdit: true,
        			// width: 700,
        			recreateForm : true,
        			beforeShowForm : function(e) {
        				var form = $(e[0]);
        				form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar').wrapInner('<div class="widget-header" />')
        				style_edit_form(form);
        			},
    				errorTextFormat: function (response) {
    					var result = eval('('+response.responseText+')');
    				    return result.message;
    				}
        		}, {
        			// new record form
        			// width: 700,
        			closeAfterAdd : true,
        			recreateForm : true,
        			viewPagerButtons : false,
        			beforeShowForm : function(e) {
        				var form = $(e[0]);
        				form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar').wrapInner('<div class="widget-header" />')
        				style_edit_form(form);
        			},
    				errorTextFormat: function (response) {
    					var result = eval('('+response.responseText+')');
    				    return result.message;
    				}
        		}, {
        			// delete record form
        			recreateForm : true,
        			beforeShowForm : function(e) {
        				var form = $(e[0]);
        				if (form.data('styled'))
        					return false;
        				form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar').wrapInner('<div class="widget-header" />')
        				style_delete_form(form);
        				form.data('styled', true);
        			},
        			onClick : function(e) {
        				// alert(1);
        			}
        		}, {
        			// search form
        			recreateForm : true,
        			afterShowSearch : function(e) {
        				var form = $(e[0]);
        				form.closest('.ui-jqdialog').find('.ui-jqdialog-title').wrap('<div class="widget-header" />')
        				style_search_form(form);
        			},
        			afterRedraw : function() {
        				style_search_filters($(this));
        			},
        			multipleSearch : true 
	        		/**
	        		 * multipleGroup:true, showQuery: true
	        		 */
        		}, {
        			// view record form
        			recreateForm : true,
        			beforeShowForm : function(e) {
        				var form = $(e[0]);
        				form.closest('.ui-jqdialog').find('.ui-jqdialog-title').wrap('<div class="widget-header" />')
        			}
        		})
        		
        		
        		function style_edit_form(form) {
        			// form.find('input[name=statusCn]').addClass('ace ace-switch ace-switch-5').after('<span class="lbl"></span>');
        			// don't wrap inside a label element, the checkbox value won't be submitted (POST'ed)
        			// .addClass('ace ace-switch ace-switch-5').wrap('<label class="inline" />').after('<span class="lbl"></span>');

        			// update buttons classes
        			var buttons = form.next().find('.EditButton .fm-button');
        			buttons.addClass('btn btn-sm').find('[class*="-icon"]').hide();// ui-icon, s-icon
        			buttons.eq(0).addClass('btn-primary').prepend('<i class="ace-icon fa fa-check"></i>');
        			buttons.eq(1).prepend('<i class="ace-icon fa fa-times"></i>')

        			buttons = form.next().find('.navButton a');
        			buttons.find('.ui-icon').hide();
        			buttons.eq(0).append('<i class="ace-icon fa fa-chevron-left"></i>');
        			buttons.eq(1).append('<i class="ace-icon fa fa-chevron-right"></i>');
        		}

        		function style_delete_form(form) {
        			var buttons = form.next().find('.EditButton .fm-button');
        			buttons.addClass('btn btn-sm btn-white btn-round').find('[class*="-icon"]').hide();// ui-icon, s-icon
        			buttons.eq(0).addClass('btn-danger').prepend('<i class="ace-icon fa fa-trash-o"></i>');
        			buttons.eq(1).addClass('btn-default').prepend('<i class="ace-icon fa fa-times"></i>')
        		}

        		function style_search_filters(form) {
        			form.find('.delete-rule').val('X');
        			form.find('.add-rule').addClass('btn btn-xs btn-primary');
        			form.find('.add-group').addClass('btn btn-xs btn-success');
        			form.find('.delete-group').addClass('btn btn-xs btn-danger');
        		}
        		function style_search_form(form) {
        			var dialog = form.closest('.ui-jqdialog');
        			var buttons = dialog.find('.EditTable')
        			buttons.find('.EditButton a[id*="_reset"]').addClass('btn btn-sm btn-info').find('.ui-icon').attr('class', 'ace-icon fa fa-retweet');
        			buttons.find('.EditButton a[id*="_query"]').addClass('btn btn-sm btn-inverse').find('.ui-icon').attr('class', 'ace-icon fa fa-comment-o');
        			buttons.find('.EditButton a[id*="_search"]').addClass('btn btn-sm btn-purple').find('.ui-icon').attr('class', 'ace-icon fa fa-search');
        		}

        		function beforeDeleteCallback(e) {
        			var form = $(e[0]);
        			if (form.data('styled'))
        				return false;
        			form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar').wrapInner('<div class="widget-header" />')
        			style_delete_form(form);
        			form.data('styled', true);
        		}

        		function beforeEditCallback(e) {
        			var form = $(e[0]);
        			form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar').wrapInner('<div class="widget-header" />')
        			style_edit_form(form);
        		}

        		// 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'
        			});
        		}

        		$(document).one('ajaxloadstart.page', function(e) {
       			$(grid_selector).jqGrid('GridUnload');
       			$('.ui-jqdialog').remove();
        		});
        		
        		$('#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"
    		    });
    		    $('#sendStart').datepicker({
    		        language: 'zh-CN',
    		        pickTime: false,
    		        todayBtn: true,
    		        autoclose: true,
    		        minView: '2',
    		        forceParse: false,
    		        format:"yyyy-mm-dd"
    		    });
    			$('#sendEnd').datepicker({
    		        language: 'zh-CN',
    		        pickTime: false,
    		        todayBtn: true,
    		        autoclose: true,
    		        minView: '2',
    		        forceParse: false,
    		        format:"yyyy-mm-dd"
    		    });
        	});
        });
		
		$(function(){
			hiddenModalBody = '<div class="row">'
				              + '<label class="col-sm-3 control-label">立案费缴费记录:</label>'
				              + '<label class="control-label text-left" id="mt-ssfAttachs"  attachType=121 ></label>'
				            + '</div>'
				            + '<div class="row">'
				              + '<label class="col-sm-3 control-label">保全费缴费记录:</label>'
				              + '<label class="control-label text-left" id="mt-bqfAttachs" attachType=121 ></label>'
				            + '</div>'
				            + '<div class="row">'
				              + '<label class="col-sm-3 control-label">判决书:</label>'
				              + '<label class="control-label text-left" id="mt-pjsAttachs" attachType=111 ></label>'
				            + '</div>'
				            + '<div class="row">'
				              + '<label class="col-sm-3 control-label">帐户名:</label>'
				              + '<label class="control-label text-left" id="mt-accountName"></label>'
				            + '</div>'
				            + '<div class="row">'
				              + '<label class="col-sm-3 control-label">帐号:</label>'
				              + '<label class="control-label text-left" id="mt-account"></label>'
				            + '</div>'
				            + '<div class="row">'
				              + '<label class="col-sm-3 control-label">开户行:</label>'
				              + '<label class="control-label text-left" id="mt-bankName"></label>'
				            + '</div>';
		});
		
		$('#modal-edit-order-submit').click(function(event) {
 			editOrder();
		});
		
		function editOrder(){
			var ssf = $('#mod-edit-ssf').val();
			var bqf = $('#mod-edit-bqf').val();
			var dbf = $('#mod-edit-dbf').val();
			if(ssf==null || ssf==""){
				alert("诉讼费不能为空！")
				return;
			}
			if(bqf==null || bqf==""){
				alert("保全费不能为空！")
				return;
			}
			if(dbf==null || dbf==""){
				alert("担保费不能为空！")
				return;
			}
			$.post("${contextPath}/sys/ssbOrder/editApplyFee", {
				'orderId' : $('#mod-edit-orderId').val(),
				'ssf' : $('#mod-edit-ssf').val(),
				'bqf' : $('#mod-edit-bqf').val(),
				'dbf' : $('#mod-edit-dbf').val(),
				'remark' : $('#mod-edit-remark').val(),
			}, function(ret){
				if(ret && ret.success){					
					$("#modal-edit-order").modal("toggle");
					myGrid.trigger("reloadGrid");
				}else{
					alert(ret.message);
				}
			});
		}
		
		function initModalTableBody(){
			$('#modal-table-body').html(hiddenModalBody);
		}
		
		function showdetail(id){
			$('#modal-table-body').html('');
			$.post("${contextPath}/sys/ssbOrder/getApplyFeeInfo", {
				'orderId' : id
			}, function(ret){
				if(ret.success){
					initModalTableBody();
					var keyObj = {"bankName":"mt-bankName","account":"mt-account","accountName":"mt-accountName"};
					for(var key in keyObj){
						$('#' + keyObj[key]).html(ret[key]);
					}
					var htmlPjs='',htmlSsf='',htmlBqf = '';
					for(var m in ret.attas){
						var oa = ret.attas[m];
						if(oa.attachType==111){
							htmlPjs += getImgHtml(oa.path, oa.pathSL);
						}else if(oa.attachType==121){
							htmlSsf += getImgHtml(oa.path, oa.pathSL);
						}else if(oa.attachType==221){
							htmlBqf += getImgHtml(oa.path, oa.pathSL);
						}
					}						
					$("#mt-pjsAttachs").html(htmlPjs);
					$("#mt-ssfAttachs").html(htmlSsf);
					$("#mt-bqfAttachs").html(htmlBqf);					
					$("#modal-table").modal("toggle");
				}else{
					alert(ret.message);
				}
			});			
		}

		function showCheckSsf(orderId){
			showCheck(orderId, 11, "缴费单");
		}
		function showCheckBqf(orderId){
			showCheck(orderId, 12, "保全单");			
		}
		
		function showCheck(orderId, type){
			$.post("${contextPath}/sys/ssbOrder/getApplyFeeInfo", {
				'orderId' : orderId,
				'type' : type
			}, function(ret){
				if(ret.success){
					var html = '';
					var htmlPjs='',htmlSsf='',htmlBqf = '';
					for(var m in ret.attas){
						var oa = ret.attas[m];
						if(oa.attachType==111){
							htmlPjs += getImgHtml(oa.path, oa.pathSL);
						}else if(oa.attachType==121){
							htmlSsf += getImgHtml(oa.path, oa.pathSL);
						}else if(oa.attachType==221){
							htmlBqf += getImgHtml(oa.path, oa.pathSL);
						}
					}
					if(type==11){
						$("#mod-check-bqf").html(htmlBqf).parent().parent().hide();
						$("#mod-check-ssf").html(htmlSsf).parent().parent().show();
					}else{
						$("#mod-check-ssf").html(htmlSsf).parent().parent().hide();
						$("#mod-check-bqf").html(htmlBqf).parent().parent().show();						
					}			
					$("#mod-check-pjs").html(htmlPjs);
					html = "";
					for(var m in ret.checkLogs){
						var clog = ret.checkLogs[m];
						if(type==clog.type){
							html += clog.createDate + " &nbsp; " + clog.operName + " &nbsp; " + clog.logContent + "<br/>";							
						}
					}				
					$("#mod-check-type").val(type);
					$('#mod-check-orderId').val(orderId);	
					$('#mod-check-log').html(html);	
					$('#mod-check-logContent').val('');
					$("#modal-check").modal("toggle");							
				}else{
					alert(ret.message);
				}
			});
		}
		
		$('#modal-check-submit-y').click(function(event) {
			checkApplyFee('y');
		});
		$('#modal-check-submit-n').click(function(event) {
			checkApplyFee('n');
		});
		
		function checkApplyFee(flag){
			if(flag=='n' && $("#mod-check-logContent").val()==''){
				alert("请输入反馈内容！");
				//$("#modal-check-order").modal("toggle");
				return;
			}
			if(confirm('n'==flag?"确定不通过？":"确定通过？")){
				$.post("${contextPath}/sys/ssbOrder/checkApplyFee", {
					'orderId' : $("#mod-check-orderId").val(),
					'flag' : flag,
					'type' : $("#mod-check-type").val(),
					'logContent' : $('#mod-check-logContent').val()
				}, function(ret){
					if(ret && ret.success){
						$("#modal-check").modal("toggle");
						myGrid.trigger("reloadGrid");
					}else{
						alert(ret.message);
					}
				});
			}			
		}
		
		function getImgHtml(path, pathSL){
			var html = '';
			html +='<a href="' + path + '" target="_blank">';
			html += '<img class="lazy" src="' + pathSL + '" height="100" width="100">';
			html +='</a>&nbsp;';
			return html;
		}

		function showEditOrder(orderId){
			$.post("${contextPath}/sys/ssbOrder/getApplyFeeUpdateInfo", {
				'orderId' : orderId
			}, function(ret){
				if(ret.success){
					$('#mod-edit-orderId').val(orderId);
					$('#mod-edit-ssf').val(ret.ssf);
					$('#mod-edit-bqf').val(ret.bqf);
					$('#mod-edit-dbf').val(ret.dbf);
					$('#mod-edit-remark').val(ret.remark);
					$('#mod-edit-updateLog').html(ret.updateLog==null?"":ret.updateLog);			
					$("#modal-edit-order").modal("toggle");
				}else{
					alert(ret.message);
				}
			});	
			
		}
		
		function formatStr(str){
			var result = '';
			if(str != undefined && str != null){
				result = str;
			}
			return result;
		}
		
		function isNotBlank(obj){
			var result = true;
			if(obj == undefined || obj == null || obj == 'null' || obj.length < 1){
				result = false;
			}
			return result;
		}

</script>
