//REQHOP8-170103-68 心安怡自动化理算需求 Add wbs start 2017/4/24
function selectedClassFn(){
	// if($("#className").val()==undefined || $("#className").val())
	var classCode=$("#className").val();
	if(classCode==undefined || classCode==null || classCode==""){
		alert("请选择需要修改的产品!");
		return;
	}else{
		$("#productCode").val(classCode);
		$("#formId").attr("action","claimAutomation.do");
		$("#formId").attr("method","POST");
		$("#formId").submit();
	}

}

function selectedClassFnFirst(){
	// $("#productCode").val($("#className").val());
	$("#formId").attr("action","claimAutomation.do");
	$("#formId").attr("method","POST");
	$("#formId").submit();
}

//保存理赔自动化规则
function saveClaimAutomation(){
	//取分公司数据
	var all = $("input[dataClass='branch']");
	var params = {};
	var k = 0;
	for (var i = 0; i < all.length; i++) {
		if(all[i].checked){
			params["branchSeqId"+k] = all[i].value;
			k++;
		}
	}
	//产品代码
	var classCode=$("#className").val();
	params["productCode"]=classCode;
	if(classCode==undefined || classCode==null || classCode==""){
		alert("请选择需要修改的产品!");
		return;
	}
	//预估金额
	params["estimateamt"]=$("#estimateamt").val();
	//出险日期距离保单生效日期
	params["accident"] = $("#accident").val();
	//取出险人年龄数据
	var age = $("input[dataClass='age']");
	var k1 = 0;
	for (var j = 0; j < age.length; j++) {
		if(age[j].checked){
			params["ageSeqId"+k1] = age[j].value;
			k1++;
		}
	}
	//取赔付金额数据
	params["realPayAmt"]=$("#realPayAmt").val();

	//取抽检率
	params["sampling"]=$("#sampling").val();

	$.ajax({
		type: "POST",
		url : 'saveClaimAutomation.do',
		data: params,
		error: function(){
			alert("保存理赔自动化规则出错!");
		},
		success: function(data){
			if("success" == data){
				alert("保存规则成功!");
			}else if("notfound" == data){
				alert("保存规则失败，失败原因：通过产品代码未找到相关产品!");
			}
		}
	});
}



//wbs 全选function
//判断分公司
function selectRegAll() {
	var branchSel = $("#branchSel");
	var all = $("input[dataClass='branch']");
	if(branchSel.is(":checked")){
		all.prop("checked",true);
	}else{
		all.prop("checked",false);
	}
}

//判断出险人年龄
function selectAgeAll() {
	var ageSel = $("#ageSel");
	var all = $("input[dataClass='age']");
	if(ageSel.is(":checked")){
		all.prop("checked",true);
	}else{
		all.prop("checked",false);
	}
}

//审核规则判断
function selectAuditAll() {
	var auditSel = $("#auditSel");
	var all = $("input[dataClass='audit']");
	if(auditSel.is(":checked")){
		all.prop("checked",true);
	}else{
		all.prop("checked",false);
	}
}

//理算校验规则
function selectGverifyAll() {
	var gverifySel = $("#gverifySel");
	var all = $("input[dataClass='gverify']");
	if(gverifySel.is(":checked")){
		all.prop("checked",true);
	}else{
		all.prop("checked",false);
	}
}


//审核规则激活状态
function activeStatus(str) {
	var all = $("input[dataClass='audit']");
	var classCode = $("#className").val();
	if(classCode==undefined || classCode==null || classCode==""){
		alert("请选择需要修改的产品!");
		return;
	}
	var params = {};
	var k = 0;
	for (var i = 0; i < all.length; i++) {
		if(all[i].checked){
			var invalid=$("#"+all[i].value).attr("value");
			if(str=="Y" && invalid!="1"){//未配置\未激活
				params["seqId"+k] = all[i].value;
				k++;
			}
			if(str=="N" && invalid=="1"){//已激活
				params["seqId"+k] = all[i].value;
				k++;
			}
		}
	}
	if(k==0 && str=="Y"){
		alert("请最少选择一条未激活的审核规则");
		return;
	}
	if(k==0 && str=="N"){
		alert("请最少选择一条已激活的审核规则");
		return;
	}
	params["classCode"]=classCode;
	params["str"]=str;
	params['flag']='FA';
	$.ajax({
		type: "POST",
		url : 'activeAudit.do',
		data: params,
		cache:false,
		error: function(){
			alert("激活或取消激活出错!");
			all.attr('checked',false);
			return;
		},
		success: function(data){
			if("success" == data.success){
				alert("激活规则成功!");
				all.attr('checked',false);
			}else if("cancel" == data.success){
				alert("取消激活规则成功!");
				all.attr('checked',false);
			}else if("notfound" == data.fail){
				alert("激活或取消激活失败");
				all.attr('checked',false);
			}
			var all1 = $("span[auditClass='audit']");
			all1.attr("value", "0");
			all1.text("未激活");
			for (var j = 0; j < data.list.length; j++) {
				var obj =data.list[j];
					$("#"+obj).attr("value","1");
					$("#"+obj).text("已激活");
			}
		}
	});
}

