$(function() {
	//工号选择
	$('select[node-hrNature]').change(function() {
		 var nature=$(this).val();
		 if(nature==1){
			 $('#regularStaff').show();
			 $('#internStaff').hide();
		 }else{
			 $('#internStaff').show();
			 $('#regularStaff').hide();
		 }
	});
	
	//审批和抄送的cidKey交互
	$('a[node-employeeApprovals]').click(function() {
		$("#cidKey").val($(this).attr("node-cidKey"));
	});
	$('a[node-employeeCC]').click(function() {
		$("#CCcidKey").val($(this).attr("node-cidKey"));
	});
	
	$("input[id^='verify_']").click(function(){
		
		var uid=$(this).val();
		var uname=$(this).attr('data');
		var ischeck=$(this).attr('checked');
		
		if(ischeck==undefined){
			alert('请清空重新设置审批流程');
			return ;
		}else{
			$(this).attr("disabled","disabled");
		}
		
		var chk_value =[]; 
		$('input[name="staff[]"]:checked').each(function(){ 
			chk_value.push($(this).val()); 
			}); 
		
		if(chk_value.length==1){
			$("#AUTDO").html(uname);
			$('#uidlist').val(uid);
		}else{
			var html2=$("#AUTDO").html();
			$("#AUTDO").html(html2+'->'+uname);
			var uil=$('#uidlist').val();
			$('#uidlist').val(uil+','+uid);
		}
		return ;
	});
	
	//设置抄送人员
	$("input[node-approvalsStaff]").click(function(){
		var didkey=$(this).attr('node-didkey');
		var cidkey=$(this).val();
		if($(this).is(':checked')) {
			if(didkey=='')
				$("input[node-cidKey="+cidkey+"]").attr("checked",true);
			else
				$("input[node-didKey="+cidkey+"_"+didkey+"]").attr("checked",true);
		}else{
			if(didkey=='')
				$("input[node-cidKey="+cidkey+"]").attr("checked",false);
			else
				$("input[node-didKey="+cidkey+"_"+didkey+"]").attr("checked",false);
		}
	});
	
	//获得入职审批数据
	$("a[node-approvals]").click(function(){
		var sidkey=$(this).attr('node-sidKey');
		var type='STAFF';
		
		var url = "/ajaxGetStaffInfoByType";
		$.ajax({
			url : url,
			type : "post",
			cache : false,
			dataType : "json",
			data : {
				serial : sidkey,
				type:type
			},
			global : true,
			success : function(data) {
				if (data.status == 1) {
					$("#sidKey").val(data.sidKey);
					$("#staffDetailNC").html(data.html);

				} else
					$("div[loading-msg='true']").html("illegal request");
			},
			error : function(err) {
				$("div[loading-msg='true']").html("");
			}
		});
	});
	
	//获得离职审批数据
	$("a[node-approvalsRegular]").click(function(){
		var sidkey=$(this).attr('node-sidKey');
		var type='STAFF';
		
		var url = "/ajaxGetStaffInfoByType";
		$.ajax({
			url : url,
			type : "post",
			cache : false,
			dataType : "json",
			data : {
				serial : sidkey,
				type:type
			},
			global : true,
			success : function(data) {
				if (data.status == 1) {
					$("#sidKeyRegular").val(data.sidKey);
					$("#staffDetailAD").html(data.html);
				} else
					$("div[loading-msg='true']").html("illegal request");
			},
			error : function(err) {
				$("div[loading-msg='true']").html("");
			}
		});
	});
	
	//获得离职审批数据
	$("a[node-approvalsDimission]").click(function(){
		var sidkey=$(this).attr('node-sidKey');
		var type='STAFF';
		
		var url = "/ajaxGetStaffInfoByType";
		$.ajax({
			url : url,
			type : "post",
			cache : false,
			dataType : "json",
			data : {
				serial : sidkey,
				type:type
			},
			global : true,
			success : function(data) {
				if (data.status == 1) {
					$("#sidKeyDimission").val(data.sidKey);
					$("#staffDetailDi").html(data.html);
				} else
					$("div[loading-msg='true']").html("illegal request");
			},
			error : function(err) {
				$("div[loading-msg='true']").html("");
			}
		});
	});
	
	//获得晋升审批数据
	$("a[node-approvalsPromote]").click(function(){
		var sidkey=$(this).attr('node-sidKey');
		var type='STAFF';
		
		var url = "/ajaxGetStaffInfoByType";
		$.ajax({
			url : url,
			type : "post",
			cache : false,
			dataType : "json",
			data : {
				serial : sidkey,
				type:type
			},
			global : true,
			success : function(data) {
				if (data.status == 1) {
					$("#sidKeyPromote").val(data.sidKey);
					$("#staffDetailP").html(data.html);
				} else
					$("div[loading-msg='true']").html("illegal request");
			},
			error : function(err) {
				$("div[loading-msg='true']").html("");
			}
		});
	});
	
	//获得再入职审批数据
	$("a[node-approvalsReentry]").click(function(){
		var sidkey=$(this).attr('node-sidKey');
		var type='STAFF';
		
		var url = "/ajaxGetStaffInfoByType";
		$.ajax({
			url : url,
			type : "post",
			cache : false,
			dataType : "json",
			data : {
				serial : sidkey,
				type:type
			},
			global : true,
			success : function(data) {
				if (data.status == 1) {
					$("#sidKeyReentry").val(data.sidKey);
					$("#staffDetailReentry").html(data.html);
				} else
					$("div[loading-msg='true']").html("illegal request");
			},
			error : function(err) {
				$("div[loading-msg='true']").html("");
			}
		});
	});
	
	//获得员工更新数据
	$("a[node-employeeInfo]").click(function(){
		var sidkey=$(this).attr('node-sidKey');
		var type='EMPLOYEE';
		
		
		
		var url = "/ajaxGetStaffInfoByType";
		$.ajax({
			url : url,
			type : "post",
			cache : false,
			dataType : "json",
			data : {
				serial : sidkey,
				type:type
			},
			global : true,
			success : function(data) {
				if (data.status == 1) {
					$("#sidKeyEmployeeInfo").val(data.sidKey);
					$("#EMPLOYEENC").html(data.html);
					
				} else
					$("div[loading-msg='true']").html("illegal request");
			},
			error : function(err) {
				$("div[loading-msg='true']").html("");
			}
		});
	});
	
	//转职为试用
	$("a[node-Transfer]").click(function(){
		var sidkey=$(this).attr('node-sidKey');
		
		var url = "/ajaxGetStaffInfoBySid";
		$.ajax({
			url : url,
			type : "post",
			cache : false,
			dataType : "json",
			data : {
				serial : sidkey
			},
			global : true,
			success : function(data) {
				if (data.status == 1) {
				
					$("#sidKeyTRIAL").val(data.detail.sidKey);
					$("#transferJobNumber").html(data.detail.jobNumber);
					$("#transferUsername").html(data.detail.username);
					
					var cateDepart=data.detail.category;
					if(data.detail.department)
						cateDepart+=data.detail.department.departmentName;
					$("#transferCategory").html(cateDepart);
					
					$("#transferPosition").html(data.detail.position);
					$("#transferHiredate").html(data.detail.hiredate);
					$("#transferHiredate2").html(' 已入职 '+data.detail.workforce+' 天');
				} else
					$("div[loading-msg='true']").html("illegal request");
			},
			error : function(err) {
			}
		});
	});
	
	//转职为正式
	$("a[node-TransferFORMAL]").click(function(){
		var sidkey=$(this).attr('node-sidKey');
		
		var url = "/ajaxGetStaffInfoBySid";
		$.ajax({
			url : url,
			type : "post",
			cache : false,
			dataType : "json",
			data : {
				serial : sidkey
			},
			global : true,
			success : function(data) {
				if (data.status == 1) {
				
					$("#sidKeyREGULARS").val(data.detail.sidKey);
					$("#formalJobNumber").html(data.detail.jobNumber);
					$("#formalUsername").html(data.detail.username);
					
					var cateDepart=data.detail.category;
					if(data.detail.department)
						cateDepart+=data.detail.department.departmentName;
					$("#formalCategory").html(cateDepart);
					
					$("#formalPosition").html(data.detail.position);
					$("#formalHiredate").html(data.detail.hiredate);
					$("#formalHiredate2").html(' 已入职 '+data.detail.workforce+' 天');
					$("#formalProbationaryDate").html(data.detail.probationaryDate);
				} else
					$("div[loading-msg='true']").html("illegal request");
			},
			error : function(err) {
			}
		});
	});
	
	//转职为离职
	$("a[node-TransferDimission]").click(function(){
		var sidkey=$(this).attr('node-sidKey');
		
		var url = "/ajaxGetStaffInfoBySid";
		$.ajax({
			url : url,
			type : "post",
			cache : false,
			dataType : "json",
			data : {
				serial : sidkey
			},
			global : true,
			success : function(data) {
				if (data.status == 1) {
					console.log(data);
					$("#sidKeyDismiss").val(data.detail.sidKey);
					$("#DimissionJobNumber").html(data.detail.jobNumber);
					$("#DimissionUsername").html(data.detail.username);
					
					var cateDepart=data.detail.category;
					if(data.detail.departmentID!=0)
						cateDepart+="/"+data.detail.department.departmentName;
					$("#DimissionCategory").html(cateDepart);
					
					$("#DimissionPosition").html(data.detail.position);
					$("#DimissionHiredate").html(data.detail.hiredate);
					$("#DimissionHiredate2").html(' 已入职 '+data.detail.workforce+' 天');
					$("#applyLeaveDate2").val(data.detail.applyLeaveDate);
					
				} else
					$("div[loading-msg='true']").html("illegal request");
			},
			error : function(err) {
			}
		});
	});
	
	//在入职
	$("a[node-TransferReentry]").click(function(){
		var sidkey=$(this).attr('node-sidKey');
		
		var url = "/ajaxGetStaffInfoBySid";
		$.ajax({
			url : url,
			type : "post",
			cache : false,
			dataType : "json",
			data : {
				serial : sidkey
			},
			global : true,
			success : function(data) {
				if (data.status == 1) {
				
					$("#sidKeyReentry").val(data.detail.sidKey);
					$("#ReentryJobNumber").html(data.detail.jobNumber);
					$("#ReentryUsername").html(data.detail.username);
					
					var cateDepart=data.detail.category;
					if(data.detail.department)
						cateDepart+=data.detail.department.departmentName;
					$("#ReentryCategory").html(cateDepart);
					
					$("#ReentryPosition").html(data.detail.position);
					$("#ReentryHiredate").html(data.detail.dimissionDate);
					$("#ReentryHiredate2").html(' 已离职 '+data.detail.workforceDimission+' 天');
					
				} else
					$("div[loading-msg='true']").html("illegal request");
			},
			error : function(err) {
			}
		});
	});
	
	//员工的筛选
	$('select[node-pendStatus]').change(function() {
		 $('#hrEmployee').submit();
	});
	$('select[node-nature]').change(function() {
		 $('#hrEmployee').submit();
	});
	$('select[node-cid_did]').change(function() {
		 $('#hrEmployee').submit();
	});
	
	//编辑员工CLD访问权限
	$('a[employee-access]').click(function() {
		var sidkey=$(this).attr('node-sidKey');
		var selectData=$(this).attr('select-data');
		console.log(selectData);
		$("#Access_INFORMATION").attr("checked",false);
		$("#Access_DIRECTORIES").attr("checked",false);
		$("#Access_LOCK").attr("checked",false);
		$("#Access_RECEIPTS").attr("checked",false);
		$("#Access_INVOICE").attr("checked",false);
		$("#Access_HR").attr("checked",false);
		$("#Access_BUILD").attr("checked",false);
		if(selectData!=''){
		var jsonStr = JSON.parse(selectData);
		for(var j = 0;j<jsonStr.length;j++){
			console.log(jsonStr[j]);
			if(jsonStr[j]=='INFORMATION'){
				$("#Access_INFORMATION").attr("checked",true);
			}
			if(jsonStr[j]=='DIRECTORIES'){
				$("#Access_DIRECTORIES").attr("checked",true);
			}
			if(jsonStr[j]=='LOCK'){
				$("#Access_LOCK").attr("checked",true);
			}
			if(jsonStr[j]=='RECEIPTS'){
				$("#Access_RECEIPTS").attr("checked",true);
			}
			if(jsonStr[j]=='INVOICE'){
				$("#Access_INVOICE").attr("checked",true);
			}
			if(jsonStr[j]=='HR'){
				$("#Access_HR").attr("checked",true);
			}
			if(jsonStr[j]=='BUILD'){
				$("#Access_BUILD").attr("checked",true);
			}
		}
		}
		
		$("#sidKeyAccess").val(sidkey);
	});
	
	//编辑员工访问客户地区权限
	$('a[employee-district]').click(function() {
		var sidkey=$(this).attr('node-sidKey');
		$("#sidKeyDistrict").val(sidkey);
		var url = "/ajaxGetDistrictByLv1";
		$.ajax({
			url : url,
			type : "post",
			cache : false,
			dataType : "json",
			data : {
				serial : sidkey
			},
			global : true,
			success : function(data) {
				if (data.status == 1) {
					$("#StaffDistrictHtml").html(data.html);
					
				} else
					$("#StaffDistrictHtml").html("illegal request");
			},
			error : function(err) {
			}
		});
		
		
		
	});
	
	//跳转到员工权限设置页面
	$('input[node-setApproval]').click(function() {
		window.location.replace("/hrEmployeeApprovalsSetting");
	});
	
	//跳转到员工页面
	$('input[node-employeeInfo]').click(function() {
		window.location.replace("/hrEmployee");
	});
	
	
	//岗位设置
	$("a[node-ediPosition]").click(function(){
		var pidkey=$(this).attr('pidKey');
		
		var url = "/ajaxGetPositionByPid";
		$.ajax({
			url : url,
			type : "post",
			cache : false,
			dataType : "json",
			data : {
				pidkey : pidkey
			},
			global : true,
			success : function(data) {
				if (data.status == 1) {
				
					
					$("#pidkeyUpdate").val(data.detail.pidKey);
					$("#positionNameEdi").val(data.detail.positionName);
					$("#positionDescribeEdi").val(data.detail.positionDescribe);
					$("#baseWageEdi").val(data.detail.baseWage);
					$("#postWageEdi").val(data.detail.postWage);
					$("#achievementBonusEdi").val(data.detail.achievementBonus);
					
					
				} else
					$("div[loading-msg='true']").html("illegal request");
			},
			error : function(err) {
			}
		});
	});
	
	
	$("a[node-delPosition]").click(function(){
		var pidkey=$(this).attr('pidKey');
		
		var url = "/ajaxGetPositionByPid";
		$.ajax({
			url : url,
			type : "post",
			cache : false,
			dataType : "json",
			data : {
				pidkey : pidkey
			},
			global : true,
			success : function(data) {
				if (data.status == 1) {
					$("#pidkeyDel").val(data.detail.pidKey);
					$("#delPositionHtml").html("是否删除岗位“"+data.detail.positionName+"“");
				} else
					$("div[loading-msg='true']").html("illegal request");
			},
			error : function(err) {
			}
		});
	});
	
	$("a[node-PositionStaff]").click(function(){
		var pidkey=$(this).attr('pidKey');
		
		var url = "/ajaxGetStaffByPid";
		$.ajax({
			url : url,
			type : "post",
			cache : false,
			dataType : "json",
			data : {
				pidkey : pidkey
			},
			global : true,
			success : function(data) {
				if (data.status == 1) {
					
					
					$("#positionNameHtml").html(data.positionName);
					$("#positionStaffHTMl").html(data.html);
				} else
					$("#positionStaffHTMl").html("illegal request");
			},
			error : function(err) {
			}
		});
	});
	
	$("a[node-Promotion]").click(function(){
		var sidkey=$(this).attr('node-sidKey');
		
		var url = "/ajaxGetPromotionStaffByPid";
		$.ajax({
			url : url,
			type : "post",
			cache : false,
			dataType : "json",
			data : {
				sidkey : sidkey
			},
			global : true,
			success : function(data) {
				if (data.status == 1) {
					
					
					$("#sidKeyPromote").val(data.detail.sidKey);
					$("#staffPromotionHtml").html(data.html);
					//data.detail.positionId
					//$("#positionStaffSelect").find("option[text='程序员']").attr("selected",true);
					
					$("#positionStaffSelect").find("option[value='"+data.detail.positionIdKey+"_"+data.detail.positionDetail.positionName+"']").attr("selected",'selected');
					
					$("#promotionBaseWage").val(data.detail.positionDetail.baseWage);
					$("#promotionpostWage").val(data.detail.positionDetail.postWage);
					$("#promotionAchievementBonus").val(data.detail.positionDetail.achievementBonus);
				} else
					$("#staffPromotionHtml").html("illegal request");
			},
			error : function(err) {
			}
		});
	});
	
	
	$("#positionStaffSelect").change(function(){
		
		var nodeWages=$("option:selected", this).attr("node-wages");
		var nw=nodeWages.split("_");
		
		//var nodeWages=$(this).attr('node-wages');
		//console.log(nw);
		
		$("#promotionBaseWage").val(nw[0]);
		$("#promotionpostWage").val(nw[1]);
		$("#promotionAchievementBonus").val(nw[2]);
		
	
	});
	
	$("#positionStaffAddSelect").change(function(){
		
		var nodeWages=$("option:selected", this).attr("node-wages");
		var nw=nodeWages.split("_");
		
		//var nodeWages=$(this).attr('node-wages');
		//console.log(nw);
		
		$("#promotionAddBaseWage").val(nw[0]);
		$("#promotionAddpostWage").val(nw[1]);
		$("#promotionAddAchievementBonus").val(nw[2]);
		
	
	});
	
	
	
	
})

function CLEARTUIL(){
	$('input[name="staff[]"]:checked').each(function(){ 
		$(this).removeAttr("disabled");
		$(this).attr('checked',false);
		}); 
	$("#AUTDO").html('');
	$('#uidlist').val('');
}