|
|
@@ -5,6 +5,8 @@ import evaluate from 'evaluator.js';
|
|
|
export interface IKeywordItem {
|
|
|
optionCode: string; // 选项号
|
|
|
coe: string; // 系数 *1.29
|
|
|
+ keyword: string;
|
|
|
+ unit: string;
|
|
|
}
|
|
|
|
|
|
export interface IInfoPriceMain {
|
|
|
@@ -29,6 +31,7 @@ export const calcMaterialExp = (infoPrice: IInfoPriceMain, keywordItems: IKeywor
|
|
|
const decimal = 2; // 小数位数
|
|
|
const groupStr = infoPrice.classCode.substr(preCodeLength);
|
|
|
let { expString } = infoPrice; // 计算式
|
|
|
+ const matchKeywords: IKeywordItem[] = [];
|
|
|
try {
|
|
|
if (groupStr.length > 0) {
|
|
|
let startIndex = 0;
|
|
|
@@ -41,6 +44,7 @@ export const calcMaterialExp = (infoPrice: IInfoPriceMain, keywordItems: IKeywor
|
|
|
let coeNumber = parseFloat(group.coe.substr(1)); // 要代入计算的系数
|
|
|
if (operator === '*') coeNumber -= 1;
|
|
|
expString = replaceAll(option.charAt(0), `${coeNumber}`, expString);
|
|
|
+ matchKeywords.push(group);
|
|
|
}
|
|
|
startIndex += 3;
|
|
|
}
|
|
|
@@ -49,11 +53,11 @@ export const calcMaterialExp = (infoPrice: IInfoPriceMain, keywordItems: IKeywor
|
|
|
|
|
|
// 没找到的按0处理
|
|
|
expString = replaceAll(/[a-zA-Z]/, '0', expString);
|
|
|
- return roundForObj(evaluate(expString), decimal);
|
|
|
+ return { price: roundForObj(evaluate(expString), decimal), matchKeywords };
|
|
|
}
|
|
|
} catch (error) {
|
|
|
throw new Error('计算失败,表达式有误');
|
|
|
}
|
|
|
|
|
|
- return roundForObj(infoPrice.basePrice, decimal);
|
|
|
+ return { price: roundForObj(infoPrice.basePrice, decimal), matchKeywords };
|
|
|
};
|