<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<c:set var="contextPath" value="${pageContext.request.contextPath}"></c:set>

<%@include file="/WEB-INF/page/header.jsp" %>
<script>changeMenu(5,1);//左边菜单active</script>
<div class="row white-bg border-bottom white-bg page-heading">
	<div class="col-lg-12">
		<h2>保单信息</h2>
		<ol class="breadcrumb">
			<li>主页</li>
			<li><a>保单信息</a></li>
			<li class="active" id="navigationList"><strong>待审核</strong></li>
			<li id="navigationReview1" style="display:none">待审核</li>
			<li class="active" id="navigationReview2" style="display:none"><strong>审核资料</strong></li>
		</ol>
	</div>
</div>

<div class="wrapper wrapper-content">
	<div class="row">
		<div class="col-lg-12" id="gridTable1List">
			<div class="ibox float-e-margins">
				<div class="ibox-content">
					 <div class="row">
                        <div class="col-sm-2">
                        	<div class="input-group m-b"><span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        	<input type="text" class="input-sm form-control" placeholder="订单日期" id="searchDate">
                        	</div>
                        </div>
                        <div class="col-sm-3">
                            <div class="input-group"><input type="text" id="keyword" placeholder="订单号、法院" class="input-sm form-control"><span class="input-group-btn">
                                <button type="button" class="btn btn-sm btn-primary" onclick="search()"> 查询</button> </span></div>
                        </div>
                    </div>
					<div class="row">
						<div class="col-md-12 jqGrid_wrapper">
							<table id="gridTable1"></table>
							<div id="gridPager1"></div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
	
	<div class="row" id="gridTable1Review" style="display:none">
		<div class="col-lg-12">
			<div class="ibox float-e-margins">
				<div class="ibox-content" id= "gridTable1ReviewDetail">
				</div>
			</div>
		</div>
	</div>
</div>

<div id="modal-reviewFail" class="modal fade" tabindex="-1">
	<div class="modal-dialog" style="max-width: 400px;">
		<div class="modal-content">
			<div class="modal-header">
      			<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">
	      		<div class="form-group">失败原因：</div>
	      		<div class="form-group"><textarea cols="39" rows="5" id="reviewFailReason"></textarea></div>
	      	</div>
	      	<div class="modal-footer">
                <button class="btn " data-dismiss="modal"><i class="fa fa-share bigger-160"></i>取消</button>
	      		<button class="btn btn-primary" type="button" id="mod-reviewFail-submit"><strong><i class="fa fa-floppy-o bigger-160"></i>确定</strong></button>
			</div>
		</div>
	</div>
</div>

<div id="modal-replyLawyer" class="modal fade" tabindex="-1">
	<div class="modal-dialog" style="max-width: 400px;">
		<div class="modal-content">
			<div class="modal-header">
      			<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-replyLawyer-body"></div>
	      	<div class="modal-footer">
                <button class="btn " data-dismiss="modal"><i class="fa fa-share bigger-160"></i>取消</button>
	      		<button class="btn btn-primary" type="button" id="mod-replyLawyer-submit"><strong><i class="fa fa-floppy-o bigger-160"></i>确定</strong></button>
			</div>
		</div>
	</div>
</div>

