<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<%@page import="com.fadu.app.util.SystemCache"%>
<%@ 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" />
<link rel="stylesheet" href="${contextPath}/static/assets/css/jquery.gritter.css" />
<script>  
function setCity(obj){  
    var val = obj.value;  
    var sec = document.getElementById('cityId');
    sec.innerHTML = "<option value=''>全部</option>"; 
    if(val != ''){  
    	//ajax
    	$.getJSON("${contextPath}/util/getCitysByProvince?provinceId="+val,function(result){
    		$.each(result, function(i, v){
    			sec.innerHTML+="<option value='"+v.value+"'>"+v.name+"</option>";
    		});
  		});
    }     
}  

/**初始化所有案例类型*/
var caseTypes;
initCaseTypes();
function initCaseTypes(){
	$.getJSON("${contextPath}/sys/lawyercase/getCaseTypes", function(result){
		caseTypes = result;		
		$("select[name=caseType]").each(function(i, obj){
			var html = "";
			$.each(caseTypes, function(key, value){
				html+="<option value='"+key+"'>"+value+"</option>";
			});
			$(this).html(html);
			$("#beField").append(html);
		})
	});
}
</script> 
<!-- 律师信息 -->
<div class="row">
	<div class="col-xs-12">
	<!-- 搜索框开始 -->
				<div class="dropdown">
					省：<select id="provinceId" onchange="setCity(this)">
						    <option selected value="" >全部</option>
						    <% for(String s:SystemCache.provinceMap.keySet()){ %>
						    <option value="<%=s %>" ><%=SystemCache.getProvinceName(s) %></option>
						    <%} %>
						</select>
					市：<select id="cityId">
					</select>
					接单状态:
				<select id='orderFlag'>
				    <option selected value="" >全部</option>
				    <option value="1" >可以接单</option>
				    <option value="0" >不能接单</option>
				</select>
				关键字:<input id="keyword" class="input-medium search-query" type="text"/> 	
		<button id="searchd" type="button" class="btn" >搜索</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 -->
<div id="modal-table" class="modal fade" tabindex="-1" data-backdrop="static">
	<div class="modal-dialog" style="min-width: 820px;">
			<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="max-height: 500px; overflow-y: scroll;">
					<div class="container-fluid">
						<div class="row-fluid">
							<div class="span12">
								<div class="hero-unit">
									<h3>律师基本信息</h3>
									<div class="container-fluid">
										<div class="row-fluid">
											<div class="span12">
												<table class="table" id="lawyerTab">
													<tr>
														<td>律师姓名:</td>
														<td><span id="realNamePro"></span></td>
													</tr>
													<tr>
														<td>手机号码:</td>
														<td><span id="mobilePro"></span></td>
													</tr>
													<tr class="success">
														<td>注册邮箱：</td>
														<td><span id="emailPro"></span></td>
													</tr>
													<tr class="error">
														<td>律所:</td>
														<td><span id="officePro"></span></td>
													</tr>
													<tr class="warning">
														<td>地址:</td>
														<td><span id="addressPro"></span></td>
													</tr>																										
													<tr class="warning">
														<td>简介:</td>
														<td><span id="briefInfoPro"></span></td>
													</tr>
													<tr class="info">
														<td>创建时间:</td>
														<td><span id="createDatePro"></span></td>
													</tr>
												</table>
											</div>
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</form>
	</div>
	<!-- /.modal-dialog -->
</div>
<!-- 编辑显示律师信息  end -->


<!-- 案例信息弹框 start -->
<div id="lawyerCaseDiv" class="modal fade" tabindex="-1" data-backdrop="static">
	<div class="modal-dialog" style="min-width: 920px;">
			<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="max-height: 700px; overflow-y: scroll;">
											<div class="container-fluid">
												<div class="row-fluid">
													<div class="span12">	
														<button id="startSearchCaseBtn">导入文书网案例</button><span id="startSearchCaseShow" style="display:none">处理中</span>
														<table class="table" id="caseTable">
															<tbody>
																<tr class="success">
																	<td width="5%">序号</td>
																	<td width="30%">标题</td>
																	<td width="20%">法院</td>
																	<td width="18%">案号</td>
																	<td width="10%">案件类型</td>
																	<td width="7%">点击数</td>
																	<td width="10%">操作</td>
																</tr>
															</tbody>
															<tbody id="lawyerCaseList"></tbody>
														</table>
														
													</div>
												</div>
											</div>
											<div class="container-fluid">
												<div class="row-fluid">
													<div class="span12">
														<form id="editCase" type="POST" action="">
															<table class="table" id="caseTable">																
																<tr class="warning">																
																	<td width="100">标 题:</td>
																	<td><input type="text" name="title" id="case_title" width="500"/></td>
																</tr>
																<tr class="warning">
																	<td>法院:</td>
																	<td><input type="text" name="court" id="case_court" width="500"/></td>
																</tr>
																<tr class="warning">
																	<td>案号:</td>
																	<td><input type="text" name="casenum" id="case_casenum" width="500"/></td>
																</tr>
																<tr class="warning">
																	<td valign="top">案件类型:</td>
																	<td><select name="caseType" id="case_casetype">																			
																		</select>
																	</td>
																</tr>
																<tr class="warning">
																	<td>例案详情:</td>
																	<td>
																	<div class="wysiwyg-editor" id="editor" style="min-height: 400px;"></div>
																		<!-- <textarea rows="10" cols="90" name="content"></textarea> -->
																	</td>
																</tr>																			
															</table>			
															<input type="hidden" name="id" id="case_id"/>
															<input type="hidden" name="content" id="case_content"/>
															<input type="hidden" name="lawyer.id" id="case_lawyerId" lawyerId="lawyerId" />
														</form>
														
														<div class="modal-footer no-margin-top">
															<div class="text-center">
																<button id="saveCaseBtn" class="btn btn-app btn-success btn-xs">
																	<i class="ace-icon fa fa-floppy-o bigger-160"></i> 保存案例
																</button>
																<button class="btn btn-app btn-pink btn-xs"
																	data-dismiss="modal">
																	<i class="ace-icon fa fa-share bigger-160"></i> 取消
																</button>																
															</div>
														</div>
														<div id="show">保存中，请稍等...</div>
													</div>
												</div>
											</div>
								</div>	
				</div>
	</div>
