|
@@ -909,6 +909,7 @@ const rationCalcBases = {
|
|
|
};
|
|
|
|
|
|
let analyzer = {
|
|
|
+ error: '',
|
|
|
standard: function(expr){
|
|
|
let str = expr;
|
|
|
str = str.replace(/\s/g, ""); // 去空格、去中文空格
|
|
@@ -952,8 +953,18 @@ let analyzer = {
|
|
|
return template.calcItems[idx];
|
|
|
},
|
|
|
isCycleCalc: function (expression, ID, template) { // 这里判断expression,是ID引用: @5+@6
|
|
|
- if (expression.includes(`@${ID}`))
|
|
|
- return true;
|
|
|
+ let atID = `@${ID}`;
|
|
|
+ // 避免部分匹配,如:@10匹配@1
|
|
|
+ let idx = expression.indexOf(atID);
|
|
|
+ if (idx >= 0){
|
|
|
+ let nextPos = idx + atID.length;
|
|
|
+ if (nextPos >= expression.length)
|
|
|
+ return true;
|
|
|
+
|
|
|
+ let char = expression.charAt(nextPos);
|
|
|
+ if (!char.isNumberStr())
|
|
|
+ return true;
|
|
|
+ };
|
|
|
|
|
|
let atIDs = analyzer.getAtIDArr(expression);
|
|
|
for (let atID of atIDs) {
|
|
@@ -970,6 +981,7 @@ let analyzer = {
|
|
|
try {
|
|
|
expr = expr.replace(/\[[\u4E00-\u9FA5]+\]/gi, '0');
|
|
|
expr = expr.replace(/@\d+/gi, '0');
|
|
|
+ expr = expr.replace(/L/gi, '0');
|
|
|
if (expr.includes('00'))
|
|
|
return false;
|
|
|
|
|
@@ -985,14 +997,16 @@ let analyzer = {
|
|
|
let expr = me.standard(dispExpr);
|
|
|
let invalidChars = /[^0-9\u4e00-\u9fa5\+\-\*\/\(\)\.\[\]FL%]/g;
|
|
|
if (invalidChars.test(expr)){
|
|
|
- hintBox.infoBox('错误提示',`表达式中含有${hintBox.font('无效字符')}!`,1);
|
|
|
+ analyzer.error = `表达式中含有${hintBox.font('无效字符')}!`;
|
|
|
+ // hintBox.infoBox('错误提示',`表达式中含有${hintBox.font('无效字符')}!`,1);
|
|
|
return false;
|
|
|
};
|
|
|
|
|
|
let i = expr.search(/\df/ig); // 4F3
|
|
|
let j = expr.search(/\d\[/ig); // 4[定额基价人工费]
|
|
|
if (i > -1 || j > -1){
|
|
|
- hintBox.infoBox('错误提示', `表达式中${hintBox.font('缺少运算符')}!`, 1);
|
|
|
+ analyzer.error = `表达式中${hintBox.font('缺少运算符')}!`;
|
|
|
+ // hintBox.infoBox('错误提示', `表达式中${hintBox.font('缺少运算符')}!`, 1);
|
|
|
return false;
|
|
|
}
|
|
|
|
|
@@ -1001,26 +1015,30 @@ let analyzer = {
|
|
|
let pattBase = new RegExp(/\[[\u4E00-\u9FA5]+\]/gi);
|
|
|
let arrBase = expr.match(pattBase);
|
|
|
if (arrCn && !arrBase){
|
|
|
- hintBox.infoBox('错误提示', `定额基数必须用中括号${hintBox.font('[]')}括起来!`, 1);
|
|
|
+ analyzer.error = `定额基数必须用中括号${hintBox.font('[]')}括起来!`;
|
|
|
+ // hintBox.infoBox('错误提示', `定额基数必须用中括号${hintBox.font('[]')}括起来!`, 1);
|
|
|
return false;
|
|
|
};
|
|
|
if (arrCn && arrBase && (arrCn.length != arrBase.length)){
|
|
|
for (let cn of arrCn){
|
|
|
let tempBase = `[${cn}]`;
|
|
|
if (!arrBase.includes(tempBase)){
|
|
|
- hintBox.infoBox('错误提示', `定额基数“${hintBox.font(cn)}”必须用中括号${hintBox.font('[]')}括起来!`, 1);
|
|
|
+ analyzer.error = `定额基数“${hintBox.font(cn)}”必须用中括号${hintBox.font('[]')}括起来!`;
|
|
|
+ // hintBox.infoBox('错误提示', `定额基数“${hintBox.font(cn)}”必须用中括号${hintBox.font('[]')}括起来!`, 1);
|
|
|
return false;
|
|
|
}
|
|
|
};
|
|
|
// 这里要加一个保险。因为上面的 for 循环在“主材费 + [主材费]” 情况下有Bug
|
|
|
- hintBox.infoBox('错误提示', `定额基数必须用中括号${hintBox.font('[]')}括起来!`, 1);
|
|
|
+ analyzer.error =`定额基数必须用中括号${hintBox.font('[]')}括起来!`;
|
|
|
+ // hintBox.infoBox('错误提示', `定额基数必须用中括号${hintBox.font('[]')}括起来!`, 1);
|
|
|
return false;
|
|
|
};
|
|
|
if (arrBase){
|
|
|
for (let base of arrBase){
|
|
|
let baseName = base.slice(1, -1);
|
|
|
if (!rationCalcBases[baseName]){
|
|
|
- hintBox.infoBox('错误提示', `定额基数${hintBox.font('[' +baseName + ']')}末定义!`, 1);
|
|
|
+ analyzer.error = `定额基数${hintBox.font('[' +baseName + ']')}末定义!`;
|
|
|
+ // hintBox.infoBox('错误提示', `定额基数${hintBox.font('[' +baseName + ']')}末定义!`, 1);
|
|
|
return false;
|
|
|
}
|
|
|
};
|
|
@@ -1031,18 +1049,21 @@ let analyzer = {
|
|
|
let num = F.slice(1);
|
|
|
if (num > template.calcItems.length){
|
|
|
let s = hintBox.font('F'+num);
|
|
|
- hintBox.infoBox('错误提示', `表达式中 “${hintBox.font(s)}” 行号引用错误!`, 1);
|
|
|
+ analyzer.error = `表达式中 “${hintBox.font(s)}” 行号引用错误!`;
|
|
|
+ // hintBox.infoBox('错误提示', `表达式中 “${hintBox.font(s)}” 行号引用错误!`, 1);
|
|
|
return false;
|
|
|
};
|
|
|
};
|
|
|
|
|
|
let expression = me.getExpression(expr, template);
|
|
|
if (me.isCycleCalc(expression, itemID, template)){
|
|
|
- hintBox.infoBox('错误提示', `表达式中有${hintBox.font('循环计算')}!`, 1);
|
|
|
+ analyzer.error = `表达式中有${hintBox.font('循环计算')}!`;
|
|
|
+ // hintBox.infoBox('错误提示', `表达式中有${hintBox.font('循环计算')}!`, 1);
|
|
|
return false;
|
|
|
};
|
|
|
if (!testValue(expression)){
|
|
|
- hintBox.infoBox('错误提示', `表达式中有${hintBox.font('语法错误')}!`, 1);
|
|
|
+ analyzer.error = `表达式中有${hintBox.font('语法错误')}!`;
|
|
|
+ // hintBox.infoBox('错误提示', `表达式中有${hintBox.font('语法错误')}!`, 1);
|
|
|
return false;
|
|
|
};
|
|
|
|
|
@@ -1146,6 +1167,17 @@ let analyzer = {
|
|
|
}
|
|
|
return false;
|
|
|
},
|
|
|
+ refreshUsedCalcItemsStatement: function(template, calcItem){
|
|
|
+ let atID = '@' + calcItem.ID;
|
|
|
+ for (var i = 0; i < template.calcItems.length; i++) {
|
|
|
+ let item = template.calcItems[i];
|
|
|
+ let atIDArr = analyzer.getAtIDArr(item.expression);
|
|
|
+ if (atIDArr.indexOf(atID) >= 0){
|
|
|
+ item.statement = analyzer.getStatement(item.expression, template);
|
|
|
+ };
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
calcItemLabourCoe: function(calcItem){
|
|
|
let lc = 0;
|
|
|
if (calcItem.labourCoeID)
|
|
@@ -1831,11 +1863,11 @@ class CalcProgram {
|
|
|
leafBills.push(leafBill);
|
|
|
};
|
|
|
|
|
|
- mergeArr(billNodes, leafBills);
|
|
|
+ billNodes.merge(leafBills);
|
|
|
|
|
|
for (let bill of billNodes){
|
|
|
let changeBills = me.calculate(bill, true, false, tender);
|
|
|
- mergeArr(allChangedNodes, changeBills);
|
|
|
+ allChangedNodes.merge(changeBills);
|
|
|
};
|
|
|
|
|
|
me.calcFormulaNodes(allChangedNodes, tender);
|
|
@@ -1877,7 +1909,7 @@ class CalcProgram {
|
|
|
};
|
|
|
|
|
|
let curChangeds = me.calculate(treeNode, true, true, tender);
|
|
|
- mergeArr(changedNodes, curChangeds);
|
|
|
+ changedNodes.merge(curChangeds);
|
|
|
me.saveNodes(changedNodes);
|
|
|
};
|
|
|
};
|