瀏覽代碼

设计量公式

MaiXinRong 1 年之前
父節點
當前提交
cc1a684423
共有 2 個文件被更改,包括 45 次插入9 次删除
  1. 7 4
      app/const/spread.js
  2. 38 5
      app/public/js/ledger.js

+ 7 - 4
app/const/spread.js

@@ -537,7 +537,8 @@ const BaseSpreadColSetting = {
             name: [{title: '计量单元', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 230, formatter: '@'}],
             position: [{title: '位置', colSpan: '1', rowSpan: '2', field: 'position', hAlign: 0, width: 60, formatter: '@'}],
             tz_calc: [
-                {title: '台账数量|设计量', colSpan: '4|1', rowSpan: '1|1', field: 'sgfh_qty', hAlign: 2, width: 100, type: 'Number'},
+                {title: '台账数量|设计量', colSpan: '5|1', rowSpan: '1|1', field: 'sgfh_qty', hAlign: 2, width: 100, type: 'Number'},
+                {title: '|设计量公式', colSpan: '|1', rowSpan: '|1', field: 'sgfh_expr', hAlign: 2, width: 100},
                 {title: '|设计错漏增减', colSpan: '|1', rowSpan: '|1', field: 'sjcl_qty', hAlign: 2, width: 100, type: 'Number'},
                 {title: '|其他错漏增减', colSpan: '|1', rowSpan: '|1', field: 'qtcl_qty', hAlign: 2, width: 100, type: 'Number'},
                 {title: '|小计', colSpan: '|1', rowSpan: '|1', field: 'quantity', hAlign: 2, width: 60, type: 'Number', readOnly: true},
@@ -668,7 +669,8 @@ const BaseSpreadColSetting = {
             name: [{title: '计量单元', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 230, formatter: '@'}],
             position: [{title: '位置', colSpan: '1', rowSpan: '2', field: 'position', hAlign: 0, width: 60, formatter: '@'}],
             tz_calc: [
-                {title: '台账数量|设计量', colSpan: '4|1', rowSpan: '1|1', field: 'sgfh_qty', hAlign: 2, width: 100, type: 'Number'},
+                {title: '台账数量|设计量', colSpan: '5|1', rowSpan: '1|1', field: 'sgfh_qty', hAlign: 2, width: 100, type: 'Number'},
+                {title: '|设计量公式', colSpan: '|1', rowSpan: '|1', field: 'sgfh_expr', hAlign: 2, width: 100},
                 {title: '|设计错漏增减', colSpan: '|1', rowSpan: '|1', field: 'sjcl_qty', hAlign: 2, width: 100, type: 'Number'},
                 {title: '|其他错漏增减', colSpan: '|1', rowSpan: '|1', field: 'qtcl_qty', hAlign: 2, width: 100, type: 'Number'},
                 {title: '|小计', colSpan: '|1', rowSpan: '|1', field: 'quantity', hAlign: 2, width: 60, type: 'Number', readOnly: true},
@@ -765,13 +767,14 @@ const BaseSpreadColSetting = {
 };
 const withoutClReplace = {
     indexField: 'sgfh_qty',
-    remove: ['sgfh_qty', 'sgfh_tp', 'sjcl_qty', 'sjcl_tp', 'qtcl_qty', 'qtcl_tp', 'quantity', 'total_price'],
+    remove: ['sgfh_qty', 'sgfh_expr', 'sgfh_tp', 'sjcl_qty', 'sjcl_tp', 'qtcl_qty', 'qtcl_tp', 'quantity', 'total_price'],
     billsCols: [
         {title: '设计量|数量', colSpan: '2|1', rowSpan: '1|1', field: 'sgfh_qty', hAlign: 2, width: 60, type: 'Number'},
         {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'sgfh_tp', hAlign: 2, width: 60, type: 'Number', readOnly: true},
     ],
     posCols: [
-        {title: '设计量', colSpan: '1', rowSpan: '2', field: 'sgfh_qty', hAlign: 2, width: 120, type: 'Number'},
+        {title: '台账数量|设计量', colSpan: '2|1', rowSpan: '1|1', field: 'sgfh_qty', hAlign: 2, width: 100, type: 'Number'},
+        {title: '|设计量公式', colSpan: '|1', rowSpan: '|1', field: 'sgfh_expr', hAlign: 2, width: 100},
     ],
 };
 const SpreadSpec = {

+ 38 - 5
app/public/js/ledger.js

@@ -23,12 +23,13 @@ const invalidFields = {
     posCalc: ['sgfh_qty', 'sgfh_tp', 'sjcl_qty', 'sjcl_tp', 'qtcl_qty', 'qtcl_tp'],
     posXmj: ['code'],
 };
-function getExprInfo (field) {
+function getExprInfo (field, converse = false) {
     const exprField = [
         {qty: 'sgfh_qty', expr: 'sgfh_expr'},
         {qty: 'sjcl_qty', expr: 'sjcl_expr'},
         {qty: 'qtcl_qty', expr: 'qtcl_expr'},
     ];
+    if (converse) return _.find(exprField, { expr: field });
     return _.find(exprField, {qty: field});
 }
 function transExpr(expr) {
@@ -1952,6 +1953,23 @@ $(document).ready(function() {
                             return;
                         }
                     }
+                } else if (col.field.indexOf('_expr') > 0) {
+                    const exprInfo = getExprInfo(col.field, true);
+                    if (!exprInfo) return;
+
+                    if (newText) {
+                        try {
+                            data.updateData[exprInfo.qty] = math.evaluate(transExpr(newText));
+                            data.updateData[exprInfo.expr] = newText;
+                        } catch(err) {
+                            toastr.error('输入的表达式非法');
+                            SpreadJsObj.reLoadRowData(info.sheet, info.row);
+                            return;
+                        }
+                    } else {
+                        data.updateData[exprInfo.qty] = 0;
+                        data.updateData[exprInfo.expr] = '';
+                    }
                 } else {
                     data.updateData[col.field] = newText;
                 }
@@ -1997,9 +2015,16 @@ $(document).ready(function() {
                             const style = sheet.getStyle(iRow, iCol);
                             if (!style.locked) {
                                 const colSetting = sheet.zh_setting.cols[iCol];
-                                data[colSetting.field] = null;
-                                const exprInfo = getExprInfo(colSetting.field);
-                                if (exprInfo) data[exprInfo.expr] = '';
+                                if (colSetting.field.indexOf('_expr') > 0) {
+                                    const exprInfo = getExprInfo(colSetting.field, true);
+                                    if (!exprInfo) continue;
+                                    data[exprInfo.expr] = '';
+                                    data[exprInfo.qty] = 0;
+                                } else {
+                                    data[colSetting.field] = null;
+                                    const exprInfo = getExprInfo(colSetting.field);
+                                    if (exprInfo) data[exprInfo.expr] = '';
+                                }
                                 bDel = true;
                             }
                         }
@@ -2112,7 +2137,6 @@ $(document).ready(function() {
                         if (!colSetting) continue;
 
                         posData[colSetting.field] = trimInvalidChar(info.sheet.getText(curRow, curCol));
-
                         if (colSetting.type === 'Number') {
                             const num = _.toNumber(posData[colSetting.field]);
                             if (num) {
@@ -2132,6 +2156,15 @@ $(document).ready(function() {
                                     toastMessageUniq(hint.expr);
                                 }
                             }
+                        } else if (colSetting.field.indexOf('_expr') > 0) {
+                            try {
+                                const exprInfo = getExprInfo(colSetting.field, true);
+                                posData[exprInfo.expr] = trimInvalidChar(info.sheet.getText(curRow, curCol));
+                                posData[exprInfo.qty] = math.evaluate(transExpr(posData[exprInfo.expr]));
+                                bPaste = true;
+                            } catch (err) {
+                                toastMessageUniq(hint.expr);
+                            }
                         } else {
                             bPaste = true;
                         }