Ver código fonte

台账修订,表达式相关

maixinrong 5 anos atrás
pai
commit
4e0e84d7a1
1 arquivos alterados com 24 adições e 14 exclusões
  1. 24 14
      app/public/js/revise.js

+ 24 - 14
app/public/js/revise.js

@@ -1001,6 +1001,24 @@ $(document).ready(() => {
     }
     // 计量单元 相关方法&绑定spreadjs事件
     const posSpreadObj = {
+        loadExprToInput: function () {
+            const sel = posSheet.getSelections()[0];
+            if (!sel) return;
+
+            const col = posSheet.zh_setting.cols[sel.col];
+            const cell = posSheet.getCell(sel.col, sel.col);
+            if (col && col.type === 'Number') {
+                const data = SpreadJsObj.getSelectObject(posSheet);
+                if (data) {
+                    $('#pos-expr').val(data[col.field]).attr('field', col.field).attr('org', data[col.field])
+                        .attr('row', sel.row).attr('readOnly', readOnly || cell.locked());
+                } else {
+                    $('#pos-expr').val('').attr('readOnly', true);
+                }
+            } else {
+                $('#pos-expr').val('').attr('readOnly', true);
+            }            
+        },
         /**
          * 加载计量单元 根据当前台账选择节点
          */
@@ -1013,6 +1031,7 @@ $(document).ready(() => {
                 SpreadJsObj.loadSheetData(posSheet, 'data', []);
             }
             SpreadJsObj.resetFieldReadOnly(posSheet);
+            posSpreadObj.loadExprToInput();
         },
         editStarting: function (e, info) {
             posSpreadObj.billsNode = SpreadJsObj.getSelectObject(billsSheet);
@@ -1285,19 +1304,7 @@ $(document).ready(() => {
             });
         },
         selectionChanged: function (e, info) {
-            const col = info.sheet.zh_setting.cols[info.newSelections[0].col];
-            const cell = info.sheet.getCell(info.newSelections[0].col, info.newSelections[0].col);
-            if (col && col.type === 'Number') {
-                const data = SpreadJsObj.getSelectObject(info.sheet);
-                if (data) {
-                    $('#pos-expr').val(data[col.field]).attr('field', col.field).attr('org', data[col.field])
-                        .attr('row', info.newSelections[0].row).attr('readOnly', readOnly || cell.locked());
-                } else {
-                    $('#pos-expr').val('').attr('readOnly', true);
-                }
-            } else {
-                $('#pos-expr').val('').attr('readOnly', true);
-            }
+            posSpreadObj.loadExprToInput();
         },
         addPegs: function (pegs) {
             if (!pegs || pegs.length <= 0) return;
@@ -1320,12 +1327,15 @@ $(document).ready(() => {
     if (!readOnly && isTz) {
         $('#pos-expr').bind('change mouseleave', function () {
             if (this.readOnly) return;
+            if (document.activeElement.id !== 'pos-expr') return;
 
             const expr = $(this);
             const select = SpreadJsObj.getSelectObject(posSheet);
+            if (!select) return;
+
             const row = posSheet.getSelections()[0].row;
             const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = trimInvalidChar(expr.val());
-            if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
+            if (orgValue === newValue || (!orgValue && newValue == '')) return;
 
             const data = {id: select.id};
             if (newValue !== '') {