ebu_ecology_dev1/javascript/xuanran.wang/bme/js/Common.js

203 lines
6.3 KiB
JavaScript
Raw Permalink Normal View History

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);
}
2023-03-15 13:50:48 +08:00
/**
* 校验比例是否等于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}`;
2023-06-15 14:05:53 +08:00
sum = addFloat(sum, parseFloat(WfForm.getFieldValue(field)));//遍历明细行字段
}
}
console.log('sum => ', sum)
sum === 100.00 ? callback() : WfForm.showMessage("明细付款比例总和不等于100,请修改后提交!");
});
}
2023-06-15 14:05:53 +08:00
function addFloat(a, b) {
let precision = Math.pow(10, 10); // 设置精度,根据需要调整
return (Math.round(a * precision) + Math.round(b * precision)) / precision;
}
/**
* 明细表字段发生变化进行日期计算
* @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 readOnlyArr = obj['readOnlyArr'];
// 款项类型
let paymentType = WfForm.getFieldValue(`${detailPaymentTypeId}_${index}`);
if(readOnlyArr.includes(paymentType)){
WfForm.changeFieldAttr(`${detailComPayDateId}_${index}`, READ_ONLY);
}else{
// 如果款项类型不需要计算就把预计付款日期属性改成可编辑
WfForm.changeFieldAttr(`${detailComPayDateId}_${index}`, EDIT);
}
// 先进行赋值
if(computeDatePayType.includes(paymentType)){
// 存在字段联动延时处理
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);
}
}
2023-01-03 09:40:04 +08:00
2023-03-15 13:50:48 +08:00
/**
* 字段联动后添加明细行后执行的逻辑
* @param detail
* @param configObj
*/
function addRowBack(detail, configObj){
WfForm.registerAction(WfForm.ACTION_ADDROW + detail, function(index){
configObj.index = index;
changeDetailPayDate(configObj);
});
}
2023-01-03 09:40:04 +08:00
/**
* 改变明细表字段只读
* @param detailTable
* @param detailComDateField
* @param detailPaymentTypeId
* @param readOnlyArr
*/
function changeDetailFieldReadOnly(detailTable, detailComDateField, detailPaymentTypeId, readOnlyArr){
let rowArr = WfForm.getDetailAllRowIndexStr(detailTable).split(",");
for(let i=0; i < rowArr.length; i++){
let index = rowArr[i];
if(index !== ""){
let paymentType = WfForm.getFieldValue(`${detailPaymentTypeId}_${index}`);
// 先进行赋值
if(readOnlyArr.includes(paymentType)){
WfForm.changeFieldAttr(`${detailComDateField}_${index}`, READ_ONLY);
}
}
}
}
2023-03-15 13:50:48 +08:00