/*************************************************************** *
ProName:EdorSMInput.js
*Title:定期结算维护
*Description:定期结算维护
*Copyright:Copyright (c) 2012
*Company:Sinosoft
* @author : 蔡云聪 * @version : 8.0 * @date : 2014-06-19 ****************************************************************/ var showInfo; var turnPage = new turnPageClass(); var turnPage1 = new turnPageClass(); var turnPage2 = new turnPageClass(); var tSQLInfo = new SqlClass(); function balanceSubmit(){ if(fm.BalanceOnState.value==''||fm.BalanceOnState.value==null){ i18nAlert("请录入结算方式!", "LIS-03318"); return false; } if(fm.BalanceOnState.value=='0'){ if(!verifyForm("fm")){ return false; } } if (fm.BalanceMoney.value!="" || fm.BalanceMoney.value != null) { var tBalanceMoney = fm.BalanceMoney.value; if (!checkDecimalFormat(tBalanceMoney, 10, 2)) { i18nAlert("结算金额整数位不应超过10位,小数位不应超过2位!", ""); return false; } } if(fm.BalanceOnState.value=='0') { var tCvaliDate = document.all('CValiDate').value; var ContEndDate = document.all('ContEndDate').value; var tStartDate = document.all('ValDate').value; var tEndDate = document.all('EndDate').value; if (tStartDate < tCvaliDate || tStartDate > ContEndDate) { i18nAlert("输入的【定期结算起期】需在保单的有效期内,请核实!", ""); return false; } if (tEndDate > ContEndDate || tEndDate < tCvaliDate) { i18nAlert("输入的【定期结算止期】需在保单的有效期内,请核实!", ""); return false; } if (tStartDate >= tEndDate ) { i18nAlert("输入的【定期结算起期】不得晚于【定期结算止期】,请核实!", ""); return false; } var checkEndDate = addDateByCode(tStartDate,document.all("BalancePeriod").value); if (checkEndDate > tEndDate) { i18nAlert("输入的【定期结算起期】+【定期结算频率】不得晚于【定期结算止期】,请核实!", ""); return false; } } fm.action="../API/grp_pa/g_pos/EdorSMSave/ADD?Operate=INSERT&EdorType="+tEdorType+"&EdorNo="+tEdorNo+"&GrpContNo="+tGrpContNo+"&MissionID="+tMissionID+"&SubMissionID="+tSubMissionID+"&ActivityID="+tActivityID; submitForm(fm,"INSERT"); } function submitFunc(){ var showStr=i18nMessage("正在保存数据,请您稍候并且不要修改屏幕上的值或链接其他页面", "LIS-04525"); var urlStr="../common/jsp/MessagePage.jsp?picture=C&content=" + encodeURIComponent(showStr); //showInfo=window.showModelessDialog(urlStr,window,"status:no;help:0;close:0;dialogWidth:550px;dialogHeight:250px"); var name='提示'; //网页名称,可为空; var iWidth=550; //弹出窗口的宽度; var iHeight=250; //弹出窗口的高度; var iTop = (window.screen.availHeight - iHeight) / 2; //获得窗口的垂直位置 var iLeft = (window.screen.availWidth - iWidth) / 2; //获得窗口的水平位置 showInfo = window.open (urlStr,name, "status=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=0,titlebar=no,height="+ iHeight+",width="+iWidth+",innerHeight="+iHeight+",innerWidth=" +iWidth+",left="+iLeft+",top="+iTop,false); showInfo.focus(); } /** * 提交数据后返回操作 */ function afterSubmit(FlagStr, content) { if (typeof(showInfo)=="object" && typeof(showInfo)!="unknown") { showInfo.close(); } if (FlagStr=="Fail") { var urlStr = "../common/jsp/MessagePage.jsp?picture=C&content="+ encodeURIComponent(content); //showModalDialog(urlStr,window,"status:no;help:0;close:0;dialogWidth:550px;dialogHeight:250px"); var name='提示'; //网页名称,可为空; var iWidth=550; //弹出窗口的宽度; var iHeight=250; //弹出窗口的高度; var iTop = (window.screen.availHeight - iHeight) / 2; //获得窗口的垂直位置 var iLeft = (window.screen.availWidth - iWidth) / 2; //获得窗口的水平位置 showInfo = window.open (urlStr,name, "status=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=0,titlebar=no,height="+ iHeight+",width="+iWidth+",innerHeight="+iHeight+",innerWidth=" +iWidth+",left="+iLeft+",top="+iTop,false); showInfo.focus(); } else { var urlStr = "../common/jsp/MessagePage.jsp?picture=S&content="+ encodeURIComponent(content); //showModalDialog(urlStr,window,"status:no;help:0;close:0;dialogWidth:550px;dialogHeight:250px"); var name='提示'; //网页名称,可为空; var iWidth=550; //弹出窗口的宽度; var iHeight=250; //弹出窗口的高度; var iTop = (window.screen.availHeight - iHeight) / 2; //获得窗口的垂直位置 var iLeft = (window.screen.availWidth - iWidth) / 2; //获得窗口的水平位置 showInfo = window.open (urlStr,name, "status=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=0,titlebar=no,height="+ iHeight+",width="+iWidth+",innerHeight="+iHeight+",innerWidth=" +iWidth+",left="+iLeft+",top="+iTop,false); showInfo.focus(); } } function submitForm(obj, tOperate) { submitFunc(); mOperate = tOperate; //obj.submit(); //提交 ajaxSubmit2(obj); } function afterCodeSelect(o, p){ if(o=='balanceonstate'){ if(p.value=='0'){ td1.style.display=''; td2.style.display=''; // td3.style.display=''; // td4.style.display=''; td9.style.display=''; td10.style.display=''; td11.style.display=''; td12.style.display=''; td13.style.display=''; td14.style.display=''; }else if(p.value=='1'){ td1.style.display='none'; td2.style.display='none'; td9.style.display='none'; td10.style.display='none'; td11.style.display='none'; td12.style.display='none'; td13.style.display='none'; td14.style.display='none'; // td3.style.display='none'; // td4.style.display='none'; td5.style.display=''; td6.style.display=''; td7.style.display=''; td8.style.display=''; fm.BalancePeriod.value=''; fm.BalancePeriodName.value=''; // fm.GracePeriod.value=''; fm.BalanceMoney.value=''; fm.ValDate.value=''; fm.EndDate.value=''; } } } // 查询定期结算数据 function queryBalanceInfo() { //查询保单的生效日期和终止日期 tSQLInfo = new SqlClass(); tSQLInfo.setResourceName("g_pos.EdorSMSql"); tSQLInfo.setModule("grp_pa"); tSQLInfo.setSqlId("EdorSMSql3"); tSQLInfo.addSubPara(tGrpContNo); var upArrResul = easyExecSql(tSQLInfo.getString()); if (upArrResul != null) { document.all('CValiDate').value = upArrResul[0][0]; document.all('ContEndDate').value = upArrResul[0][1]; // document.all('EndDate').value = upArrResul[0][1]; } tSQLInfo = new SqlClass(); tSQLInfo.setModule("grp_pa"); tSQLInfo.setResourceName("g_pos.EdorSMSql"); tSQLInfo.setSqlId("EdorSMSql1"); tSQLInfo.addSubPara(tEdorNo); tSQLInfo.addSubPara(tEdorType); tSQLInfo.addSubPara(tGrpContNo); var arrRuselt = easyExecSql(tSQLInfo.getString(), 1, 0, 1); if (arrRuselt == null) { tSQLInfo = new SqlClass(); tSQLInfo.setModule("grp_pa"); tSQLInfo.setResourceName("g_pos.EdorSMSql"); tSQLInfo.setSqlId("EdorSMSql2"); tSQLInfo.addSubPara(tGrpContNo); var arrRuselt = easyExecSql(tSQLInfo.getString(), 1, 0, 1); if (arrRuselt != null) { fm.BalanceOnState.value = arrRuselt[0][4]; fm.BalanceOnStateName.value = arrRuselt[0][5]; fm.BalancePeriod.value = arrRuselt[0][6]; fm.BalancePeriodName.value = arrRuselt[0][7]; // fm.GracePeriod.value=arrRuselt[0][8]; fm.ValDate.value = arrRuselt[0][9]; fm.EndDate.value = arrRuselt[0][10]; fm.BalanceMoney.value = arrRuselt[0][11]; }else{ fm.EndDate.value = document.all('ContEndDate').value } } else { fm.BalanceOnState.value = arrRuselt[0][0]; fm.BalanceOnStateName.value = arrRuselt[0][1]; fm.BalancePeriod.value = arrRuselt[0][2]; fm.BalancePeriodName.value = arrRuselt[0][3]; // fm.GracePeriod.value=arrRuselt[0][4]; fm.ValDate.value = arrRuselt[0][5]; fm.EndDate.value = arrRuselt[0][6]; fm.BalanceMoney.value = arrRuselt[0][7]; } } function showBalanceOnState(){ if(fm.BalanceOnState.value=="0"){ td1.style.display=''; td2.style.display=''; // td3.style.display=''; // td4.style.display=''; td9.style.display=''; td10.style.display=''; td11.style.display=''; td12.style.display=''; td13.style.display=''; td14.style.display=''; } if(fm.BalanceOnState.value=="1"){ td1.style.display='none'; td2.style.display='none'; td9.style.display='none'; td10.style.display='none'; td11.style.display='none'; td12.style.display='none'; td13.style.display='none'; td14.style.display='none'; td5.style.display=''; td6.style.display=''; td7.style.display=''; td8.style.display=''; fm.BalancePeriod.value=''; fm.BalancePeriodName.value=''; // fm.GracePeriod.value=''; fm.BalanceMoney.value=''; fm.ValDate.value=''; fm.EndDate.value=''; } } /** * 校验数据整数位于小数位长度 */ function checkDecimalFormat(cValue, cLen1, cLen2) { if (cValue=='' || cValue==null) {//为空, return true; } var tLen = (""+cValue+"").length; var tLen1 = (""+cValue+"").indexOf("."); var tLen2 = 0; if (tLen1==-1) { tLen1 = tLen; } else { tLen2 = tLen - tLen1 - 1; } if (Number(tLen1)>Number(cLen1)) { return false; } if (Number(tLen2)>Number(cLen2)) { return false; } return true; } function returnbak() { top.opener.initForm(); top.close(); } /** * 校验并执行日期加法操作 * @param {string} dateStr - 日期字符串,格式:yyyy-MM-dd * @param {string} unitCode - 单位码值:'01'(月), '03'(季), '06'(半年), '12'(年) * @returns {Object} 包含 success、result、message 的结果对象 */ function addDateByCode(dateStr, unitCode) { // 1. 定义码值映射和校验规则 const validCodes = { '01': { type: 'month', amount: 1, label: '月' }, '03': { type: 'month', amount: 3, label: '季' }, '06': { type: 'month', amount: 6, label: '半年' }, '12': { type: 'year', amount: 1, label: '年' } }; // 2. 校验码值 if (!validCodes.hasOwnProperty(unitCode)) { i18nAlert("无效的单位码值:"+unitCode+"。支持的码值为:'01'(月)、'03'(季)、'06'(半年)、'12'(年)", ""); return false; } const { type, amount, label } = validCodes[unitCode]; // 3. 校验日期格式(基本正则校验) const dateRegex = /^\d{4}-\d{2}-\d{2}$/; if (!dateRegex.test(dateStr)) { i18nAlert("日期格式不正确:"+unitCode+",请使用 yyyy-MM-dd 格式", ""); return false; } // 4. 解析日期并校验有效性(防止如 2025-02-30 这类非法日期) const [yearStr, monthStr, dayStr] = dateStr.split('-'); const year = parseInt(yearStr, 10); const month = parseInt(monthStr, 10); // 1-12 const day = parseInt(dayStr, 10); // 构造 Date 对象(注意 JS 中月份从 0 开始) const date = new Date(year, month - 1, day); // 校验是否为有效日期 if ( date.getFullYear() !== year || date.getMonth() !== month - 1 || date.getDate() !== day ) { i18nAlert("无效的日期:"+unitCode+",请使用 yyyy-MM-dd 格式", ""); return false; } // 5. 执行日期加法 let resultDate = new Date(date); // 复制原日期,避免修改 if (type === 'month') { resultDate.setMonth(resultDate.getMonth() + amount); } else if (type === 'year') { resultDate.setFullYear(resultDate.getFullYear() + amount); } // 6. 统一减去一天 resultDate.setDate(resultDate.getDate() - 1); // 7. 格式化结果日期 const formatDate = (d) => { const y = d.getFullYear(); const m = String(d.getMonth() + 1).padStart(2, '0'); const dDay = String(d.getDate()).padStart(2, '0'); return `${y}-${m}-${dDay}`; }; // 8. 返回成功结果 return formatDate(resultDate); }