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

118 lines
4.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

// 首台销售日期
const firstSaleDateField = WfForm.convertFieldNameToId("stxsrq");
// 跟踪时间
const trackTimeField = WfForm.convertFieldNameToId("gzsj");
// 跟踪时间为三个月以内
const threeMonthIndex = 1;
// 是否提交等待节点
const submitWaitNode = WfForm.convertFieldNameToId("sftjddjd");
// 下次超时提醒日期
const timeoutRemindDateFiled = WfForm.convertFieldNameToId("cstxrq");
// 跟踪天数
const trackingDays = WfForm.getFieldValue(trackTimeField) <= 1 ? 15 : 30;
// 跟踪触发行数
const trackingLineField = WfForm.convertFieldNameToId("gzcfxs");
$(() => {
let detail2LineNum = WfForm.getDetailRowCount("detail_2");
// let firstTrack = Boolean(true);
// if (new Date(firstSaleDate) < new Date(currentDate) && dayDiff > 0) {
// firstTrack = false;
// }
// console.log('firstTrack ', firstTrack)
// 到达节点次数
const nodeNum = getNodeNum();
let 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}`,()=>{
initTimeoutDate();
});
});
function getNodeNum(){
let firstSaleDate = WfForm.getFieldValue(firstSaleDateField);
console.log('首台销售日期 ', firstSaleDate);
let currentDate = getCurrentDate();
let dayDiff = getDaysDiff(firstSaleDate, currentDate);
console.log('当前天数与首台销售日期相差天数 : ', dayDiff)
return Math.floor(dayDiff / trackingDays) + 1;
}
function initTimeoutDate(){
console.log('==== initTimeoutDate begin ====')
let firstSaleDate = WfForm.getFieldValue(firstSaleDateField);
const nodeNum = getNodeNum();
console.log('到达节点次数 ', nodeNum);
console.log('跟踪天数 ', trackingDays);
let computeTimeoutDate = addDays(firstSaleDate, nodeNum * trackingDays);
console.log('计算下次超时日期 ', computeTimeoutDate);
let trackingLine = parseInt(WfForm.getFieldValue(trackingLineField));
let detail2LineNum = WfForm.getDetailRowCount("detail_2");
setTimeout(()=>{
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 (let 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);
const oneDay = 24 * 60 * 60 * 1000; // 一天的毫秒数
const timeDiff = Math.abs(date1.getTime() - date2.getTime()); // 两个日期对象的毫秒数差值
// 将毫秒数差值转换为天数差值并四舍五入
return Math.round(timeDiff / oneDay);
}
function getCurrentDate() {
return parseDate(new Date());
}
function parseDate(date) {
const currentYear = date.getFullYear();
const currentMonth = date.getMonth() + 1; // getMonth()返回0~11需要加1
const currentDay = date.getDate();
return currentYear + '-' + currentMonth + '-' + currentDay;
}
function addDays(date, days) {
const newDate = new Date(date);
newDate.setDate(newDate.getDate() + days);
console.log('newDate ', newDate)
return parseDate(newDate);
}