gogozz

导航

明细表,根据开始日期的值,+1年赋值给结束日期JS

<script>
 
jQuery(document).ready(function(){
    
    
    var yxqqsrq = WfForm.convertFieldNameToId("yxqqsrq", "detail_1");
    var yxjzrq = WfForm.convertFieldNameToId("yxjzrq", "detail_1");
  //字段值改变事件 WfForm.bindDetailFieldChangeEvent(yxqqsrq,
function(id,rowIndex,value){ console.log("WfForm.bindDetailFieldChangeEvent--",id,rowIndex,value); let lastyeardate = getOneYearLast(value) WfForm.changeFieldValue(yxjzrq+"_"+rowIndex, {value:lastyeardate}); }); //明细新增事件 WfForm.registerAction(WfForm.ACTION_ADDROW+"1", function(i){ let yxqqsrqvalue = WfForm.getFieldValue(yxqqsrq+"_"+i); let lastyeardate = getOneYearLast(yxqqsrqvalue) WfForm.changeFieldValue(yxjzrq+"_"+i, {value:lastyeardate}); });
  //保存后页面刷新
var rowArr = WfForm.getDetailAllRowIndexStr("detail_1").split(","); for(let j=0; j<rowArr.length; j++){ let i = rowArr[j]; let yxqqsrqvalue = WfForm.getFieldValue(yxqqsrq+"_"+i); let lastyeardate = getOneYearLast(yxqqsrqvalue) WfForm.changeFieldValue(yxjzrq+"_"+i, {value:lastyeardate}); } //提交校验 WfForm.registerCheckEvent(WfForm.OPER_SAVE+","+WfForm.OPER_SUBMIT, function(callback){ //开始日期和截止日期只能365天之内 let rowArr = WfForm.getDetailAllRowIndexStr("detail_1").split(","); for(let j=0; j<rowArr.length; j++){ let i = rowArr[j]; let yxqqsrqvalue = WfForm.getFieldValue(yxqqsrq+"_"+i); let yxjzrqvalue = WfForm.getFieldValue(yxjzrq+"_"+i); let diffdate = daysDiff(new Date(yxqqsrqvalue), new Date(yxjzrqvalue)) console.log(diffdate) if(Number(diffdate)>366){ alert("起始日期和截止日期不能超过366天!"); return; } } callback(); //继续提交需调用callback,不调用代表阻断 }); });

//加一年
function getOneYearLast(date){ var date = new Date(date); var year = date.getFullYear()+1; var month = date.getMonth() + 1; var day = date.getDate(); if (month < 10) { month = "0" + month; } if (day < 10) { day = "0" + day; } var enTime = year + "-" + month + "-" + day; return enTime }

//计算两日期相差天数
function daysDiff(date, date2){ return Math.ceil(Math.abs(date - date2) / 86400000); } </script>

 

posted on 2023-10-12 14:33  stfzhuang  阅读(133)  评论(0编辑  收藏  举报