</div>
<!-- 案例信息弹框 end -->

<!-- 裁判文书网案例  start-->
<div id="lawyerCaseGovDiv" class="modal fade" tabindex="-1" data-backdrop="static">
	<div class="modal-dialog" style="min-width: 1020px;">
		<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="max-height: 700px; overflow-y: scroll;">
					<div><span style="color: red">*</span>灰色背景为已经导入案例</div>
					<form id="importForm">
						<input id="importBtn" type="button" value="导入" /><span id="importShow" style="display:none">处理中，请稍等...</span>
					</form>														
					<table id="case-gov-grid" style="width: 100%"></table>
					<div id="case-gov-grid-pager"></div>
			</div>
		</div>
	</div>
</div>
<!-- 裁判文书网案例  end -->


<!-- 裁判文书网案例裁定书  start-->
<div id="lawyerCaseGovContentDiv" class="modal fade" tabindex="-1" data-backdrop="static">
	<div class="modal-dialog" style="min-width: 1020px;">
		<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="max-height: 500px; overflow-y: scroll;">
				<div id="caseGovContent">
					
				</div>
			</div>
		</div>
	</div>
</div>
<!-- 裁判文书网案例裁定书  end-->


		<!-- 查档绑定地区 start -->
		<div id="bindAreaDiv" class="modal fade" tabindex="-1" data-backdrop="static">
			<div class="modal-dialog" style="min-width: 920px;">
				<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="container-fluid">
						<div class="row-fluid">
							<div class="span12">	
								<table class="table">
									<tbody>
										<tr class="success">
											<td width="10%">地区</td>
											<td width="7%">查档天数</td>
											<td width="20%">绑定时间</td>
											<td width="10%">查档类型</td>
											<td width="7%">金额</td>
											<td width="7%">接单状态</td>
											<td width="20%">备注</td>
											<td width="10%">操作</td>
										</tr>
									</tbody>
									<tbody id="bindAreaList"></tbody>
								</table>
							</div>
						</div>
					</div>
					<div class="modal-body"	style="max-height: 700px; overflow-y: scroll;">
						<div class="container-fluid">
							<div class="row-fluid">
								<div class="span12">
									<form id=addArea type="POST" action="">
										<table class="table" id="bindAreaTable">
											<tr class="warning">
												<td>省：</td>
												<td>
													<select id="areaProvince" onchange="setAreaCity(this);"><option value=''>全部</option></select>
												</td>
											</tr>
											<tr>
												<td>市：</td>	
												<td><select id="areaCity" onchange="getCounty(this)"></td>
											</tr>
											<tr><td id="tdCounty" colspan="4"></td></tr>	
											<tr id="trSelectStatus" style="display: none">
												<td>接单优先级：</td>
												<td>
													<select id='status' name=status >
													    <option selected value="1" >1</option>
													    <option value="2">2</option>
													    <option value="3">3</option>
													    <option value="4">4</option>
													    <option value="5">5</option>
													    <option value="6">6</option>
													    <option value="7">7</option>
													    <option value="8">8</option>
													    <option value="9">9</option>
													</select>
												</td>
											</tr>
											<tr>
												<td>查档价格：</td>
												<td><input type="text" name="price" id="price" width="500"/></td>
											</tr>
											<tr>
												<td>查档天数：</td>
												<td><input type="text" name="takeTime" id="takeTime" width="500"/></td>
											</tr>	
											<tr>
												<td>备注信息</td>
												<td><input type="text" name="remark" id="remark" width="500"/></td>
											</tr>																			
										</table>
										<input type="hidden" name="lawyerId" />
									</form>											
									<div class="modal-footer no-margin-top">
										<div class="text-center">
											<button id="saveAreaBtn" class="btn btn-app btn-success btn-xs">
												<i class="ace-icon fa fa-floppy-o bigger-160"></i> 绑定
											</button>
											<button class="btn btn-app btn-pink btn-xs"	data-dismiss="modal">
												<i class="ace-icon fa fa-share bigger-160"></i> 取消
											</button>															
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>	
				</div>
			</div>
		</div>
		<!-- 查档绑定地区 end -->


