155 lines
4.9 KiB
JavaScript
155 lines
4.9 KiB
JavaScript
|
const ADD = '1';
|
||
|
const DEL = '0';
|
||
|
const READ_ONLY = '1';
|
||
|
const EDIT = '2';
|
||
|
/**
|
||
|
* 计算日期
|
||
|
* @param date 计算日期
|
||
|
* @param around 前/后 前是0 后是1
|
||
|
* @param day
|
||
|
*/
|
||
|
function computeDate(date, around, day){
|
||
|
let dateTime = new Date(date).getTime();
|
||
|
let mill = 0;
|
||
|
switch (around){
|
||
|
case ADD:{
|
||
|
mill = day * 1;
|
||
|
console.log('add :', mill);
|
||
|
break;
|
||
|
}
|
||
|
case DEL:{
|
||
|
mill = day * -1;
|
||
|
console.log('del :', mill);
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
// 转成毫秒数
|
||
|
mill *= (24 * 60 * 60 * 1000);
|
||
|
dateTime += mill;
|
||
|
return getDate(dateTime);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 时间戳转 yyyy-MM-dd
|
||
|
* @param time
|
||
|
* @returns {string}
|
||
|
*/
|
||
|
function getDate(time) {
|
||
|
let date = new Date(time);
|
||
|
y = date.getFullYear();
|
||
|
m = date.getMonth() + 1;
|
||
|
d = date.getDate();
|
||
|
return y + "-" + (m < 10 ? "0" + m : m) + "-" + (d < 10 ? "0" + d : d);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 校验比例是否等于100
|
||
|
* @param detailTable 明细表
|
||
|
* @param detail2PayProportionId 比例字段
|
||
|
*/
|
||
|
function submitCallback(detailTable, detail2PayProportionId){
|
||
|
WfForm.registerCheckEvent(WfForm.OPER_SUBMIT,function(callback){
|
||
|
let rowArr = WfForm.getDetailAllRowIndexStr(detailTable).split(",");
|
||
|
let sum = 0;
|
||
|
for(let i=0; i < rowArr.length; i++){
|
||
|
let rowIndex = rowArr[i];
|
||
|
if(rowIndex !== ""){
|
||
|
let field = `${detail2PayProportionId}_${rowIndex}`;
|
||
|
sum += parseFloat(WfForm.getFieldValue(field));//遍历明细行字段
|
||
|
}
|
||
|
}
|
||
|
sum === 100.00 ? callback() : WfForm.showMessage("明细付款比例总和不等于100,请修改后提交!");
|
||
|
});
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 明细表字段发生变化进行日期计算
|
||
|
* @param bindField
|
||
|
* @param configObj
|
||
|
*/
|
||
|
function detailFieldChangeDetailCom(bindField, configObj){
|
||
|
WfForm.bindDetailFieldChangeEvent(bindField,function(id,index,value){
|
||
|
configObj.index = index;
|
||
|
changeDetailPayDate(configObj);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 主表字段发生变化进行日期计算
|
||
|
* @param mainField
|
||
|
* @param detailTable
|
||
|
* @param configObj
|
||
|
*/
|
||
|
function mainFieldChangeDetailCom(mainField, detailTable, configObj){
|
||
|
// 主表项目字段变化绑定
|
||
|
WfForm.bindFieldChangeEvent(mainField, function(obj,id,value){
|
||
|
let rowArr = WfForm.getDetailAllRowIndexStr(detailTable).split(",");
|
||
|
for(let i=0; i < rowArr.length; i++){
|
||
|
let index = rowArr[i];
|
||
|
if(index !== ""){
|
||
|
configObj.index = index;
|
||
|
changeDetailPayDate(configObj);
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 先进行主表的dml查询日期字段赋值到明细 然后在计算日期
|
||
|
* @param obj 配置对象
|
||
|
*/
|
||
|
function changeDetailPayDate(obj){
|
||
|
console.log('---- changeDetailPayDate obj ----', obj);
|
||
|
// 明细表的款项类型
|
||
|
let detailPaymentTypeId = obj['detailPaymentTypeId'];
|
||
|
// 明细下标
|
||
|
let index = obj['index'];
|
||
|
// 明细表的对应日期
|
||
|
let detailTempDateId = obj['detailTempDateId'];
|
||
|
// 明细表的前/后
|
||
|
let aroundId = obj['around'];
|
||
|
// 明细表的预计付款日期
|
||
|
let detailComPayDateId = obj['detailComPayDateId'];
|
||
|
// 明细表的天数
|
||
|
let dayId = obj['dayId'];
|
||
|
// 需要计算的款项数组
|
||
|
let computeDatePayType = obj['computeDatePayType'];
|
||
|
// 获取主表的字符值转换函数
|
||
|
let paymentTypeGetValue = obj['paymentTypeGetValue'];
|
||
|
// 款项类型
|
||
|
let paymentType = WfForm.getFieldValue(`${detailPaymentTypeId}_${index}`);
|
||
|
// 先进行赋值
|
||
|
if(computeDatePayType.includes(paymentType)){
|
||
|
WfForm.changeFieldAttr(`${detailComPayDateId}_${index}`, READ_ONLY);
|
||
|
// 存在字段联动延时处理
|
||
|
setTimeout(()=>{
|
||
|
if(paymentTypeGetValue){
|
||
|
paymentTypeGetValue[paymentType](index);
|
||
|
}
|
||
|
// 获取对应日期
|
||
|
let tempDate = WfForm.getFieldValue(`${detailTempDateId}_${index}`);
|
||
|
if(tempDate){
|
||
|
// 前/后
|
||
|
let around = WfForm.getFieldValue(`${aroundId}_${index}`);
|
||
|
// 天数
|
||
|
let day = WfForm.getFieldValue(`${dayId}_${index}`);
|
||
|
// 如果明细表三个字段的值都不为空 那么就去计算日期
|
||
|
if(tempDate && around && day){
|
||
|
let comDate = computeDate(tempDate, around, day);
|
||
|
WfForm.changeFieldValue(`${detailComPayDateId}_${index}`,{
|
||
|
value: comDate
|
||
|
});
|
||
|
}
|
||
|
}else {
|
||
|
// 如果对应日期为空就给预计付款赋空值
|
||
|
WfForm.changeFieldValue(`${detailComPayDateId}_${index}`,{
|
||
|
value: ''
|
||
|
});
|
||
|
}
|
||
|
},100);
|
||
|
}else{
|
||
|
// 如果款项类型不需要计算就把预计付款日期属性改成可编辑
|
||
|
WfForm.changeFieldAttr(`${detailComPayDateId}_${index}`, EDIT);
|
||
|
}
|
||
|
}
|