<div id="mod-file" class="modal fade" tabindex="-1">
	<div class="modal-dialog" style="max-width: 500px;">
		<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">
				<div class="row">
					<div class="col-xs-12">
						<!-- PAGE CONTENT BEGINS -->
						<form id="fileform">
							<div class="col-xs-12">
								<input id="fileId" type="file" name="avatar" multiple />
								<input type="hidden" name="attachType" id="mod-file-attachType"/>
								<input type="hidden" name="orderId" id="mod-file-orderId"/>
							</div>
							<div class="col-xs-12">
								<select id="mod-file-accountSel" class="form-control input-sm"></select>
							</div>
							<div class="col-xs-12">
								<label class="col-sm-2 no-padding">银行账户:</label>
					      		<div class="col-sm-10 text-left no-padding">
					      			<input type="text" id="mod-file-accountNum" class="form-control" />
					      		</div>
							</div>
							<div class="col-xs-12">
								<label class="col-sm-2 no-padding">开户行:</label>
					      		<div class="col-sm-10 text-left no-padding">
					      			<input type="text" id="mod-file-accountBank" class="form-control" />
					      		</div>
							</div>
							<div class="col-xs-12">
								<label class="col-sm-2 no-padding">开户名:</label>
					      		<div class="col-sm-10 text-left no-padding">
					      			<input type="text" id="mod-file-accountName" class="form-control" />
					      		</div>
							</div>
							<div class="col-xs-12">
			      				<div class="hr hr-12 dotted"></div>
			      			</div>
							<div class="text-center">
								<button type="button" class="btn btn-sm btn-primary" onclick="fileUpload();">上传</button>
								<button type="reset" class="btn btn-sm">清除</button>
							</div>
						</form>
					</div><!-- /.col -->
				</div><!-- /.row -->
				
			</div>
		</div><!-- /.modal-content -->
	</div><!-- /.modal-dialog -->
</div>

<%@include file="/WEB-INF/page/order/orderDetail.jsp" %>

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

<link href="${contextPath}/static/css/plugins/jQueryUI/jquery-ui-1.10.4.custom.min.css" rel="stylesheet" />
<link href="${contextPath}/static/css/plugins/jqGrid/ui.jqgrid.css" rel="stylesheet">
<link href="${contextPath}/static/css/plugins/datapicker/datepicker3.css" rel="stylesheet">
<link href="${contextPath}/static/ssdb/ace.fileinput.css" rel="stylesheet"/>

<script src="${contextPath}/static/js/plugins/jqGrid/jquery.jqGrid.min.js"></script>
<script src="${contextPath}/static/js/plugins/jqGrid/i18n/grid.locale-cn.js"></script>
<!-- Data picker -->
<script src="${contextPath}/static/js/plugins/datapicker/bootstrap-datepicker.js"></script>

<script src="${contextPath}/static/js/plugins/lazyload/jquery.lazyload.js"></script>

<!-- 阿里OSS  JSSDK -->
<script type="text/javascript" src="${contextPath}/static/ssdb/promise-6.1.0.js"></script>
<script type="text/javascript" src="http://gosspublic.alicdn.com/aliyun-oss-sdk-4.3.0.min.js"></script>
<script type="text/javascript" src="${contextPath}/static/ssdb/ace.fileinput.js"></script>  
<script type="text/javascript" src="${contextPath}/static/ssdb/uuid.js"></script>
<script type="text/javascript" src="${contextPath}/static/ssdb/fileupload.js?v=2"></script>
   