<input type="hidden" id="importLawyerId"/>
<!-- page specific plugin scripts -->
<script type="text/javascript">
		document.getElementById("show").style.display ='none';
		function showdiv() {            
			document.getElementById("show").style.display ="block";
		    $("#saveCaseBtn").attr({"disabled":"disabled"});
		}
		function hidediv() {
			document.getElementById("show").style.display ='none';
		    $("#saveCaseBtn").removeAttr("disabled");
		}	
		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/jquery-ui.custom.js",
		                "${contextPath}/static/assets/js/jquery.ui.touch-punch.js",
		                "${contextPath}/static/assets/js/markdown/markdown.js",
		                "${contextPath}/static/assets/js/markdown/bootstrap-markdown.js",
		                "${contextPath}/static/assets/js/jquery.hotkeys.js",
		                "${contextPath}/static/assets/js/bootstrap-wysiwyg.js", 
		                "${contextPath}/static/assets/js/bootbox.js", 
		                "${contextPath}/static/assets/js/jquery.gritter.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);
        			}
        		})
        		myGrid=	jQuery(grid_selector).jqGrid({
        			subGrid : true,
        			url : "${contextPath}/sys/lawyer/getHqlLawyer",
        			datatype : "json",
        			height : '100%',
        			width : 'auto',
        			shrinkToFit:false,
        			autoScroll: false,
        			colNames : ['','头像', '姓名', '手机号码', '省','市','', '律所','执业年限','简介','接单状态','操作' ],
        			colModel : [ {
        				name : '',
        				index : '',
        				width : 40,
        				fixed : true,
        				sortable : false,
        				resize : false,
        				formatter : 'actions',
        				formatoptions : {
        					keys : true,
        					delbutton : false,//disable delete button
        					/* delOptions : {
        						recreateForm : true,
        						beforeShowForm : beforeDeleteCallback
        					}, */
        					editOptions:{recreateForm:true, beforeShowForm: beforeEditCallback}
        				}
        			},{	name : 'logo',index : 'logo',width : 100,editable : false,
			            formatter: function (cellvalue, options, rowObject) {
			           	 //cellvalue :要格式化的值  
			              return "<a href='<%=com.fadu.app.util.AppConfig.url_duowenapp_c%>/lawyer/uploadlogo?id="+rowObject.id+"'  target='_blank'><img width='50' height='50' src='<%=com.fadu.app.util.AppConfig.url_duowenapp_c%>"+cellvalue+"' /></a>";
			            }
        			}, {name : 'realName',index : 'realName',width : 80,editable : true,searchoptions : {sopt : ['like']},editrules : {required : true},
        				editoptions : {
        					dataEvents:[{type:'blur',fn:function(e){ 
       							$("[name=certificateDate]").datepicker({
                				format : 'yyyy-mm-dd',
                					autoclose : true,
                				  	language: 'zh-CN'
                				});	        							
        					}}]        					
       					}
        			}, {name : 'mobile',index : 'mobile',width : 120,editable : true,searchoptions : {sopt : ['like']},editrules : {required : true},
        			}, {name : 'province',index : 'province',width : 80,edittype : "select",
        				editoptions : {
        					dataUrl : "${contextPath}/sys/lawyer/getprovinceIdSelectList",
        					dataEvents:[{type:'change',fn:function(e){
        						var lawyerId =  $(this).attr("id").split("_")[0];
        						var classTypeCol = $('#' + lawyerId + '_city');
        						classTypeCol = classTypeCol.length>0 ? classTypeCol : $('#'+'city');
           			          	classTypeCol.empty();
           			         	$.get("${contextPath}/util/getCitys", {provinceId:$(this).val()}, function(result){
           			         		if(result){
           			         			for(var i=0; i<result.length; i++){
           			        	         	classTypeCol.append("<option value="+result[i].value+">"+result[i].name+"</option>");
           								}
           			         		}					
           						});
    						}}]
        				},        				
        				editable : false, search : false,
        			}, {
        				name : 'city',
        				index : 'cityId',
        				width : 80,
        				edittype : "select",
        				editoptions : {
        					dataUrl : "${contextPath}/sys/lawyer/getCitySelectList"
        				},
        				editable : false,
        				search : false,
        			},{
        				name : 'recommend',
        				index : 'recommend',
        				width : 60,
        				editable : true,
        				edittype : "select",
        				editoptions:{value:"0:否;1:是"},formatter:defaultValrecommend,
        				hidden:true
        			}, {name : 'office',index : 'office',width : 120,editable : false,search : false,
        			}, {name : 'expYear',index : 'expYear',width : 60,editable : false,
        			}, {name : 'briefInfo', index : 'briefInfo', width : 250, editable : false, search : false, edittype: 'textarea',
        			}, {
        				name : 'orderFlag',
        				index : 'orderFlag',
        				width : 110,
        				editable : true,
        				edittype : "select",
        				editoptions:{value:"0:不能接单;1:可以接单"},formatter:defaultValorderFlag
        			},{ name : "id", index : "id", label : "编辑", width : 300,editable : true, search : true,
        				editable:false,viewable:false,formatter:moveButton//(cellvalue, options, rowObject) 
        				//:moveButton
        			}],
        			//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, 50 ],
        			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);
        			},
        			editurl : "${contextPath}/sys/lawyer/operateLawyer"
        		});
         		
        		function multiCheckElem(values, optio) {
        		    var id = optio.id;
        		    var ctl = '<div id="'+ id + '" class="checklist">';
        		    var ckboxAry = optio.list.split(';');
        		    var aValues = [];
        		    if (values && values.length)
        		    {
        		        aValues = values.split(",");
        		    }
        		    for (var i = 0; i < ckboxAry.length; i++)
        		    {
        		        var item = ckboxAry[i].split(':');
        		        ctl += '<input type="checkbox" ';

        		        if (aValues.indexOf(item[0]) != -1)
        		        {
        		            ctl += 'checked="checked" ';
        		        }
        		        ctl += 'value="' + item[0] + '"> ' + item[1] + '</input><br/>';
        		    }
        		    return ctl + '</div>';
        		}

        		function multiCheckVal(elem, action, val) {
        		    var items = '';
        		    if (action == 'get') // submitted
        		    {

        		        $("input[type=checkbox]:checked", elem).each(function (i, e)
        		        {
        		            if (items) items += ","
        		            items += e.value;
        		        });

        		    }
        		    else // launched
        		    {

        		    }
        		    return items;
        		}
        		
        		function	defaultLawyerTypeFlag(cellvalue, options, rowObject){
        			switch(cellvalue)
					{
					case 0:
					return "";
						break;
					case 1:
						return "实习";
						break;
					default:
					return cellvalue;
					}
				}
        		
        		//推荐初始化默认值
        		function	defaultValrecommend(cellvalue, options, rowObject){
        			switch(cellvalue)
					{
					case 0:
					return "否";
						break;
					case 1:
						return "是";
						break;
					default:
					return cellvalue;
					}
				}
        		
        		//默认值格式化: Status 状态
				function defaultValFormat(cellvalue, options, rowObject){
					switch(cellvalue)
					{
					case 0:
					return "注册";
						break;
					case 1:
						return "已经完善资料";
						break;
					case 2:
						return "认证审核中";
						break;
					case 3:
						return "认证审核失败";
						break;
					case 4:
						return "认证成功";
						break;
					default:
					return cellvalue;
					}
			}
        		
        		//接单状态初始化默认值
        		function	defaultValorderFlag(cellvalue, options, rowObject){
        			switch(cellvalue)
					{
					case 0:
					return "不能接单";
						break;
					case 1:
						return "可以接单";
						break;
					default:
					return cellvalue;
					}
				}
        		
        		//接单状态初始化默认值
        		function	defaultCdStatus(cellvalue, options, rowObject){
        			switch(cellvalue)
					{
					case 0:
					return "不能查档";
						break;
					case 1:
						return "可以查档";
						break;
					default:
					return cellvalue;
					}
				}
        		
        		//审核失败初始化默认值
        		function defaultValfailType(cellvalue, options, rowObject){
        			if(cellvalue==null)
        				return "";
        			var ret='';
        			if(cellvalue.indexOf("1")!=-1)
        				ret+="年限 ";
        			if(cellvalue.indexOf("2")!=-1)
        				ret+="证书 ";
        			if(cellvalue.indexOf("3")!=-1)
        				ret+="头像 ";
        			if(cellvalue.indexOf("4")!=-1)
        				ret+="简介 ";
        			if(cellvalue.indexOf("5")!=-1)
        				ret+="资料 ";
        			if(ret!='')
        				ret+="不符";
        			return ret;
				}
        		
        		$(document).keydown(function(event) {
					var key = window.event ? event.keyCode : event.which;
					if (key == 13) {
						$("#searchd").click();
					}
				});
        		
        		//搜索
				$("#searchd").click(function(){
					var keyword =$("#keyword").val();
					var orderFlag =$("#orderFlag").val();
					var provinceId = $("#provinceId").val();
					var cityId = $("#cityId").val();
					myGrid.setGridParam({postData:{'keyword':keyword,'orderFlag':orderFlag,'provinceId':provinceId,'cityId':cityId},url : '${contextPath}/sys/lawyer/getHqlLawyer',page:1}).trigger('reloadGrid');	
				});
        		//company 
        		function moveButton(cellvalue, options, rowObject){
        			var html = "<input id='openLawyerBtn' class='movingup' type='button' name='" + cellvalue + "' value='查看' />";
        			html += "<input id='openCaseBtn' class='movingup' type='button' lawyerId='" + cellvalue + "' value='案例 ' />";       			
					return html;
				}
        		
				//弹出律师信息详细窗口
        		$(grid_selector).delegate("#openLawyerBtn","click",function(){
      				//弹出模态窗口
        			$("#modal-table").modal("toggle");
    				var lawyerId=$(this).attr('name');
    				//alert(myId);
    				//模块窗口 详情信息 同样是json数据
					$.getJSON("${contextPath}/sys/lawyer/getLawyerByid?lawyerId="+lawyerId+"", {data:new Date()}, function(result){
						if(result.isSuccess){
							$.each(result.lawyer, function(i, field){
								if(field!=null && field!="null"){
									$("#"+i+"Pro").text(field);									
								}
							});
						}
			  		});
				});
				
        		//编辑律师案例信息
        		$(grid_selector).delegate("#openCaseBtn","click",function(){
      				//弹出模态窗口
        			$("#lawyerCaseDiv").modal("toggle");
    				var lawyerId=$(this).attr('lawyerId');   
    				$("#importLawyerId").val($(this).attr('lawyerId'));
    				$("#editCase [lawyerId=lawyerId]").val(lawyerId);
    				//清空表单
        			$(':input','#editCase').not(':button, :submit, :reset, :hidden').val('').removeAttr('checked').removeAttr('selected');
   					$('#editCase [name=id]').val("");
   					$("#editor").html("");
   					$("#case_content").val("");
   					
    				initCase(lawyerId);
				});
        		
        		//编辑律师查档绑定地区
        		$(grid_selector).delegate("#openBindArea","click",function(){
      				//弹出模态窗口
        			$("#bindAreaDiv").modal("toggle");
    				var lawyerId=$(this).attr('lawyerId');    				
    				if($(this).attr('status')=='4'){
    					$("#trSelectStatus").show();
    				}else{
    					$("#trSelectStatus").hide();
    				}
    				$("#addArea [name=lawyerId]").val(lawyerId);
    				
    				//清空表单
        			$(':input','#addEara').not(':button, :submit, :reset, :hidden').val('').removeAttr('checked').removeAttr('selected');
  					
   					initBindAreaList(lawyerId);
				});
        		
        		var caseGovGT=null;
        		var params = {};
        		//编辑律师案例信息
        		$(grid_selector).delegate("#openCaseGovBtn","click",function(){

      				//弹出模态窗口
        			$("#lawyerCaseGovDiv").modal("toggle");
    				var caseGovGrid = "#case-gov-grid";
    				var caseGovGridPager = "#case-gov-grid-pager"; 
    				//var enLawyerName = $(this).attr('lawyerName');
    				var lawyerIdTemp = $(this).attr('lawyerId');
    				$("#importLawyerId").val(lawyerIdTemp);
    				
    				if( caseGovGT && params.lawyerId!=lawyerIdTemp ){
    					params = {lawyerId : lawyerIdTemp, curr: new Date()};
    					caseGovGT.setGridParam({postData:params, url : '${contextPath}/sys/lawyer/getGovCaseList',page:1}).trigger('reloadGrid');	
					}else if(caseGovGT==null){
						params = {lawyerId : lawyerIdTemp};    				
	    				caseGovGT =	jQuery(caseGovGrid).jqGrid({
	            			subGrid : false,
	            			url : "${contextPath}/sys/lawyer/getGovCaseList",
	            			postData : params,
	            			datatype : "json",
	            			height : '100%',
	            			width : '100%',
	            			colNames : ['标题', '类型', '法院','是否存在', '主键', '案例号', '原类型', '时间', '操作'],
	            			colModel : [  {name : 'title',index : 'title',width : 350
							}, {name : 'suggestType',index : 'court', width : 100, formatter: function(cellvalue, options, rowObject){								
									var html = "<select>";
									$.each(caseTypes, function(key, value){
										html+="<option value='"+key+"' " + (cellvalue==key?" selected='selected' ":"") + ">"+value+"</option>";
									});
									html += "</select>";
									return html;
								}
							}, {name : 'court',index : 'court', width : 200
							}, {name : 'isExist',index : 'isExist', hidden:true
							}, {name : 'id',index:'id', hidden:true
	            			}, {name : 'casenum',index : 'casenum', width : 190
	            			}, {name : 'caseTypeName',index : 'caseTypeName', width : 60
	            			}, {name : 'createDate',index : 'createDate', width : 80
	            			}, { name : "aaa", index : "aaa", width : 60, formatter:function(cellvalue, options, rowObject){
	            					var html = "<input type='button' onclick=window.open('${contextPath}/sys/lawyer/toViewGovCaseContent?caseGovId="+rowObject.id+"&lawyerId="+rowObject.lawyerId+"','_blank') value='预览' />"; 
									return html;
	            				}
	            			}],
	            			sortname : "createDate",
	            			sortorder : "asc",
	            			viewrecords : true,
	            			rowNum : 10,
	            			rowList : [ 5, 10, 15, 20 ],
	            			pager : caseGovGridPager,
	            			altRows : true,
	            			multiselect : true,
	            	        multiboxonly : true,
	            	        loadComplete : function() {
	            				var table = this;
	            				setTimeout(function(){
	            					styleCheckbox(table);
	            					updateActionIcons(table);
	            					updatePagerIcons(table);
	            					enableTooltips(table);
	            					$("#importBtn").unbind(importCaseGovList)
	            					$("#importBtn").click(importCaseGovList);
	            					           					
	            				}, 0);
	            			},
	            			gridComplete: function(){

            					//获取列表数据
	            				var rowDatas = $(caseGovGrid).jqGrid('getRowData');	 		            				
	            				for(i=0;i<rowDatas.length;i++){
	            					//alert(JSON.stringify(rowDatas[i]));
		            				if(rowDatas[i].isExist!=1){
		            					$("#"+rowDatas[i].id).find("td").css("background-color", "#E4EFC9");
		            					//$("#"+rowDatas[i].id).find("[type=checkbox]").attr("checked", true);		
		            				}else{
		            					$("#"+rowDatas[i].id).find("td").css("background-color", "#E5E5E5");
		            				}
	            				}	 
	            			}
	            		}).navGrid(caseGovGridPager,{edit:false,add:false,del:false,view:false});
					}
    			});
        		
        		function initCase(lawyerId){
        			$("#lawyerCaseList").html("<tr><td colspan='6' class='info'>获取案例中,请稍等...</td></tr>");
        			//具体案件获取：
				 	$.getJSON("${contextPath}/sys/lawyer/getLawyerCases?lawyerId="+lawyerId, {data:new Date()},  function(result){					 
		 	 	 		if(result && result.isSuccess){
		 	 	 			var html = "";
		 	 	 			for(var i=0; i<result.rows.length; i++){
								html += "<tr lawyerId="+lawyerId;
								if(i%2==1)
									html +=" class='info'";
								html +=" >";
								html += "<td>"+(i+1)+"</td>";
								html += "<td>"+result.rows[i].title+"</td>";
								html += "<td>"+result.rows[i].court+"</td>";
								html += "<td>"+result.rows[i].casenum+"</td>";
								html += "<td>"+result.rows[i].caseTypeName+"</td>";
								html += "<td>"+result.rows[i].views+"</td>";
								html += "<td lawyerCaseId="+result.rows[i].id+">"+"<a href='javascript:void(0)' onclick='delLawyerCase(this)'>删除</a> <a href='javascript:void(0)' onclick='updLawyerCase(this)'>修改</a> <a href='"+result.url_duowenapp_c+ "/case?id=" + result.rows[i].id +"' target='blank' >查看</a></td> ";
								html += "</tr>";								
		 	 	 			}
		 	 	 			$("#lawyerCaseList").html(html);
		 	 	 		}
				 	});
        		}

        		function initBindAreaList(lawyerId){
        			$("#lawyerCaseList").html("<tr><td colspan='8' class='info'>获取绑定地区中,请稍等...</td></tr>");
        			//具体案件获取：
				 	$.getJSON("${contextPath}/sys/cdPrice/getLawyerBindAreas?lawyerId="+lawyerId, {data:new Date()},  function(result){					 
		 	 	 		if(result && result.isSuccess){
		 	 	 			var html = "";
		 	 	 			for(var i=0; i<result.rows.length; i++){
								html += "<tr lawyerId="+lawyerId;
								if(i%2==1)
									html +=" class='info'";
								html +=" >";
								html += "<td>"+result.rows[i].areaName+"</td>";
								html += "<td>"+result.rows[i].takeTime + "</td>";
								html += "<td>"+(result.rows[i].createDate==null?"":result.rows[i].createDate)+"</td>";
								html += "<td>"+result.rows[i].orderTypeName+"</td>";
								html += "<td>"+result.rows[i].price+"</td>";
								html += "<td>" + (result.rows[i].status==0?"后选":"默认")+"</td>";
								html += "<td>"+result.rows[i].remark+"</td>";
								html += "<td cdPriceId="+result.rows[i].id+">"+"<a href='javascript:void(0)' onclick='delBindArea(this)'>删除</a></td> ";
								html += "</tr>";								
		 	 	 			}
		 	 	 			$("#bindAreaList").html(html);
		 	 	 		}
				 	});
				 	initAreaProvince();
        		}
        		
        		$("#saveCaseBtn").click(function(){        			
       				if($('#editCase [name=title]').val()==""){
       					alert("请输入标题!");
       					$('#editCase [name=title]').focus();
       					return ;
       				}
       				if($('#editCase [name=casenum]').val()==""){
       					alert("请输入法院号!");
       					$('#editCase [name=casenum]').focus();
       					return ;
       				}
       				if($('#editCase [name=caseType]').val()=="" || $('#editCase [name=caseType]').val()=='undefined' || $('#editCase [name=caseType]').val()==null){
       					alert("请选择案件类型!");
       					$('#editCase [name=caseType]').focus();
       					return ;
       				}
       				if($("#editor").html()==""){
       					alert("请输入详细!");
       					return ;
       				}
       				showdiv();
       				$("#case_content").val($("#editor").html());
       				var params = $('#editCase').serialize();
       				
       				$.post("${contextPath}/sys/lawyer/saveLawyerCase", params, function(data){
       					hidediv();
       					alert(data.message);
       					if(data.isSuccess==true){
	       					//清空表单
	       					var lawyerId = $('#editCase [lawyerId=lawyerId]').val();
	       					$(':input','#editCase').not(':button, :submit, :reset, :hidden').val('').removeAttr('checked').removeAttr('selected');
	       					$('#editCase [name=id]').val("");
	       					$("#editor").html("");
	       					$("#case_content").val("");
	       					initCase(lawyerId);
       					}
       				});   				
        		});
        		
        		$("#saveAreaBtn").click(function(){        			
       				if($('#addArea [name=areaProvince]').val()==""){
       					alert("请选择省!");
       					return ;
       				}
       				if($('#addArea [name=areaCity]').val()==""){
       					alert("请选择市!");
       					return ;
       				}       				
       				if(!$('#addArea [name=price]').val().match("^[0-9]+(.[0-9]{2})?$")){
       					alert("请输入正确的查档价格，只支持两位小数!");
       					return ;
       				}
       				if(!$('#addArea [name=takeTime]').val().match("\\d+")){
       					alert("请输入正确的查档时间!");
       					return ;
       				}
       				
       				var countys =[];     
                    $('input[name="county"]:checked').each(function(){  
                    	countys.push($(this).val());      
                    });       				
       				if(countys.length==0 ){
       					alert("请选择要绑定的地区!");
       					return ;
       				}       				
       				var params = $('#addArea').serialize();
       				params += "&countys=" + countys.join(',');
       				$.post("${contextPath}/sys/cdPrice/saveBindArea", params, function(data){
       					if(data.isSuccess==true){
	       					//清空表单
	       					var lawyerId = $('#addArea [name=lawyerId]').val();
	       					$(':input','#addArea').not(':button, :submit, :reset, :hidden').val('').removeAttr('checked').removeAttr('selected');
	       					initBindAreaList(lawyerId);
       					}else {
       						alert(data.message);
       					}
       				});	
        		});
        		
        		$("#startSearchCaseBtn").click(function (){
        			$("#startSearchCaseShow").show();
        		    $("#startSearchCaseBtn").attr({"disabled":"disabled"});

        			$.post("${contextPath}/sys/lawyer/startSearchCase", {lawyerId: $("#case_lawyerId").val()}, function(data){
       					if(data.isSuccess==true){
       	        			$("#startSearchCaseShow").html("已经开始启动抓取案例任务.");
       	        		    $("#startSearchCaseBtn").attr("disabled","disabled");
       					}
       				}); 
        		})
				
        		$(window).triggerHandler('resize.jqGrid');//
        		
        		$("#editor").ace_wysiwyg({
        			toolbar:
        			[
        				"font",
        				null,
        				"fontSize",
        				null,
        				{name:"bold", className:"btn-info"},
        				{name:"italic", className:"btn-info"},
        				{name:"strikethrough", className:"btn-info"},
        				{name:"underline", className:"btn-info"},
        				null,
        				{name:"insertunorderedlist", className:"btn-success"},
        				{name:"insertorderedlist", className:"btn-success"},
        				{name:"outdent", className:"btn-purple"},
        				{name:"indent", className:"btn-purple"},
        				null,
        				{name:"justifyleft", className:"btn-primary"},
        				{name:"justifycenter", className:"btn-primary"},
        				{name:"justifyright", className:"btn-primary"},
        				{name:"justifyfull", className:"btn-inverse"},
        				null,
        				{name:"createLink", className:"btn-pink"},
        				{name:"unlink", className:"btn-pink"},
        				null,
        				{name:"insertImage", className:"btn-success"},
        				null,
        				"foreColor",
        				null,
        				{name:"undo", className:"btn-grey"},
        				{name:"redo", className:"btn-grey"}
        			],
        			"wysiwyg": {
        				fileUploadError: showErrorAlert
        			}
        		}).prev().addClass("wysiwyg-style3");
        		
        		function showErrorAlert(reason, detail) {
        			var msg = "";
        			if (reason === "unsupported-file-type") {
        				msg = "Unsupported format " + detail;
        			} else {
        				// console.log("error uploading file", reason, detail);
        			}
        			$("<div class='alert'> <button type='button' class='close' data-dismiss='alert'>&times;</button>" + "<strong>File upload error</strong> " + msg + " </div>").prependTo("#alerts");
        		}
        		
        		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 : <shiro:hasPermission name="${ROLE_KEY}:lawyerinfo:edit">true</shiro:hasPermission><shiro:lacksPermission name="${ROLE_KEY}:lawyerinfo:edit">false</shiro:lacksPermission>,
        			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 : <shiro:hasPermission name="${ROLE_KEY}:lawyerinfo:search">true</shiro:hasPermission><shiro:lacksPermission name="${ROLE_KEY}:lawyerinfo:search">false</shiro:lacksPermission>,
        			searchicon : 'ace-icon fa fa-search orange',
        			refresh : true,
        			refreshicon : 'ace-icon fa fa-refresh blue',
        			view : <shiro:hasPermission name="${ROLE_KEY}:lawyerinfo:view">true</shiro:hasPermission><shiro:lacksPermission name="${ROLE_KEY}:lawyerinfo:view">false</shiro:lacksPermission>,
        			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) {
        			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) {
        			//alert("asfsdf1213");
        			var form = $(e[0]);
        			form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar').wrapInner('<div class="widget-header" />')
        			style_edit_form(form);
        		}
        		function styleCheckbox(table) {
        		}
        		function updateActionIcons(table) {
        		}

        		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();
        		});
        		
        	});
        });

		/**删除律师案例*/
		function delLawyerCase(obj){
			if(confirm('确定删除这个案例?')){
				$.post("${contextPath}/sys/lawyer/delLawyerCase?lawyerCaseId=" + $(obj).parent().attr("lawyerCaseId"), {data:new Date()}, function(result){
					if(result && result.isSuccess){                			
						$(obj).parent().parent().remove();
					}
				});
			}
		}
		
		/**删除律师绑定的地区*/
		function delBindArea(obj){
			if(confirm('确定删除这个案例?')){
				$.post("${contextPath}/sys/cdPrice/delBindArea?cdPriceId=" + $(obj).parent().attr("cdPriceId"), {data:new Date()}, function(result){
					if(result && result.isSuccess){                			
						$(obj).parent().parent().remove();
					}
				});
			}
		}
		
		function initAreaProvince(){
			$.getJSON("${contextPath}/sys/cdPrice/getProvince",function(result){
	    		$.each(result, function(i, v){
	    			$("#areaProvince").append("<option value='"+v.code+"'>"+v.name+"</option>");
	    		});
	  		});	
		}

		function setAreaCity(obj){  
		    var val = obj.value;  
		    var sec = document.getElementById('areaCity');
		    sec.innerHTML = "<option value=''>全部</option>"; 
		    if(val != ''){  
		    	//ajax
		    	$.getJSON("${contextPath}/sys/cdPrice/getAreas?parentCode="+val,function(result){
		    		$.each(result, function(i, v){
		    			sec.innerHTML+="<option value='"+v.code+"'>"+v.name+"</option>";
		    		});
		  		});
		    }     
		}
		
		function getCounty(obj){  
		    var val = obj.value; 
		    var text = $(obj).find("option:selected").text();
		    $("#tdCounty").html("").append(getCheckBoxHtml(val, text));
		    if(val != ''){  
		    	$.getJSON("${contextPath}/sys/cdPrice/getAreas?parentCode="+val,function(result){
		    		$.each(result, function(i, v){
		    			$("#tdCounty").append(getCheckBoxHtml(v.code, v.name));
		    		});
		  		});
		    }     
		} 
		
		function getCheckBoxHtml(value, text){
			return "<input type=checkbox name=county value='" + value + "' />" + text + "&nbsp;&nbsp;";
		}
		
		/**获得律师案例*/
		function updLawyerCase(obj){
			$.get("${contextPath}/sys/lawyer/getLawyerCase?lawyerCaseId=" + $(obj).parent().attr("lawyerCaseId"), {data:new Date()}, function(result){
				if(result && result.isSuccess){       
					$('#editCase [name=id]').val(result.entity.id);
					$('#editCase [name=title]').val(result.entity.title);
					$('#editCase [name=casenum]').val(result.entity.casenum);
					$('#editCase [name=court]').val(result.entity.court);
					$('#editCase [name=caseType]').val(result.entity.caseType);
					$("#editor").html(result.entity.content);
				}
			});
		}
		
		function importCaseGovList(){
			var selectIds = $("#case-gov-grid").jqGrid("getGridParam", "selarrrow");
			var idAndTypes = [];
			for(var i=0; i<selectIds.length; i++){				
				idAndTypes.push(selectIds[i] + "_" + $("#"+selectIds[i]).find("select:first").val());
			}			
			if(idAndTypes==null || idAndTypes.length==0){
				 alert("请选择要导入的案例！");
				 return;
			}			
			var params = {
				caseGovIds: idAndTypes,
				lawyerId: $("#importLawyerId").val()
			};
			$("#importShow").show();
		    $("#importBtn").attr({"disabled":"disabled"});
			$.post("${contextPath}/sys/lawyer/caseGovImport", params, function(data){
				$("#importShow").hide();
				$("#importBtn").removeAttr("disabled");
				if (data.isSuccess==true) {
					alert("成功导入" + data.row + "个案例");	
				} else {
					alert(data.message);
				}
			});
		}
		
</script>