//审核规则add
function addAudit() {
	clearform();
	$("#addfaudit").val("0");
	$("#myModalLabel").text("新增审核规则");
	$('#myModal').modal('show');
}

/**理算规则add**/
function addGverify(){
	clearformGverify();
	$("#addGverify").val("0");
	$("#gverifyModalLabel").text("新增理算规则");
	$('#gverifyModal').modal('show');
}

/**理算规则清空表单**/
function clearformGverify() {
	$("#gverifyMsg").val("");
	$("#gverifyReMark").val("");
	// $("#addGverify").val("");
	$("#gverifyReValue").val("");
	$("#gverifyRePattern").val("");
	$("#gverifyForm").removeData("bs.modal");
}

/**理算规则add提交**/
function submitGverify(){
	var params={};
	params['regName']=$('#gverifyMsg').val();//理算规则详细
	params['regRemark']=$('#gverifyReMark').val();//提示
	params['regValue']=$('#addGverify').val();//状态
	params['seqId']=$('#gverifyseqId').val();//
	params['regValue'] = $("#gverifyReValue").val();//校验值
	params['regPattern'] = $("#gverifyRePattern").val();//校验方式
	params['flag']='GA';
	$.ajax({
		type:'post',
		url:'addOrEditAudit.do',
		data:params,
		cache:false,
		error: function(){
			alert("新增理算规则出错!");
		},
		success:function(data){
			if(data=='success'){
				alert('新增理算规则成功!');
				clearformGverify();
				$('#gverifyModal').remove();
				window.location.reload()
			}else if(data=='success1'){
				alert("修改理算规则成功!");
				clearformGverify();
				$("input[dataClass='gverify']:checked").attr('checked',false);
				$('#gverifyModal').remove();
				window.location.reload()
			}else{
				alert('新增理算规则失败!');
				clearformGverify();
				$('#gverifyModal').remove();
				window.location.reload()
			}
		}
	});
}
/**理算规则edit**/
function editGverify() {
	var all = $("input[dataClass='gverify']");
	var params1 = [];
	var k = 0;
	for (var i = 0; i < all.length; i++) {
		if(all[i].checked){
			params1[k] = all[i].value;
			k++;
		}
	}
	if(params1.length==1){
		var params = {};
		params['seqId'] = params1[0];
		$.ajax({
			type: "POST",
			url : 'findAudit.do',
			data: params,
			cache:false,
			error: function(){
				alert("编辑出错!");
			},
			success: function(data){
				if(data!=null){
					clearformGverify();
					$("#gverifyModalLabel").text("编辑理算规则");
					$('#gverifyseqId').val(data.seqId);
					$("#gverifyMsg").val(data.regName);
					$("#gverifyReMark").val(data.regRemark);
					// $("#addGverify").val(data.regValue);
					$("#gverifyReValue").val(data.regValue);
					$("#gverifyRePattern").val(data.regValue);
					$('#gverifyModal').modal('show');
				}else{
					clearformGverify();
					alert("编辑规则失败!");
				}
			}
		});
	}else {
		alert('请只选择一个理算规则');
	}
}
/**理算规则删除 该功能不用**/
function deleteGverify(){
	var all = $("input[dataClass='gverify']");
	var params1 = [];
	var k = 0;
	for (var i = 0; i < all.length; i++) {
		if(all[i].checked){
			params1[k] = all[i].value;
			k++;
		}
	}
	alert(params1.length);
	if(params1.length==1){
		var params = {};
		params['seqId'] = params1[0];
		$.ajax({
			type: "POST",
			url : 'deleteAudit.do',
			data: params,
			cache:false,
			error: function(){
				alert("删除出错!");
				window.location.reload();
			},
			success: function(data){
				if(null != data){
					alert("删除规则成功!");
					all.attr('checked',false);
					window.location.reload();
				}else {
					alert("删除规则失败!");
					all.attr('checked',false);
					window.location.reload();
				}
			}
		});
	}else {
		alert('请只选择一个理算规则');
	}
}

//审核规则add提交
function submitAudit() {
	var params = {};
	params['regName'] = $("#auditMsg").val();//审核规则详细
	params['regRemark'] = $("#auditReMark").val();//产品代码
	params['regInvalid'] = $("#addfaudit").val();//状态
	params['regValue'] = $("#auditReValue").val();//校验值
	params['regPattern'] = $("#auditRePattern").val();//校验方式
	params['seqId'] = $("#auditseqId").val();//seqId
	params['flag']='FA';
	$.ajax({
		type: "POST",
		url : 'addOrEditAudit.do',
		data: params,
		cache:false,
		error: function(){
			alert("新增审核规则出错!");
		},
		success: function(data){
			if("success" == data){
				alert("新增审核规则成功!");
				clearform();
				$("#myModal").remove();
				window.location.reload();
			}else if("notfound" == data){
				alert("新增审核规则失败");
				clearform();
				$("#myModal").remove();
				window.location.reload();
			}else if("success1" == data){
				alert("修改审核规则成功!");
				clearform();
				$("#myModal").remove();
				window.location.reload();
			}
		}
	});
}

//审核规则edit
function editAudit() {
	var all = $("input[dataClass='audit']");
	var params1 = [];
	var k = 0;
	for (var i = 0; i < all.length; i++) {
		if(all[i].checked){
			params1[k] = all[i].value;
			k++;
		}
	}
	if(params1.length==1){
		var params = {};
		params['seqId'] = params1[0];
		$.ajax({
			type: "POST",
			url : 'findAudit.do',
			data: params,
			cache:false,
			error: function(){
				alert("编辑出错!");
			},
			success: function(data){
				if(null != data){
					clearform();
					$("#myModalLabel").text("编辑审核规则");
					$("#auditseqId").val(data.seqId);
					$("#auditMsg").val(data.regName);
					$("#auditReMark").val(data.regRemark);
					$("#auditReValue").val(data.regValue);
					// $("#addfaudit").val(data.regInvalid);
					$("#auditRePattern").val(data.regPattern);
					$('#myModal').modal('show');
				}else {
					clearform();
					alert("编辑规则失败!");
				}
			}
		});
	}else {
		alert('请只选择一个审核规则');
	}
}

//审核规则删除
function deleteAudit() {
	var all = $("input[dataClass='audit']");
	var params1 = [];
	var k = 0;
	for (var i = 0; i < all.length; i++) {
		if(all[i].checked){
			params1[k] = all[i].value;
			k++;
		}
	}
	if(params1.length==1){
		var params = {};
		params['seqId'] = params1[0];
		$.ajax({
			type: "POST",
			url : 'deleteAudit.do',
			data: params,
			cache:false,
			error: function(){
				alert("删除出错!");
				window.location.reload()
			},
			success: function(data){
				if(null != data){
					alert("删除规则成功!");
					window.location.reload()
				}else {
					alert("删除规则失败!");
					window.location.reload()
				}
			}
		});
	}else {
		alert('请只选择一个审核规则');
	}
}





//理算规则激活和取消激活
function activeGverifyStatus(str) {
	var all = $("input[dataClass='gverify']");
	var classCode = $("#className").val();
	if(classCode==undefined || classCode==null || classCode==""){
		alert("请选择需要修改的产品!");
		return;
	}
	var params = {};
	var k = 0;
	for (var i = 0; i < all.length; i++) {
		if(all[i].checked) {
			var invalid = $("#" + all[i].value).attr("value");
			if (str == "Y" && invalid != "1") {//未配置\未激活
				params["seqId" + k] = all[i].value;
				k++;
			}
			if (str == "N" && invalid == "1") {//已激活
				params["seqId" + k] = all[i].value;
				k++;
			}
		}
	}
	if(k==0 && str=="Y"){
		alert("请最少选择一条未激活的理算规则");
		return;
	}
	if(k==0 && str=="N"){
		alert("请最少选择一条已激活的理算规则");
		return;
	}
	params["str"]=str;//激活还是取消激活
	params["classCode"] = classCode;//产品代码
	params["flag"]="GA";
	$.ajax({
		type: "POST",
		url : 'activeAudit.do',
		data: params,
		cache:false,
		error: function(){
			alert("激活或取消激活出错!");
			all.attr('checked',false);
			return;
		},
		success: function(data){
			if("success" == data.success){
				alert("激活规则成功!");
				all.attr('checked',false);
			}else if("cancel" == data.success){
				alert("取消激活规则成功!");
				all.attr('checked',false);
			}else if("notfound" == data.fail){
				alert("激活或取消激活规则失败!");
				all.attr('checked',false);
			}
			var all1 = $("span[gverifyClass='gverify']");
			all1.attr("value", "0");
			all1.text("未激活");
			for (var j = 0; j < data.list.length; j++) {
				var obj =data.list[j];
				$("#"+obj).attr("value","1");
				$("#"+obj).text("已激活");
			}
		}
	});
}


//审核规则清空表单
function clearform() {
	$("#auditMsg").val("");
	$("#auditReMark").val("");
	$("#addfaudit").val("");
	$("#auditRePattern").val("");
	$("#auditReValue").val("");
	$("#auditForm").removeData("bs.modal");
}


/**添加产品**/
function addProduct(){
	var classCode=$('#classCode').val();
	if(classCode==''||classCode==null){
		alert('请输入产品代码！');
		return;
	}
	var params={};
	params['classCode']=classCode;
		$.ajax({
			type:'post',
			url:'addProduct.do',
			data:params,
			cache:false,
			success:function(data){
				if(data=='success'){
					alert('添加成功！');
					$('#classCode').val('');
					window.location.reload()
				}else if(data=='notfound'){
					alert('没有相关产品代码！');
				}else if(data=='repeat'){
					alert('产品已存在！');
				}else{
					alert('添加失败！');
				}
			}
		});
}

//REQHOP8-170103-68 心安怡自动化理算需求 Add wbs end 2017/4/24
























