ecology_maven/html/aiyh_pcn/流程代码块/index.js

190 lines
6.2 KiB
JavaScript
Raw Normal View History

2022-01-12 11:22:31 +08:00
//<editor-fold desc="法务预算审核流程 明细表数据计算(╰_╯)#o(≧口≦)o">
//#region 法务预算审核流程 明细表数据计算
/**
* 转换字段名为字段id
* @param fieldName 字段名
* @param detail
* @returns {*} 字段id
*/
function convertField2Id(fieldName, detail = "main") {
return WfForm.convertFieldNameToId(fieldName, detail)
}
/**
* 统计第一个明细表数据
* @returns {Map} 整理后的明细数据
*/
function statisticalDetailTableData() {
let config = {
groupField: "sqrbm",
sumField: 'fyygrmb',
detailTable: 'formtable_main_173_dt1',
detailTableSimple: 'detail_1'
}
let sumMap = new Map()
let rowArr = (WfForm.getDetailAllRowIndexStr(config.detailTableSimple) ?? '').split(",");
for (let i = 0; i < rowArr.length; i++) {
let rowIndex = rowArr[i];
let groupFieldMark = convertField2Id(config.groupField, config.detailTableSimple)
let groupFieldId = groupFieldMark + "_" + rowIndex
// 获取值
let groupFieldValue = WfForm.getFieldValue(groupFieldId)
let sumFieldMark = convertField2Id(config.sumField, config.detailTableSimple)
let sumFieldId = sumFieldMark + "_" + rowIndex
// 获取值
let sumFieldValue = parseInt(WfForm.getFieldValue(sumFieldId))
if (sumMap.has(groupFieldValue)) {
let sumValue = sumMap.get(groupFieldValue) + sumFieldValue
sumMap.set(groupFieldValue, sumValue)
} else {
sumMap.set(groupFieldValue, sumFieldValue)
}
}
return sumMap
}
/**
* 第二个明细表赋值
* @param sumMap 整理后的明细数据
*/
function assignmentDetailTable2(sumMap) {
let config = {
groupField: "sqrbm",
sumField: 'fyygrmbxj',
detailTable: 'formtable_main_173_dt2',
detailTableSimple: 'detail_2'
}
// 删除所有信息
if ((WfForm.getDetailAllRowIndexStr(config.detailTableSimple) ?? "") !== "") {
return
// WfForm.delDetailRow(config.detailTableSimple, "all");
}
// 赋值
sumMap.forEach((value, key) => {
let valueObj = {
[convertField2Id(config.groupField, config.detailTableSimple)]: {
value: key
},
[convertField2Id(config.sumField, config.detailTableSimple)]: {
value: value
},
}
WfForm.addDetailRow(config.detailTableSimple, valueObj);
})
}
/**
* 注册监听提交和保存事件
*/
WfForm.registerCheckEvent(WfForm.OPER_SAVE + "," + WfForm.OPER_SUBMIT, function (callback) {
let sumMap = statisticalDetailTableData()
assignmentDetailTable2(sumMap)
callback();
});
//#endregion
// </editor-fold>(╰_╯)#(╰_╯)#
// ================================================================================
//<editor-fold desc="法务预算审核流程 明细表数据计算, <( ̄ ﹌  ̄)@m 折算">
//
/**
* 转换字段名为字段id
* @param fieldName 字段名
* @param detail
* @returns {*} 字段id
*/
function convertField2Id(fieldName, detail = "main") {
return WfForm.convertFieldNameToId(fieldName, detail)
}
/**
* 根据明细2中的折扣还是啥不清楚计算明细1中的实际钱
* @param discountMap
*/
function calculateDiscountDetail1(discountMap) {
let config = {
groupField: "sqrbm",
discountField: 'spys',
costCountField: 'fyygrmb',
detailTable: 'formtable_main_173_dt1',
detailTableSimple: 'detail_1'
}
let rowArr = (WfForm.getDetailAllRowIndexStr(config.detailTableSimple) ?? '').split(",");
let groupFieldMark = convertField2Id(config.groupField, config.detailTableSimple)
let discountFieldMark = convertField2Id(config.discountField, config.detailTableSimple)
let costCountFieldMark = convertField2Id(config.costCountField, config.detailTableSimple)
for (let i = 0; i < rowArr.length; i++) {
let groupFieldId = groupFieldMark + "_" + rowArr[i]
let discountFieldId = discountFieldMark + "_" + rowArr[i]
let costCountFieldId = costCountFieldMark + "_" + rowArr[i]
let groupFieldValue = WfForm.getFieldValue(groupFieldId)
let costCountFieldValue = parseInt(WfForm.getFieldValue(costCountFieldId))
// console.log(discountMap.get(groupFieldValue) * costCountFieldValue)
//修改值
WfForm.changeFieldValue(discountFieldId, {
value: discountMap[groupFieldValue] * costCountFieldValue
});
}
}
/**
* 获取明细表2的折扣啥的不知道反正就是这几个字段
* @returns {{}}
*/
function getDiscountByDetail2() {
let config = {
groupField: "sqrbm",
discountField: 'spys',
detailTable: 'formtable_main_173_dt2',
detailTableSimple: 'detail_2'
}
let discountMap = {}
let rowArr = (WfForm.getDetailAllRowIndexStr(config.detailTableSimple) ?? '').split(",");
let groupFieldMark = convertField2Id(config.groupField, config.detailTableSimple)
let discountFieldMark = convertField2Id(config.discountField, config.detailTableSimple)
for (let i = 0; i < rowArr.length; i++) {
let groupFieldId = groupFieldMark + "_" + rowArr[i]
let discountFieldId = discountFieldMark + "_" + rowArr[i]
let groupFieldValue = WfForm.getFieldValue(groupFieldId)
discountMap[groupFieldValue] = parseFloat(WfForm.getFieldValue(discountFieldId)) / 100
}
return discountMap
}
/**
* 绑定明细表事件监听字段改变时触发计算
*/
function bindEvent() {
let config = {
changeField: 'spys',
detailTable: 'formtable_main_173_dt2',
detailTableSimple: 'detail_2'
}
WfForm.bindDetailFieldChangeEvent(convertField2Id(config.changeField, config.detailTableSimple), () => {
let discountMap = getDiscountByDetail2();
calculateDiscountDetail1(discountMap)
})
}
$(()=>{
//页面加载时执行一次
let discountMap = getDiscountByDetail2();
calculateDiscountDetail1(discountMap)
bindEvent()
})
// </editor-fold>