瀏覽代碼

1. 计量台账,复制粘贴调整
2. 计量台账,中间计量生成调整

MaiXinRong 4 年之前
父節點
當前提交
67b04b6b7a
共有 3 個文件被更改,包括 88 次插入87 次删除
  1. 54 47
      app/public/js/stage.js
  2. 34 39
      app/public/js/stage_im.js
  3. 0 1
      app/service/stage_bills.js

+ 54 - 47
app/public/js/stage.js

@@ -172,6 +172,13 @@ function getDaglText(data) {
     return def ? def.name : '';
 }
 
+function getHintMsg () {
+    return {
+        invalidExpr: {type: 'warning', msg: '粘贴了非法表达式,已过滤'},
+        disableChange: {type: 'error', msg: '不可修改此数据'},
+    }
+}
+
 
 $(document).ready(() => {
     const exportExcelSetting = {
@@ -1038,10 +1045,10 @@ $(document).ready(() => {
             }
         },
         clipboardPasted(e, info) {
+            const pasteHint = getHintMsg();
             if (info.sheet.zh_setting && info.sheet.zh_tree) {
                 const sheet = info.sheet, setting = info.sheet.zh_setting;
                 const filterNodes = [], datas = [], dgnDatas = [], mainDatas = [];
-                let bHint = false;
 
                 for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
                     const curRow = iRow + info.cellRange.row;
@@ -1077,10 +1084,7 @@ $(document).ready(() => {
                                     dgnData[col.field] = math.evaluate(transExpr(text));
                                     filterDgn = false;
                                 } catch(err) {
-                                    if (!bHint) {
-                                        toastr.warning('粘贴了非法表达式,已过滤');
-                                        bHint = true;
-                                    }
+                                    toastMessageUniq(pasteHint.invalidExpr);
                                 }
                             }
                         } else if (col.field === 'memo') {
@@ -1088,28 +1092,26 @@ $(document).ready(() => {
                             filterMain = false;
                         } else {
                             if (col.type === 'Number') {
-                                const num = _.toNumber(text);
-                                data[col.field] = num;
                                 const exprInfo = getExprInfo(col.field);
-                                if (exprInfo) {
-                                    data[exprInfo.expr] = '';
-                                }
-                                if (_.isFinite(num)) {
-                                    filter = false;
-                                } else {
-                                    try {
-                                        data[col.field] = math.evaluate(transExpr(text));
-                                        const exprInfo = getExprInfo(col.field);
-                                        if (exprInfo) {
-                                            data[exprInfo.expr] = text;
-                                        }
+                                if (text) {
+                                    const num = _.toNumber(text);
+                                    data[col.field] = num;
+                                    if (exprInfo) data[exprInfo.expr] = '';
+                                    if (_.isFinite(num)) {
                                         filter = false;
-                                    } catch(err) {
-                                        if (!bHint) {
-                                            toastr.warning('粘贴了非法表达式,已过滤');
-                                            bHint = true;
+                                    } else {
+                                        try {
+                                            data[col.field] = math.evaluate(transExpr(text));
+                                            if (exprInfo) data[exprInfo.expr] = text;
+                                            filter = false;
+                                        } catch(err) {
+                                            toastMessageUniq(pasteHint.invalidExpr);
                                         }
                                     }
+                                } else {
+                                    data[col.field] = null;
+                                    if (exprInfo) data[exprInfo.expr] = '';
+                                    filter = false;
                                 }
                             } else {
                                 data[col.field] = text;
@@ -1724,26 +1726,29 @@ $(document).ready(() => {
 
                             const newValue = trimInvalidChar(info.sheet.getText(curRow, curCol));
                             if (colSetting.type === 'Number') {
-                                const num = _.toNumber(newValue);
-                                if (num) {
-                                    newData[colSetting.field] = num;
-                                    const exprInfo = getExprInfo(colSetting.field);
-                                    if (exprInfo) {
-                                        newData[exprInfo.expr] = '';
-                                    }
-                                } else {
-                                    try {
-                                        newData[colSetting.field] = math.evaluate(transExpr(newValue));
-                                        const exprInfo = getExprInfo(colSetting.field);
+                                const exprInfo = getExprInfo(colSetting.field);
+                                if (newValue) {
+                                    const num = _.toNumber(newValue);
+                                    if (num) {
+                                        newData[colSetting.field] = num;
                                         if (exprInfo) {
-                                            newData[exprInfo.expr] = newValue;
+                                            newData[exprInfo.expr] = '';
+                                        }
+                                    } else {
+                                        try {
+                                            newData[colSetting.field] = math.evaluate(transExpr(newValue));
+                                            if (exprInfo) {
+                                                newData[exprInfo.expr] = newValue;
+                                            }
+                                        } catch(err) {
+                                            toastr.error('输入的表达式非法');
+                                            stagePosSpreadObj.loadCurPosData();
+                                            return;
                                         }
-                                    } catch(err) {
-                                        toastr.error('输入的表达式非法');
-                                        stagePosSpreadObj.loadCurPosData();
-                                        return;
-
                                     }
+                                } else {
+                                    newData[colSetting.field] = null;
+                                    if (exprInfo) newData[exprInfo.expr] = '';
                                 }
                             } else {
                                 newData[colSetting.field] = newValue;
@@ -1763,20 +1768,22 @@ $(document).ready(() => {
                                 const colSetting = info.sheet.zh_setting.cols[curCol];
                                 const newValue = trimInvalidChar(info.sheet.getText(curRow, curCol));
                                 if (colSetting.type === 'Number') {
+                                    const exprInfo = getExprInfo(colSetting.field);
+                                    if (!newValue) {
+                                        newData[colSetting.field] = newValue;
+                                        if (exprInfo) newData[exprInfo.expr] = '';
+                                        continue;
+                                    }
+
                                     const num = _.toNumber(newValue);
                                     if (num) {
                                         newData[colSetting.field] = num;
-                                        const exprInfo = getExprInfo(colSetting.field);
-                                        if (exprInfo) {
-                                            newData[exprInfo.expr] = '';
-                                        }
+                                        if (exprInfo) newData[exprInfo.expr] = '';
                                     } else {
                                         try {
                                             newData[colSetting.field] = math.evaluate(transExpr(newValue));
                                             const exprInfo = getExprInfo(colSetting.field);
-                                            if (exprInfo) {
-                                                newData[exprInfo.expr] = newValue;
-                                            }
+                                            if (exprInfo) newData[exprInfo.expr] = newValue;
                                         } catch(err) {
                                             toastr.error('输入的表达式非法');
                                             stagePosSpreadObj.loadCurPosData();

+ 34 - 39
app/public/js/stage_im.js

@@ -837,27 +837,20 @@ const stageIm = (function () {
         }
     }
 
-    /**
-     * 生成 中间计量表 全部数据
-     * @returns {Array}
-     */
-    function buildImData () {
-        // 初始化
-        ImData = [];
-        pre = (stage.im_pre && stage.im_pre !== '') ? stage.im_pre + splitChar : '';
-        if (stage.im_gather) {
-            initCheck();
-        }
-        // 生成数据
-        console.time('build');
-        recursiveBuildImData(gsTree.children);
-        console.timeEnd('build');
+    function _sortImData() {
         if (stage.im_type !== imType.tz.value) {
             ImData.sort(function (x, y) {
                 const iCode = compareCode(x.code, y.code);
                 return iCode === 0 ? x.lIndex - y.lIndex : iCode;
             });
+        } else {
+            ImData.sort(function (x, y) {
+                return x.lIndex - y.lIndex;
+            });
         }
+    }
+
+    function _buildInfoByCache() {
         for (const [i, im] of ImData.entries()) {
             if (im.source.length > 1) {
                 im.source.sort(function (x, y) {
@@ -866,9 +859,30 @@ const stageIm = (function () {
             }
             getCalcMemo(im);
             getChangeInfo(im);
-            im.im_code = pre + getNumberFormat(stage.order, 2) + splitChar + getNumberFormat(i + 1, 3);
             checkCustomDetail(im);
         }
+    }
+
+    function _buildImCode() {
+        pre = (stage.im_pre && stage.im_pre !== '') ? stage.im_pre + splitChar : '';
+        for (const [i, im] of ImData.entries()) {
+            im.im_code = pre + getNumberFormat(stage.order, 2) + splitChar + getNumberFormat(i + 1, 3);
+        }
+    }
+
+    /**
+     * 生成 中间计量表 全部数据
+     * @returns {Array}
+     */
+    function buildImData () {
+        // 初始化
+        ImData = [];
+        if (stage.im_gather) initCheck();
+        // 生成数据
+        recursiveBuildImData(gsTree.children);
+        _buildInfoByCache();
+        _sortImData();
+        _buildImCode();
         return ImData;
     }
 
@@ -903,32 +917,13 @@ const stageIm = (function () {
             return refreshIds.indexOf(x.lid) < 0
         }) : [];
         ImData = [];
-        pre = (stage.im_pre && stage.im_pre !== '') ? stage.im_pre + splitChar : '';
-        if (stage.im_gather) {
-            initCheck();
-        }
+        if (stage.im_gather) initCheck();
         // 生成数据
         recursiveReBuildImData(gsTree.children, refreshIds);
-        for (const [i, im] of ImData.entries()) {
-            if (im.source.length > 1) {
-                im.source.sort(function (x, y) {
-                    return compareCode(x.b_code, y.b_code);
-                });
-            }
-            getCalcMemo(im);
-            getChangeInfo(im);
-            checkCustomDetail(im);
-        }
+        _buildInfoByCache();
         ImData = ImData.concat(orgImData);
-        if (stage.im_type !== imType.tz.value) {
-            ImData.sort(function (x, y) {
-                const iCode = compareCode(x.code, y.code);
-                return iCode === 0 ? x.lIndex - y.lIndex : iCode;
-            });
-        }
-        for (const [i, im] of ImData.entries()) {
-            im.im_code = pre + getNumberFormat(stage.order, 2) + splitChar + getNumberFormat(i + 1, 3);
-        }
+        _sortImData();
+        _buildImCode();
         orgImData = [];
         return ImData;
     }

+ 0 - 1
app/service/stage_bills.js

@@ -251,7 +251,6 @@ module.exports = app => {
                         await this._insertStageBillsData(transaction, d, stageBills, ledgerBills);
                     } else {
                         d.id = stageBills.id;
-                        console.log(d);
                         this._calcStageBillsData(d, stageBills, ledgerBills);
                         await transaction.update(this.tableName, d);
                     }