<script type="text/javascript">
	var accountsObject = {};
	//oss
	var appServer = 'http://b.duowenlvshi.com/oss/token?name=ssdb';
    var bucket = '${oss_bucket_ssdb}';
    var region = 'oss-cn-shenzhen';
    var Buffer = OSS.Buffer;
    var OSS = OSS.Wrapper;
    var STS = OSS.STS;
    var applyTokenDo = function(func) {
        var url = appServer;
        $.ajax({
            type: "POST",
            url: url,
            data: "",
            dataType: "jsonp",
            success: function(e) {
                var client = new OSS({
                    region: region,
                    accessKeyId: e.AccessKeyId,
                    accessKeySecret: e.AccessKeySecret,
                    stsToken: e.SecurityToken,
                    bucket: bucket
                });
                return func(client);
            },
            error: function(data) {
                console.log(data);
            }
        });
    };
    
    var uploadFile = function(client) {
    	 var accountBank = $('#mod-file-accountBank').val();
    	 var accountName = $('#mod-file-accountName').val();
    	 var accountNum = $('#mod-file-accountNum').val();
    	 
		 var orderId=document.getElementById('mod-file-orderId').value;
		 var picfilenum =document.getElementById('fileId').files.length;
		 var keyArray ="";
		 var fileNameArray ="";
		 var fileTypeArray ="";
    	 for(var i=0;i<picfilenum;i++){
	    	 var picFile=document.getElementById('fileId').files[i];
	    	 var fileName = UUIDjs.create().hex;
	    	 var fileType = getFileType(picFile.name);
	    	 var oDate = new Date(); //实例一个时间对象；
	    	 var y = oDate.getFullYear();   //获取系统的年；
	    	 var m = oDate.getMonth()+1;   //获取系统月份，由于月份是从0开始计算，所以要加1
	    	 var d = oDate.getDate(); // 获取系统日
	         var key = "ssdb/order/${sessionScope.SESSION_COMPANY.id}/"+y+"/"+m+"/"+d+"/"+fileName+"."+fileType;
	         
	         client.multipartUpload(key, picFile, {
	            progress: progress
	        }).then(function(res) {
	        	
	        });
			if(i==picfilenum-1){
				keyArray += key;
				fileNameArray += fileName;
				fileTypeArray += fileType;
			}else{
				keyArray = keyArray + key +",";
				fileNameArray = fileNameArray+fileName+",";
				fileTypeArray = fileTypeArray+fileType+",";
			}
    	 }
    	 saveToDB(orderId,keyArray,fileNameArray,fileTypeArray,accountBank,accountName,accountNum);
    };
    
    var progress = function(p) {//上传成功的进度条
    	return function (done) {
  	 		 done();
  		};
    };
    
    var getFileURL = function(client) {
        console.log(client);
        var object = data[0].name;
        var filename = object.replace(/^.*[\\\/]/, '');
        console.log(object + ' => ' + filename);
        var result = client.signatureUrl(object, {
            response: {
                'content-disposition': 'attachment; filename="' + filename + '"'
            }
        });
        // fileRequest(result);
        //  return result;
    };
    
	var companyMaterialObj = {};
	var currentOrderId = null;
	var gridTable1 = null;
	var grid_selector = "#gridTable1";
	var notSubmitReplyLawyer = true;
    var notSubmitReviewFail = true;
    var notSubmitReviewPass = true;
    var pager_selector = "#gridPager1";
	jQuery(function($) {
		$('#searchDate').datepicker({
            todayBtn: "linked",
            keyboardNavigation: false,
            forceParse: false,
            calendarWeeks: true,
            autoclose: true,
            format: "yyyy-mm-dd"
        });
		
		initGridTable();
		// 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).one('ajaxloadstart.page', function(e) {
   			$(grid_selector).jqGrid('GridUnload');
   			$('.ui-jqdialog').remove();
   		});
   		
   		$('#mod-reviewFail-submit').on('click', function() {
   			reviewFailSubmit();
   		});
   		$('#mod-replyLawyer-submit').on('click', function() {
   			replyLawyerSubmit();
   		});
   		
	 	// Add responsive to jqGrid
        $(window).bind('resize', function () {
            var width = $('.jqGrid_wrapper').width();
            gridTable1.setGridWidth(width);
        });
	 	
        $('#mod-file-accountSel').change(function(){
        	onchangeAccountSel();
        }); 
	});	


	function errorCallbackDefault(data){
		
	}

    function getFileType(fileName){
    	var ldot = fileName.lastIndexOf('.')
    	if(ldot>=0)
    		return fileName.substring(ldot + 1);
    	else
    		return "";
    }
    
    function getBlankInfos(id){
    	accountsObject = {};
    	document.getElementById('mod-file-accountSel').innerHTML = '';
    	var url = '${contextPath}/order/getBlankInfos';
		var parameters = {"orderId":id};
		postData(url, parameters, getBlankInfosCallback, errorCallbackDefault);
    }

    function getBlankInfosCallback(data){
    	if(data.success){
    		document.getElementById("fileform").reset();
    		var html = '';
    		var info,v,t = null;
    		for(var i in data.accounts){
    			info = data.accounts[i];
    			//v = info.leval;
    			v = info.accountNum;
    			t = info.accountName;
    			if(v == 10){
    				t = '自定义';
    				b = true;
    			}
    			accountsObject[v] = info;
    			html += '<option value="' + v + '" >' + t + '</option>';
    		}
    		if(html.length > 0){
    			html = '<option value="" ></option>' + html;
    			document.getElementById('mod-file-accountSel').innerHTML = html;
    			
    			var obj = {'accountBank':'mod-file-accountBank','accountName':'mod-file-accountName','accountNum':'mod-file-accountNum'};
    			info = data.accounts[0];
	    		for(var o in obj){
	    			$('#' + obj[o]).val(info[o]);
	    		}
	    		//$('#mod-file-accountSel').val(info.leval);
	    		$('#mod-file-accountSel').val(info.accountNum);
    		}
        	$("#mod-file").modal("toggle");
    	}else{
			showMsg(data.message);
		}
    }
    
	//获取订单详情成功回调
	function getOrderDetailCallback(data){
		if(data.success){
			var divObj = $('#gridTable1ReviewDetail');
			var html = '<div class="row">'
						+ '<div class="col-md-2"><strong>订单号</strong></div>'
						+ '<div class="col-md-3"><strong>受理法院</strong></div>'
						+ '<div class="col-md-1"><strong>标的金额</strong>（元）</div>'
						+ '<div class="col-md-1"><strong>保费</strong>（元）</div>'
						+ '<div class="col-md-2"><strong>提交时间</strong></div>'
						+ '<div class="col-md-2"><strong>承诺审核时间</strong></div>'
						+ '<div class="col-md-1"><strong>申请人</strong></div>'
					+ '</div>';
			var o = data.order;
			html += '<div class="row">'
					+ '<div class="col-md-2">' + formatString(o.orderId) + '</div>'
					+ '<div class="col-md-3">' + formatString(o.courtName) + '</div>'
					+ '<div class="col-md-1">' + formatString(o.sqbd) + '</div>'
					+ '<div class="col-md-1">' + formatString(o.bf) + '</div>'
					+ '<div class="col-md-2">' + formatString(o.createDate) + '</div>'
					+ '<div class="col-md-2">' + formatString(o.lcDate) + '</div>'
					+ '<div class="col-md-1">' + formatString(o.contactName) + '</div>'
				   + '</div>'
				   + '<div class="hr-line-dashed"></div>';
			var a = data.attachs;
			var row = null;
			var aName = null;
			var oa = null;
			var i = 1;
			var url = '${oss_bucket_ssdb_url}';
			var thum = '${oss_bucket_ssdb_url_img}';
			var size = '${oss_bucket_ssdb_url_img_size}';
			for(var j in a){
				row = a[j];
				aName = formatString(row.name);
				if(aName.length > 0){
					companyMaterialObj[row.companyAttachId] = aName;
					html += '<div class="row">'
							+ '<div class="col-md-2">' + i + '、' + aName + '</div>'
							+ '<div class="col-md-10">';
					for(var m in row.attachs){
						oa = row.attachs[m];
						html +='<a href="' + url + oa.path + '" target="_blank">';
						html += '<img class="lazy" src="${contextPath}/static/img/loading.gif" data-original="' + thum + oa.path + size + oa.suffix.toLowerCase() + '" height="100" width="100">';
						html +='</a>&nbsp;';
					}			
					html +=   '</div>'
						  + '</div>'
						  + '<div class="hr-line-dashed"></div>';
					i++;
				}
			}
			html += '<div class="row">'
					+ '<div class="col-md-4"></div>'
					+ '<div class="col-md-1 text-center">'
						+ '<button class="btn btn-default" type="button" onClick="reviewFailPageShow()">结束订单</button>'
					+ '</div>'
					+ '<div class="col-md-2 text-center">'
						+ '<button class="btn btn-primary" type="button" onClick="replyLawyerPageShow()">资料审核问题反馈</button>'
					+ '</div>'
					+ '<div class="col-md-1 text-center">'
						+ '<button class="btn btn-primary" type="button" onClick="reviewPassSubmit()">审核通过</button>'
					+ '</div>'
					+ '<div class="col-md-4"></div>'
				   + '</div>';	
			html += '<div class="hr-line-dashed"></div>';
			html +=  '<div class="row"><div class="col-sm-12 text-left"><h5>律师反馈</h5></div></div>';
			for(var m in data.logReplys){
				row = data.logReplys[m];
				html += '<div class="row">'
			 			+ '<label class="col-sm-2 control-label">' + formatString(row.createDate) + '</label>'
			 			+ '<label class="col-sm-10 control-label text-right">' + row.content + '</label>'
			 	 	  + '</div>';
			}
			html += '<div class="hr-line-dashed"></div>';
			html += '<div class="row">'
						+ '<label class="col-sm-2">反馈信息:</label>'
						+ '<div class="col-sm-8 text-left no-padding">'
						+ 	'<input type="text" id="gridTable1Review-companyFeedback" class="form-control" />'
						+ '</div>'
						+ '<div class="col-sm-2 text-center no-padding">'
						+ 	'<button class="btn btn-default" type="button" onClick="saveCompanyFeedback()">保存</button>'
						+ '</div>'
				  + '</div>';
			divObj.html(html);
			setTimeout(function () {
				$("img.lazy").lazyload({
					threshold : 200
				});
			  }, 200);
		}else{
			showMsg(data.message);
		}
	}

	//文件上传处理
    function fileUpload() {
		var obj = {'mod-file-accountBank':'开户行','mod-file-accountName':'开户名','mod-file-accountNum':'银行账户'};
    	for(var o in obj){
    		if(isBlank($('#' + o).val())){
    			showMsg(obj[o] + '不能为空');
    			return;
    		}
    	}
        applyTokenDo(uploadFile);
    }

	function formatString(str){
		var result = '';
		if(str != undefined && str != null){
			result = str;
		}
		return result;
	}

	function initGridTable(){
		gridTable1 = jQuery(grid_selector).jqGrid({
			subGrid : false,
   			url : "${contextPath}/order/getOrders?orderState=0&orderServiceType=1",//
   			datatype : "json",
   			height : "auto",
   			autowidth:true,
   			colNames : ["公司名称", "订单号", "受理法院", "标的金额（元）", "标的类型", "保费（元）", "提交时间", "承诺审核时间","申请人","操作"],
   			colModel : [{
   				name : "companyName",
   				index : "companyName",
   				label : "公司名称",
   				width : 120,
   				search : false
        	},{
   				name : "orderId",
   				index : "orderId",
   				label : "订单号",
   				width : 100,
   				search : false
        	},{
   				name : "courtName",
   				index : "courtName",
   				label : "受理法院",
   				width : 160,
   				search : false
        	},{
   				name : "sqbd",
   				index : "sqbd",
   				label : "标的金额（元）",
   				width : 80,
   				search : false
        	},{
   				name : "bdCode",
   				index : "bdCode",
   				label : "标的类型",
   				width : 60,
   				sortable: false,
   				search : false
        	},{
   				name : "bf",
   				index : "bf",
   				label : "保费（元）",
   				width : 80,
   				search : false
        	},{
   				name : "createDate",
   				index : "createDate",
   				label : "提交时间",
   				width : 80,
   				search : false
        	},{
   				name : "lcDate",
   				index : "lcDate",
   				label : "承诺审核时间",
   				width : 80,
   				search : false
        	},{
   				name : "contactName",
   				index : "contactName",
   				label : "申请人",
   				width : 60,
   				search : false
        	},{
        		align : "center",
   				name : "checkState",
   				index : "checkState",
   				label : "操作",
   				width : 100,
   				viewable:false,
   				sortable: false,
   				fixed:true,
   				formatter:operationLink
        	}],
   			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,
   	     	rownumbers:true,  
         	rownumWidth:30, 
   	       
		});
	}

	function isBlank(obj){
		var result = false;
		if(obj == undefined || obj == null || obj == 'null' || obj.length < 1){
			result = true;
		}
		return result;
	}
	
	function onchangeAccountSel(){
		var obj = {'accountBank':'mod-file-accountBank','accountName':'mod-file-accountName','accountNum':'mod-file-accountNum'};
		var info = {'accountBank':'','accountName':'','accountNum':''};
		var v = $('#mod-file-accountSel').val();
		if(!isBlank(v)){
			info = accountsObject[v];
		}
		for(var o in obj){
			$('#' + obj[o]).val(info[o]);
		}
	}

	//向后台请求数据
	function postData(url, parameters, successCallback, errorCallback){
		$.ajax({
		    type : "POST",
		    url : url,
		    data : parameters,
		    dataType : "json",
		    success : function(data) {
		    	successCallback(data); 
		    },
		    error : function(data) {
		    	errorCallback(data);
		    }
	    }); 
	}
	
	//操作链接
	function operationLink(cellvalue, options, rowObject){
		var result = '';
		if('0' == cellvalue){
			result = '<a href="javascript:void(0);" style="color:blue" onclick="reviewOperation(\'' + rowObject.orderId + '\')">去审核</a>';
		}else{
			result = '待更新';
		}
		result += '&nbsp;|&nbsp;<a href="javascript:void(0);" style="color:blue" onclick="showdetail(\''+rowObject.orderId+'\')">详细</a>';
		return result;
	}
	
	function reloadGrid(){
		gridTable1.trigger('reloadGrid');
	}

	//保存反馈给律师信息成功后回调
	function replyLawyerCallback(data){
		notSubmitReplyLawyer = true;
		if(data.success){
			$("#modal-replyLawyer").modal('toggle');
			showMsg('保存成功');
			reloadGrid();
			reviewPageHide();
		}else{
			showMsg(data.message);
		}
	}

	//保存反馈给律师信息失败后回调
	function replyLawyerErrorCallback(data){
		notSubmitReplyLawyer = true;
	}
	
	//打开反馈给律师页面 
	function replyLawyerPageShow(){
		notSubmitReplyLawyer = true;
		var divObj = $("#modal-replyLawyer-body");
		divObj.html('');
		var html = '';
		var i = 1;
		for(var key in companyMaterialObj){
			html += '<div class="form-group">' + i + '、' + companyMaterialObj[key] + '</div>'
      		      + '<div class="form-group"><textarea cols="39" rows="2" id="' + key +'" placeholder="请备注申请资料的问题，方便律师重新上传！"></textarea></div>'
      		i ++;
		}
		divObj.html(html);
		$("#modal-replyLawyer").modal('toggle');
	}
	
	//保存反馈给律师信息
	function replyLawyerSubmit(){
		if(notSubmitReplyLawyer){
			var reasons = new Array();
			var reason = null;
			for(var key in companyMaterialObj){
				reason = $('#' + key).val();
				if(reason != undefined && reason.length > 0){
					reasons.push(companyMaterialObj[key] + ':' + reason);
				}
			}
			if(reasons.length > 0){
				var url = '${contextPath}/order/saveReplyLawyer';
				var parameters = {"reasons":reasons,"orderId":currentOrderId};
				postData(url, parameters, replyLawyerCallback, replyLawyerErrorCallback);
			}else{
				showMsg('原因不能为空');
			}
		}else{
			showMsg('提交中，请稍候');
		}
	}
	
	//保存审核失败成功后回调
	function reviewFailCallback(data){
		notSubmitReviewFail = true;
		if(data.success){
			$("#modal-reviewFail").modal('toggle');
			showMsg('保存成功');
			reloadGrid();
			reviewPageHide();
		}else{
			showMsg(data.message);
		}
	}
	
	//保存审核失败失败后回调
	function reviewFailErrorCallback(data){
		notSubmitReviewFail = true;
	}
	
	//打开审核失败页面 
	function reviewFailPageShow(){
		var result = confirm("确认结束该订单吗？");
		if(result == true){
			notSubmitReviewFail = true;
			$("#modal-reviewFail").modal('toggle');
		}
	}

	//保存审核失败
	function reviewFailSubmit(){
		if(notSubmitReviewFail){
			var reason = $('#reviewFailReason').val();
			if(reason != undefined && reason.length > 0){
				notSubmitReviewFail = false;
				var url = '${contextPath}/order/saveReviewFail';
				var parameters = {"reason":reason,"orderId":currentOrderId};
				postData(url, parameters, reviewFailCallback, reviewFailErrorCallback);
			}else{
				showMsg('失败原因不能为空');
			}
		}else{
			showMsg('提交中，请稍候');
		}
	}

	//保存审核通过成功后回调
	function reviewPassCallback(data){
		notSubmitReviewPass = true;
		if(data.success){
	    	gridTable1.trigger('reloadGrid');
			showMsg('保存成功,请上传需客户签名的投保单');
			uploadFileShow(74,currentOrderId);
			reviewPageHide();
		}else{
			showMsg(data.message);
		}
	}
	
	//保存审核通过失败后回调
	function reviewPassErrorCallback(data){
		notSubmitReviewPass = true;
	}
	
	//保存审核通过
	function reviewPassSubmit(){
		if(notSubmitReviewPass){
			notSubmitReviewPass = false;
			var url = '${contextPath}/order/saveOrderPass';
			var parameters = {"orderId":currentOrderId};
			postData(url, parameters, reviewPassCallback, reviewPassErrorCallback);
		}else{
			showMsg('提交中，请稍候');
		}
	}
	
	function reviewOperation(id){
		companyMaterialObj = {};
		currentOrderId = id;
		reviewPageShow();
		notSubmitReviewPass = true;
		var url = '${contextPath}/order/getOrderDetail';
		var parameters = {"orderId":id};
		postData(url, parameters, getOrderDetailCallback, errorCallbackDefault);
	}
	
	//关闭审核资料页面
	function reviewPageHide(){
		$('#gridTable1List').show();
		$('#navigationList').show();
		$('#gridTable1Review').hide();
		$('#navigationReview1').hide();
		$('#navigationReview2').hide();
	}

	//打开审核资料页面
	function reviewPageShow(){
		$('#gridTable1ReviewDetail').html('');
		$('#gridTable1List').hide();
		$('#navigationList').hide();
		$('#gridTable1Review').show();
		$('#navigationReview1').show();
		$('#navigationReview2').show();
	}
	
	//保存公司回复律师信息
	function saveCompanyFeedback(){
		var reason = $('#gridTable1Review-companyFeedback').val();
		if(reason.length < 1){
			showMsg('反馈信息不能为空');
		}else{
			var url = '${contextPath}/order/saveCompanyFeedback';
			var parameters = {"reason":reason,"orderId":currentOrderId};
			postData(url, parameters, saveCompanyFeedbackCallback, errorCallbackDefault);
		}
	}

	//保存公司回复律师信息成功后回调
	function saveCompanyFeedbackCallback(data){
		notSubmitReplyLawyer = true;
		if(data.success){
			showMsg('保存成功');
			reloadGrid();
			reviewPageHide();
		}else{
			showMsg(data.message);
		}
	}

	//保存图片路径到数据库
    function saveToDB(orderId,keyArray,fileNameArray,fileTypeArray,accountBank,accountName,accountNum){
    	var attachType = $("#mod-file-attachType").val();
		var parameters = {"orderId":orderId,"attachType":attachType,"path":keyArray,"fileNameArray":fileNameArray,"fileTypeArray":fileTypeArray,"accountBank":accountBank,"accountName":accountName,"accountNum":accountNum};
		console.log(parameters);
		$.getJSON('${contextPath}/order/bdTempleteUpload',parameters,function(result){
			if(result.success){
				uploadFileSuccess();
			}else
				alert(result.message);
		});
    	
    }
	function search(){
		var keyword =$("#keyword").val();
		var searchDate =$("#searchDate").val();
		gridTable1.setGridParam({postData:{'keyword':keyword,'searchDate':searchDate,'orderState':0},url : '${contextPath}/order/getOrders',page:1}).trigger('reloadGrid');	
	}
	
	//显示信息
	function showMsg(msg){
		if(msg != undefined && msg.length > 0){
			alert(msg);
		}
	}
	
	//上传文件
	function uploadFileShow(attachType,orderId){
		getBlankInfos(orderId);
    	$("#mod-file-attachType").val(attachType);
    	$("#mod-file-orderId").val(orderId);
    } 
	
    function uploadFileSuccess(){
    	$("#mod-file").modal("toggle");	
    }
</script>		
