ebu_ecology_dev1/javascript/xuanran.wang/longgong/NewProductTest.js

123 lines
4.7 KiB
JavaScript
Raw Normal View History

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