فهرست منبع

合同支付,公式转换调整

MaiXinRong 3 ماه پیش
والد
کامیت
8ba7d4f3b3
1فایلهای تغییر یافته به همراه28 افزوده شده و 14 حذف شده
  1. 28 14
      app/public/js/phase_pay_detail.js

+ 28 - 14
app/public/js/phase_pay_detail.js

@@ -157,21 +157,33 @@ $(document).ready(() => {
                 return expr;
             }
             trans2NodeExpr(expr, payTree) {
-                const orderParam = expr.match(this.orderReg);
-                if (orderParam) {
-                    for (const op of orderParam) {
-                        const order = parseInt(op.substring(1, op.length));
-                        const payNode = payTree.nodes[order - 1];
-                        expr = expr.replace(op, payNode ? `<<${payNode.uuid}>>` || '' : 0);
+                const orderParam = [...expr.matchAll(this.orderReg)];
+                if (!orderParam) return expr;
+
+                orderParam.forEach(op => {
+                    op.matchLength = op[0].length;
+                    op.matchEnd = op.index + op.matchLength;
+                });
+                const parts = [];
+                for (const [i, op] of orderParam.entries()) {
+                    if (i === 0) {
+                        if (op.index > 0) parts.push(expr.substring(0, op.index));
+                    } else {
+                        parts.push(expr.substring(orderParam[i-1].matchEnd, op.index));
+                    }
+                    const order = parseInt(op[0].substring(1, op.matchLength));
+                    const payNode = payTree.nodes[order - 1];
+                    parts.push(payNode ? `<<${payNode.uuid}>>` || '' : 0);
+                    if (i === orderParam.length - 1) {
+                        if (op.matchEnd < expr.length) parts.push(expr.substring(op.matchEnd, expr.length));
                     }
                 }
-                return expr;
+                return parts.join('');
             }
-            checkExprValid(expr, invalidParam, selfId, payTree) {
+            checkExprValid(expr, invalidParam, selfId, payTree, allowFixed = false) {
                 if (!expr) return [true, ''];
                 const param = [];
-                let num = '', base = '';
-                let fixedIdParam;
+                let num = '', base = '', fixedIdParam = undefined;
                 for (let i = 0, iLen = expr.length; i < iLen; i++) {
                     const subExpr = expr.substring(i, expr.length);
                     if (/^[\d\.%]+/.test(expr[i])) {
@@ -283,10 +295,12 @@ $(document).ready(() => {
                         if (!selfId) return [false, '输入的表达式错误:不支持行号引用'];
 
                         if ([`<<${selfId}>>`].indexOf(p.value) >= 0) return [false, '输入的表达式非法:请勿引用自己'];
-                        if (!fixedIdParam) {
-                            fixedIdParam = payTree.nodes.filter(x => { return x.is_fixed; }).map(x => { return `<<${x.uuid}>>`});
+                        if (!allowFixed) {
+                            if (fixedIdParam === undefined) {
+                                fixedIdParam = payTree.nodes.filter(x => { return x.is_fixed; }).map(x => { return `<<${x.uuid}>>`});
+                            }
+                            if (fixedIdParam.indexOf(p.value) >= 0) return [false, '输入的表达式非法:请勿引用固定项'];
                         }
-                        if (fixedIdParam.indexOf(p.value) >= 0) return [false, '输入的表达式非法:请勿引用固定项'];
                     }
                     if (p.type === 'left') {
                         iLeftCount += 1;
@@ -318,7 +332,7 @@ $(document).ready(() => {
                         data.expr = num;
                     } else {
                         const expr = this.trans2NodeExpr($.trim(text).replace('\t', '').replace('=', '').toLowerCase(), payTree);
-                        const [valid, msg] = this.checkExprValid(expr, [], payNode.uuid, payTree);
+                        const [valid, msg] = this.checkExprValid(expr, [], payNode.uuid, payTree, true);
                         if (!valid) return [valid, msg];
                         data.expr = expr;
                     }