From 6fbac01dc5f4359d961653119d314b7e801d611c Mon Sep 17 00:00:00 2001 From: memorylkf <312904636@qq.com> Date: Mon, 2 Feb 2026 21:09:27 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20[=E6=A8=A1=E6=9D=BF=E7=AE=A1=E7=90=86]?= =?UTF-8?q?=20=E8=AE=A1=E7=AE=97=E6=88=90=E7=BB=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/calUnitTools.js | 72 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 55 insertions(+), 17 deletions(-) diff --git a/src/utils/calUnitTools.js b/src/utils/calUnitTools.js index 1f0aa08..6de2ec5 100644 --- a/src/utils/calUnitTools.js +++ b/src/utils/calUnitTools.js @@ -28,8 +28,11 @@ export function addTj(valueArr, unitArr) { } 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 strB = b.toString() @@ -77,23 +80,58 @@ export function multiplyDecimals(a, b) { absStr.substring(absStr.length - totalDecimals) } - result = result.replace(/\.?0+$/, '') || '0' + result = result.replace(/(\.\d*?)0+$/, '$1').replace(/\.$/, '') return (isNegative ? '-' : '') + result } //模板物资去重 -export function uniqeResource(oldList,newList) { - for(var i=0;i-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 }