123 lines
4.7 KiB
JavaScript
123 lines
4.7 KiB
JavaScript
// 首台销售日期
|
||
var firstSaleDateField = WfForm.convertFieldNameToId("stxsrq");
|
||
// 跟踪时间
|
||
var trackTimeField = WfForm.convertFieldNameToId("gzsj");
|
||
// 跟踪时间为三个月以内
|
||
var threeMonthIndex = 1;
|
||
// 是否提交等待节点
|
||
var submitWaitNode = WfForm.convertFieldNameToId("sftjddjd");
|
||
// 下次超时提醒日期
|
||
var timeoutRemindDateFiled = WfForm.convertFieldNameToId("cstxrq");
|
||
// 跟踪天数 <= 1 ? 15 : 30;
|
||
var trackingDaysField = WfForm.convertFieldNameToId("gzts")
|
||
// 跟踪触发行数
|
||
var trackingLineField = WfForm.convertFieldNameToId("gzcfxs");
|
||
jQuery(document).ready(function (){
|
||
var detail2LineNum = WfForm.getDetailRowCount("detail_2");
|
||
// let firstTrack = Boolean(true);
|
||
// if (new Date(firstSaleDate) < new Date(currentDate) && dayDiff > 0) {
|
||
// firstTrack = false;
|
||
// }
|
||
// console.log('firstTrack ', firstTrack)
|
||
// 到达节点次数
|
||
var nodeNum = getNodeNum();
|
||
var trackingLine = parseInt(WfForm.getFieldValue(trackingLineField));
|
||
// 如果不是则自动添加一行明细让他自己填写
|
||
if (detail2LineNum < trackingLine && detail2LineNum < nodeNum) {
|
||
console.log('添加一行明细!');
|
||
WfForm.addDetailRow("detail_2", {});
|
||
}
|
||
if(detail2LineNum >= trackingLine){
|
||
WfForm.changeFieldValue(submitWaitNode, {value: 1});
|
||
WfForm.changeFieldValue(timeoutRemindDateFiled, {value: ''});
|
||
return;
|
||
}
|
||
initTimeoutDate();
|
||
WfForm.bindFieldChangeEvent(firstSaleDateField + "," + trackTimeField,function (){
|
||
initTimeoutDate();
|
||
});
|
||
});
|
||
|
||
function getNodeNum(){
|
||
var firstSaleDate = WfForm.getFieldValue(firstSaleDateField);
|
||
console.log('首台销售日期 ', firstSaleDate);
|
||
var currentDate = getCurrentDate();
|
||
var dayDiff = getDaysDiff(firstSaleDate, currentDate);
|
||
console.log('当前天数与首台销售日期相差天数 : ', dayDiff)
|
||
var trackingDays = WfForm.getFieldValue(trackingDaysField);
|
||
return Math.floor(dayDiff / trackingDays) + 1;
|
||
}
|
||
|
||
function initTimeoutDate(){
|
||
console.log('==== initTimeoutDate begin ====')
|
||
var firstSaleDate = WfForm.getFieldValue(firstSaleDateField);
|
||
var nodeNum = getNodeNum();
|
||
console.log('到达节点次数 ', nodeNum);
|
||
var trackingDays = WfForm.getFieldValue(trackingDaysField);
|
||
console.log('跟踪天数 ', trackingDays);
|
||
var computeTimeoutDate = addDays(firstSaleDate, nodeNum * trackingDays);
|
||
console.log('计算下次超时日期 ', computeTimeoutDate);
|
||
var trackingLine = parseInt(WfForm.getFieldValue(trackingLineField));
|
||
var detail2LineNum = WfForm.getDetailRowCount("detail_2");
|
||
setTimeout(function (){
|
||
WfForm.changeFieldValue(timeoutRemindDateFiled, {value: computeTimeoutDate});
|
||
// 判断流程提交走向
|
||
console.log('主表跟踪触发行数 : ', trackingLine)
|
||
if (nodeNum >= trackingLine) {
|
||
console.log('nodeNum >= trackingLine');
|
||
WfForm.changeFieldValue(submitWaitNode, {value: 1});
|
||
WfForm.changeFieldValue(timeoutRemindDateFiled, {value: ''});
|
||
WfForm.registerCheckEvent(WfForm.OPER_SUBMIT, function (callback) {
|
||
detail2LineNum = WfForm.getDetailRowCount("detail_2");
|
||
if (detail2LineNum < trackingLine) {
|
||
WfForm.showMessage('请填写明细表信息!');
|
||
detail2LineNum = WfForm.getDetailRowCount("detail_2");
|
||
for (var i = 0; i < trackingLine - parseInt(detail2LineNum); i++) {
|
||
WfForm.addDetailRow("detail_2", {});
|
||
}
|
||
return;
|
||
}
|
||
callback();
|
||
});
|
||
} else {
|
||
WfForm.changeFieldValue(submitWaitNode, {value: 0});
|
||
}
|
||
console.log('==== initTimeoutDate end ====')
|
||
},10);
|
||
}
|
||
|
||
function getDaysDiff(date1, date2) {
|
||
date1 = new Date(date1);
|
||
date2 = new Date(date2);
|
||
var oneDay = 24 * 60 * 60 * 1000; // 一天的毫秒数
|
||
var timeDiff = Math.abs(date1.getTime() - date2.getTime()); // 两个日期对象的毫秒数差值
|
||
// 将毫秒数差值转换为天数差值并四舍五入
|
||
return Math.round(timeDiff / oneDay);
|
||
}
|
||
|
||
function getCurrentDate() {
|
||
return parseDate(new Date());
|
||
}
|
||
|
||
function parseDate(date) {
|
||
var currentYear = date.getFullYear();
|
||
var currentMonth = date.getMonth() + 1;// getMonth()返回0~11,需要加1
|
||
if(currentMonth < 10){
|
||
currentMonth = '0' + currentMonth;
|
||
}
|
||
var currentDay = date.getDate();
|
||
return currentYear + '-' + currentMonth + '-' + currentDay;
|
||
}
|
||
|
||
function addDays(date, days) {
|
||
var newDate = new Date(date);
|
||
newDate.setDate(newDate.getDate() + days);
|
||
console.log('newDate ', newDate)
|
||
return parseDate(newDate);
|
||
}
|
||
|
||
|
||
|
||
|
||
|