Browse Source

fix: [模板管理] 计算成绩

lkf
memorylkf 2 months ago
parent
commit
6fbac01dc5
1 changed files with 55 additions and 17 deletions
  1. +55
    -17
      src/utils/calUnitTools.js

+ 55
- 17
src/utils/calUnitTools.js View File

@ -28,8 +28,11 @@ export function addTj(valueArr, unitArr) {
} }
export function addDecimals(a, b) { export function addDecimals(a, b) {
if (Number.isNaN(a) || Number.isNaN(b)) {
return 0
if (Number.isNaN(a)) {
a = 0
}
if (Number.isNaN(b)) {
b = 0
} }
const strA = a.toString() const strA = a.toString()
const strB = b.toString() const strB = b.toString()
@ -77,23 +80,58 @@ export function multiplyDecimals(a, b) {
absStr.substring(absStr.length - totalDecimals) absStr.substring(absStr.length - totalDecimals)
} }
result = result.replace(/\.?0+$/, '') || '0'
result = result.replace(/(\.\d*?)0+$/, '$1').replace(/\.$/, '')
return (isNegative ? '-' : '') + result return (isNegative ? '-' : '') + result
} }
//模板物资去重 //模板物资去重
export function uniqeResource(oldList,newList) {
for(var i=0;i<newList.length;i++){
let _index= _.findIndex(oldList,function(item){
return item.bh==newList[i].bh&&(item.type==newList[i].type||item.elnType==newList[i].type)
})
if(_index>-1){
const { total, unit }=addTj([oldList[_index].syl,newList[i].syl],[oldList[_index].syldw,newList[i].syldw])
oldList[_index].syl=total
oldList[_index].syldw=unit
}else{
oldList.push(newList[i])
}
}
return oldList;
export function uniqeResource(oldList, newList) {
for (var i = 0; i < newList.length; i++) {
let _index = _.findIndex(oldList, function (item) {
return (
item.bh == newList[i].bh &&
(item.type == newList[i].type ||
item.elnType == newList[i].type ||
item.elnType == newList[i].elnType ||
item.type == newList[i].elnType)
)
})
if (_index > -1) {
const { total, unit } = addTj(
[oldList[_index].syl, newList[i].syl],
[oldList[_index].syldw, newList[i].syldw]
)
oldList[_index].syl = total
oldList[_index].syldw = unit
} else {
oldList.push(newList[i])
}
}
return oldList
}
//模板物资去重
export function uniqeResourceOne(newList) {
let resultList = []
for (var i = 0; i < newList.length; i++) {
let _index = _.findIndex(resultList, function (item) {
return (
item.bh == newList[i].bh &&
(item.type == newList[i].type ||
item.elnType == newList[i].type ||
item.elnType == newList[i].elnType ||
item.type == newList[i].elnType)
)
})
if (_index > -1) {
const { total, unit } = addTj(
[resultList[_index].syl, newList[i].syl],
[resultList[_index].syldw, newList[i].syldw]
)
resultList[_index].syl = total
resultList[_index].syldw = unit
} else {
resultList.push(newList[i])
}
}
return resultList
} }

Loading…
Cancel
Save