标签:jquery
function save(flag){
var groupId = $(‘input[name="groupId"]‘).val(); //团组groupId
//关于创建时间的定义
var date = new Date();
var year = date.getFullYear();
var month = date.getMonth() + 1;
var dt = date.getDate();
var today = year + "-" + month + "-" + dt;
var flights = $(‘input[name="flights"]‘).val(); //国内往返机票费用
var visa = $(‘input[name="visa"]‘).val(); //国内签证费用
var airport = $(‘input[name="airport"]‘).val(); //国内机场费用
var domestic = $(‘input[name="domestic"]‘).val();//国内其他费用
var data = []; //需要保存的数据集合
var countryNames = $("input[name^=‘countryName‘]");
countryNames.each(function(i){ //i是国家标示
var zsfRsTotal = 0,hsfRsTotal = 0,gzfRsTotal = 0; //各个类型总添加人数
var countryName = this;
var fahterId = $("input[name^=‘fatherId"+i+"‘]"); //主表主键
var traffice = $("input[name^=‘traffic"+i+"‘]"); //获得某个国家的所有交通费
var overseas = $("input[name^=‘overseas"+i+"‘]"); //获得某个国家的所有其他费用
var currency = $("input[name^=‘currency"+i+"‘]"); //获得某个国家的所有币种费用
var exchangeRate = $("input[name^=‘exchangeRate"+i+"‘]"); //获得某个国家的所有汇率费用
var countrys = {
‘id‘:fahterId.val(),
‘flights‘:flights,
‘visa‘:visa,
‘airport‘:airport,
‘domestic‘:domestic,
‘country‘: countryName.value,
‘traffic‘:traffice.val(),
‘overseas‘:overseas.val(),
‘currency‘:currency.val(),
‘exchangeRate‘:exchangeRate.val(),
‘flag‘:flag,
‘creDate‘:today,
‘groupId‘:groupId,
‘accommodation‘:‘‘,
‘meals‘:‘‘,
‘miscellaneous‘:‘‘,
fydata: []
}
var zsf = $("input[name^=‘accommodation"+i+"‘]"); //获得某个国家的所有住宿费
//var zsf = $("tr[id^=‘zsf"+i+"‘]")
var hsf = $("input[name^=‘meals"+i+"‘]"); //获得某个国家的所有伙食费
var gzf = $("input[name^=‘miscellaneous"+i+"‘]"); //获得某个国家的所有公杂费
zsf.each(function(j){ //j为国家所有住宿费类型的下标
var zsfType = this;
countrys.accommodation=zsfType.value;//设置住宿费用
var rsObj = $("input[id^=‘"+zsfType.name+"rs‘]");
rsObj.each(function(z){
var fyitems = {
‘id‘:‘‘,
‘creDate‘:today,
‘groupId‘:groupId,
‘budgetId‘:fahterId.val(),
‘days‘:‘‘,
‘member‘:‘‘,
‘flag‘:‘‘
}
var m3 = this;
var tsNum = $("input[id^=‘"+zsfType.name+"ts‘]")[z]; //取得天数对应的人数
fyitems.member=m3.value;//住宿费对应的人数
fyitems.days=tsNum.value;//住宿费对应的天数
fyitems.flag=‘1‘;//设置住宿费对应的标示
countrys.fydata.push(fyitems); //获得某个国家的所有住宿费
zsfRsTotal +=parseInt(m3.value); //统计住宿费总人数
});
});
hsf.each(function(j){ //j为国家所有伙食费类型的下标
var hsfType = this;
countrys.meals=$("input[name^=‘meals"+i+"‘]").val();//设置伙食费
var hsfrsObj = $("input[id^=‘mealsmiscellaneous"+i+"rs‘]");
hsfrsObj.each(function(z){
var fyitems = {
‘id‘:‘‘,
‘creDate‘:today,
‘groupId‘:groupId,
‘budgetId‘:fahterId.val(),
‘days‘:‘‘,
‘member‘:‘‘,
‘flag‘:‘‘
}
var hsfnum = this;
var tsNum = $("input[id^=‘"+hsfnum.name+"ts‘]")[z]; //取得天数对应的人数
fyitems.member=hsfnum.value;//伙食费对应的人数
fyitems.days=tsNum.value;//伙食费对应的人数
fyitems.flag=‘2‘;//设置伙食费对应的标示
countrys.fydata.push(fyitems); //获得某个国家的所有伙食费
hsfRsTotal +=parseInt(hsfnum.value); //统计伙食费总人数
});
});
gzf.each(function(j){ //j为国家所有公杂费类型的下标
var gzfType = this;
countrys.miscellaneous=$("input[name^=‘miscellaneous"+i+"‘]").val();//设置公杂费
var gzfrsObj = $("input[id^=‘mealsmiscellaneous"+i+"rs‘]");
gzfrsObj.each(function(z){
var fyitems = {
‘id‘:‘‘,
‘creDate‘:today,
‘groupId‘:groupId,
‘budgetId‘:fahterId.val(),
‘days‘:‘‘,
‘member‘:‘‘,
‘flag‘:‘‘
}
var gzfnum = this;
var tsNum = $("input[id^=‘"+gzfnum.name+"ts‘]")[z]; //取得天数对应的人数
fyitems.member=gzfnum.value;//公杂费对应的人数
fyitems.days=tsNum.value;//公杂费对应的天数
fyitems.flag=‘3‘;//设置伙食费对应的标示
countrys.fydata.push(fyitems); //获得某个国家的所有住宿费
gzfRsTotal +=parseInt(gzfnum.value); //统计公杂费总人数
});
});
var groupMember = <%=groupNum%>; //获取团组的人数
if(groupMember!=‘‘&&groupMember!=null){
if(zsfRsTotal>groupMember){
alert("住宿费总人数不能大于团组人数,请重新填写!");
return;
}
if(hsfRsTotal>groupMember){
alert("伙食费总人数不能大于团组人数,请重新填写!");
return;
}
if(gzfRsTotal>groupMember){
alert("公杂费总人数不能大于团组人数,请重新填写!");
return;
}
}
data.push(countrys);
});
if(!isNumber($(‘input[name^="overseas"]‘).val())||!isNumber($(‘input[name^="traffic"]‘).val())||!isNumber($(‘input[name^="miscellaneous"]‘).val())||!isNumber($(‘input[name^="meals"]‘).val())||!isNumber($(‘input[name^="accommodation"]‘).val())||!isNumber($(‘input[name^="domestic"]‘).val())||!isNumber($(‘input[name^="airport"]‘).val())||!isNumber($(‘input[name^="flights"]‘).val()) || !isNumber($(‘input[name^="visa"]‘).val())) {
alert(‘输入项不能为空并且为数字!‘);
return false;
}else if($(‘input[name^="currency"]‘).val()==‘‘){
alert(‘请输入币种!‘);
return false;
}else{// 判断住宿费、伙食费、公杂费人数不能为空!
$(‘tr[id^="zsf"]‘).each(function() {
if($(this).find(‘input[id="accommodation0rs"]‘).val()==‘‘){
alert("住宿费人数不能为空!")
return false;
}else if($(this).find(‘input[id="accommodation0ts"]‘).val()==‘‘){
alert("住宿费天数不能为空!")
return false;
}
});
$(‘tr[id^="hsf"]‘).each(function() {
if($(this).find(‘input[id="mealsmiscellaneous0rs"]‘).val()==‘‘){
alert("伙食费、公杂费人数不能为空!")
return false;
}else if($(this).find(‘input[id="mealsmiscellaneous0ts"]‘).val()==‘‘){
alert("伙食费、公杂费天数不能为空!")
return false;
}
});
}
$.ajax({
type : "post",
url : "/internation/InternationBudgetAction.do?method=saveView&groupId=${InternationGroupVOE.groupId}&flag="+flag+"",
data:{datalist:encodeURI(JSON.stringify(data))},
dataType: ‘json‘,
success : function (response) {
alert(‘保存信息成功!‘);
},
error : function (response) {
alert(‘保存信息失败!‘);
}
});
/**
if(!isNumber($(‘input[name="domesticTotal"]‘).val()) || !isNumber($(‘input[name="overseasTotal"]‘).val())) {
alert(‘小计应该为数字!‘);
return false;
}*/
//document.InternationBudgetVOE.method.value=‘saveView‘;
//document.InternationBudgetVOE.submit(); //提交暂时注释
}
标签:jquery
原文地址:http://2388249.blog.51cto.com/2378249/1437673