Commit 2e8bda49 authored by tyn's avatar tyn

成本汇总 工料汇总 差异化计算方式 优化

parent 4d479524
......@@ -465,6 +465,21 @@ export default {
console.log(error);
}
},
// 将需要编辑的值 设置为默认值 0
setEditPropDefaultValue(list = [], editPropsArray = []) {
const result = list.map(item => {
editPropsArray.forEach(prop => {
if (!item[prop]) {
item[prop] = 0;
}
});
if (item?.children?.length) {
this.setEditPropDefaultValue(item?.children, editPropsArray);
}
return item;
});
return result;
},
// 模拟 resolve 懒加载
customResolve(id, child, tableIns) {
let children = child;
......@@ -684,7 +699,58 @@ export default {
},
//保存成本
saveCostModify() {
this.$refs["costSummaryForm"].validate(async flag => {
if (flag) {
// 进行差异化对比
let resultData = this.differentCompare();
console.log(resultData);
// 没有差异
if (!resultData.length) {
}
}
});
},
// 差异化比对
differentCompare() {
const originData = this.originTableDataList;
/**
* @type {Array<object>}
*/
let data = cloneDeep(this.dataForm.tableDataList);
// 差异数据
const different = this.getDeepDifferentData(data, originData);
return cloneDeep(different);
},
// 深度差异化对比
getDeepDifferentData(data = [], originData = [], tempArray = []) {
const len = data.length;
for (let index = 0; index < len; index++) {
const item = data[index];
// 源数据
const originItem = originData[index];
// 查看可编辑字段是否存在任意一处 数据不同
const hasDifferent = editPropNames.some(prop => {
// 两个皆为无效值 返回false
if (!parseFloat(item[prop]) && !parseFloat(originItem[prop])) return false;
return item[prop] != originItem[prop];
});
// 浅层级
if (hasDifferent) {
tempArray.push({
id: item.id,
cbSummaryId: this.currentNodeValue,
taxInclusiveExpense: item.taxInclusiveExpense ? item.taxInclusiveExpense : 0,
taxExclusiveExpense: item.taxExclusiveExpense ? item.taxExclusiveExpense : 0,
expenseDate: this.expenseDate
});
}
// 递归深层级
if (item?.children?.length) {
this.getDeepDifferentData(item.children, originItem.children, tempArray);
}
}
return tempArray;
},
// 获取当前树形结构下 输入框prop的完整路径
getTableTreeProp(dataList = [], rowId, pathArray = []) {
......@@ -693,11 +759,9 @@ export default {
const item = dataList[index];
// 返回所在下标index
if (item.id === rowId) {
// return `${pathStr}${index}`;
return [...pathArray, index].join("");
}
if (item?.children?.length) {
// const childPath = `${pathStr}${index}.children.`;
const childPath = [...pathArray, index, '.children.'];
const result = this.getTableTreeProp(item.children, rowId, childPath);
if (result) {
......
......@@ -691,8 +691,10 @@ export default {
*/
let data = cloneDeep(this.dataForm.tableDataList);
const different = data.filter((item, index) => {
if (index == 0) return false;
if (index == 0 && this.hasTarget) return false;
const flag = editPropNames.some(prop => {
// 两个皆为无效值 返回false
if (!parseFloat(item[prop]) && !parseFloat(originData[index][prop])) return false;
return item[prop] != originData[index][prop];
});
return flag;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment