Sfoglia il codice sorgente

表达式相关调整

MaiXinRong 5 anni fa
parent
commit
2c4b7ad6f0
4 ha cambiato i file con 145 aggiunte e 46 eliminazioni
  1. 57 17
      app/public/js/ledger.js
  2. 37 8
      app/public/js/revise.js
  3. 33 7
      app/public/js/stage.js
  4. 18 14
      app/public/js/stage_pay.js

+ 57 - 17
app/public/js/ledger.js

@@ -127,18 +127,28 @@ $(document).ready(function() {
                         $('#bills-expr').val(data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field])
                             .attr('field', col.field).attr('org', data[col.field]);
                     } else {
-                        $('#bills-expr').val(data[col.field]).attr('field', col.field).attr('org', data[col.field]);
+                        $('#bills-expr').val(data[col.field])
+                            .attr('field', col.field).attr('org', data[col.field]);
                     }
                     if (col.field.indexOf('dgn') >= 0) {
                         $('#bills-expr').attr('readOnly', readOnly || cell.locked() || (_.isString(data.b_code) && data.b_code !== ''));
                     } else {
-                        $('#bills-expr').attr('readOnly', readOnly || cell.locked() || (data.children && data.children.length > 0));
+                        const nodePos = pos.getLedgerPos(data.id);
+                        if (nodePos && nodePos.length > 0) {
+                            $('#bills-expr').val('').attr('readOnly', true);
+                            $('#bills-expr').removeAttr('data-row');
+                        } else {
+                            $('#bills-expr').attr('readOnly', readOnly || cell.locked() || (data.children && data.children.length > 0));
+                        }
                     }
+                    $('#bills-expr').attr('data-row', sel.row);
                 } else {
                     $('#bills-expr').val('').attr('readOnly', true);
+                    $('#bills-expr').removeAttr('data-row');
                 }
             } else {
                 $('#bills-expr').val('').attr('readOnly', true);
+                $('#bills-expr').removeAttr('data-row');
             }
         },
         getSelectNode: function (sheet) {
@@ -866,6 +876,12 @@ $(document).ready(function() {
                 info.cancel = true;
                 return;
             }
+            const exprInfo = getExprInfo(col.field);
+            if (exprInfo) {
+                if (node[exprInfo.expr] && node[exprInfo.expr] !== '') {
+                    info.sheet.getCell(info.row, info.col).text(node[exprInfo.expr]);
+                }
+            }
             switch (col.field) {
                 case 'code':
                     const posRange = pos.getLedgerPos(node.id);
@@ -933,13 +949,10 @@ $(document).ready(function() {
             treeOperationObj.refreshOperationValid(info.sheet, info.newSelections);
         });
         ledgerSpread.bind(GC.Spread.Sheets.Events.EditEnded, treeOperationObj.editEnded);
-        //ledgerSpread.bind(GC.Spread.Sheets.Events.ClipboardPasted, treeOperationObj.clipboardPasted);
         SpreadJsObj.addDeleteBind(ledgerSpread, treeOperationObj.deletePress);
         ledgerSpread.bind(GC.Spread.Sheets.Events.ClipboardChanging, function (e, info) {
             const copyText = SpreadJsObj.getFilterCopyText(info.sheet);
-            //console.log(info.copyData);
             SpreadJsObj.Clipboard.setCopyData(copyText);
-            //copyToClipboard(copyText);
         });
         ledgerSpread.bind(GC.Spread.Sheets.Events.ClipboardPasting, treeOperationObj.clipboardPasting);
         ledgerSpread.bind(spreadNS.Events.EditStarting, treeOperationObj.editStarting);
@@ -983,15 +996,31 @@ $(document).ready(function() {
             });
         });
 
-        $('#bills-expr').bind('change mouseleave', function () {
-            if (document.activeElement.id !== "bills-expr") return;
-
+        $('#bills-expr').bind('change onblur', function () {
             const expr = $(this);
-            const sheet = ledgerSpread.getActiveSheet();
-            const select = SpreadJsObj.getSelectObject(sheet);
+            const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
+            const select = ledgerTree.getItemsByIndex(row);
+            if (!select) return;
+
             const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = trimInvalidChar(expr.val());
             if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
 
+            // 台账模式,检查计量单元相关
+            if (checkTzMeasureType()) {
+                if (field === 'sgfh_qty' || field === 'sgfh_tp' ||
+                    field === 'sjcl_qty' || field === 'sjcl_tp' ||
+                    field === 'qtcl_qty' || field === 'qtcl_tp') {
+                    if (!select.children || select.children.length === 0) {
+                        const lPos = pos.getLedgerPos(select.id);
+                        if (lPos && lPos.length > 0) {
+                            toastr.error('清单含有计量单元,请在计量单元输入数量');
+                            expr.val('');
+                            return;
+                        }
+                    }
+                }
+            }
+
             const data = {
                 id: select.id,
                 tender_id: select.tender_id,
@@ -1026,7 +1055,7 @@ $(document).ready(function() {
             // 更新至服务器
             postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
                 const refreshNode = ledgerTree.loadPostData(result);
-                treeOperationObj.refreshTree(sheet, refreshNode);
+                treeOperationObj.refreshTree(ledgerSpread.getActiveSheet(), refreshNode);
             });
         });
     }
@@ -1451,6 +1480,16 @@ $(document).ready(function() {
         },
         editStarting: function (e, info) {
             posOperationObj.ledgerTreeNode = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
+            const sel = info.sheet.getSelections();
+            if (!sel || !sel[0]) return;
+            const col = info.sheet.zh_setting.cols[sel[0].col];
+            const node = SpreadJsObj.getSelectObject(info.sheet);
+            const exprInfo = getExprInfo(col.field);
+            if (exprInfo) {
+                if (node[exprInfo.expr] && node[exprInfo.expr] !== '') {
+                    info.sheet.getCell(info.row, info.col).text(node[exprInfo.expr]);
+                }
+            }
         },
         loadExprToInput: function () {
             const sheet = posSpread.getActiveSheet();
@@ -1466,12 +1505,14 @@ $(document).ready(function() {
                         ? (data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field])
                         : data[col.field];
                     $('#pos-expr').val(value).attr('field', col.field).attr('org', data[col.field])
-                        .attr('row', sel.row).attr('readOnly', readOnly || cell.locked());
+                        .attr('readOnly', readOnly || cell.locked()).attr('data-row', sel.row);
                 } else {
                     $('#pos-expr').val('').attr('readOnly', true);
+                    $('#pos-expr').removeAttr('data-row');
                 }
             } else {
                 $('#pos-expr').val('').attr('readOnly', true);
+                $('#pos-expr').removeAttr('data-row');
             }
         },
         /**
@@ -1836,15 +1877,14 @@ $(document).ready(function() {
         $('a[name="pos-opr"]').click(function () {
             posOperationObj.baseOpr(posSpread.getActiveSheet(), this.getAttribute('type'));
         });
-        $('#pos-expr').bind('change mouseleave', function () {
-            if (document.activeElement.id !== "pos-expr") return;
-
+        $('#pos-expr').bind('change onblur', function () {
             const expr = $(this);
             const posSheet = posSpread.getActiveSheet();
-            const select = SpreadJsObj.getSelectObject(posSheet);
+            const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
+            const select = posSheet.zh_data ? posSheet.zh_data[row] : null;
             if (!select) return;
 
-            const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = expr.val(), row = trimInvalidChar(expr.attr('row'));
+            const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = expr.val();
             if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
 
             const data = {id: select.id};

+ 37 - 8
app/public/js/revise.js

@@ -97,13 +97,22 @@ $(document).ready(() => {
                     } else if (col.field === 'unit_price') {
                         $('#bills-expr').attr('readOnly', readOnly || cell.locked() || (data.children && data.children.length > 0) || (_.isBoolean(data.used) && data.used === true));
                     } else {
-                        $('#bills-expr').attr('readOnly', readOnly || cell.locked() || (data.children && data.children.length > 0));
+                        const nodePos = pos.getLedgerPos(data.id);
+                        if (nodePos && nodePos.length > 0) {
+                            $('#bills-expr').val('').attr('readOnly', true);
+                            $('#bills-expr').removeAttr('data-row');
+                        } else {
+                            $('#bills-expr').attr('readOnly', readOnly || cell.locked() || (data.children && data.children.length > 0));
+                        }
                     }
+                    $('#bills-expr').attr('data-row', sel.row);
                 } else {
                     $('#bills-expr').val('').attr('readOnly', true);
+                    $('#bills-expr').removeAttr('data-row');
                 }
             } else {
                 $('#bills-expr').val('').attr('readOnly', true);
+                $('#bills-expr').removeAttr('data-row');
             }
         },
         getDefaultSelectInfo: function (sheet) {
@@ -715,6 +724,12 @@ $(document).ready(() => {
                 info.cancel = true;
                 return;
             }
+            const exprInfo = getExprInfo(col.field);
+            if (exprInfo) {
+                if (node[exprInfo.expr] && node[exprInfo.expr] !== '') {
+                    info.sheet.getCell(info.row, info.col).text(node[exprInfo.expr]);
+                }
+            }
             switch (col.field) {
                 case 'code':
                     const posRange = pos.getLedgerPos(node.id);
@@ -834,11 +849,14 @@ $(document).ready(() => {
             });
         });
 
-        $('#bills-expr').bind('change mouseleave', function () {
+        $('#bills-expr').bind('change onblur', function () {
             if (this.readOnly) return;
 
             const expr = $(this);
-            const select = SpreadJsObj.getSelectObject(billsSheet);
+            const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
+            const select = billsTree.getItemsByIndex(row);
+            if (!select) return;
+
             const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = trimInvalidChar(expr.val());
             if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
 
@@ -1124,12 +1142,14 @@ $(document).ready(() => {
                         ? (data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field])
                         : data[col.field];
                     $('#pos-expr').val(value).attr('field', col.field).attr('org', data[col.field])
-                        .attr('row', sel.row).attr('readOnly', readOnly || cell.locked());
+                        .attr('readOnly', readOnly || cell.locked()).attr('data-row', sel.row);
                 } else {
                     $('#pos-expr').val('').attr('readOnly', true);
+                    $('#pos-expr').removeAttr('data-row');
                 }
             } else {
                 $('#pos-expr').val('').attr('readOnly', true);
+                $('#pos-expr').removeAttr('data-row');
             }            
         },
         /**
@@ -1212,6 +1232,16 @@ $(document).ready(() => {
         },
         editStarting: function (e, info) {
             posSpreadObj.billsNode = SpreadJsObj.getSelectObject(billsSheet);
+            const sel = info.sheet.getSelections();
+            if (!sel || !sel[0]) return;
+            const col = info.sheet.zh_setting.cols[sel[0].col];
+            const node = SpreadJsObj.getSelectObject(info.sheet);
+            const exprInfo = getExprInfo(col.field);
+            if (exprInfo) {
+                if (node[exprInfo.expr] && node[exprInfo.expr] !== '') {
+                    info.sheet.getCell(info.row, info.col).text(node[exprInfo.expr]);
+                }
+            }
         },
         /**
          * 编辑单元格响应事件
@@ -1518,15 +1548,14 @@ $(document).ready(() => {
         $('a[name="pos-opr"]').click(function () {
             posSpreadObj.baseOpr(posSheet, this.getAttribute('type'));
         });
-        $('#pos-expr').bind('change mouseleave', function () {
+        $('#pos-expr').bind('change onblur', function () {
             if (this.readOnly) return;
-            if (document.activeElement.id !== 'pos-expr') return;
 
             const expr = $(this);
-            const select = SpreadJsObj.getSelectObject(posSheet);
+            const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
+            const select = posSheet.zh_data ? posSheet.zh_data[row] : null;
             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;
 

+ 33 - 7
app/public/js/stage.js

@@ -539,6 +539,7 @@ $(document).ready(() => {
                 const data = SpreadJsObj.getSelectObject(sheet);
                 if (!data) {
                     $('#bills-expr').val('').attr('readOnly', true);
+                    $('#bills-expr').removeAttr('data-row');
                     return;
                 }
                 const nodePos = stagePos.getLedgerPos(data.id);
@@ -554,8 +555,10 @@ $(document).ready(() => {
                         $('#bills-expr').attr('readOnly', readOnly || cell.locked() || data.is_tp === 1)
                     }
                 }
+                $('#bills-expr').attr('data-row', sel.row);
             } else {
                 $('#bills-expr').val('').attr('readOnly', true);
+                $('#bills-expr').removeAttr('data-row');
             }
         },
         refreshTreeNodes: function (sheet, nodes) {
@@ -908,6 +911,12 @@ $(document).ready(() => {
             if (!info.sheet.zh_setting || !info.sheet.zh_tree) return;
             const col = info.sheet.zh_setting.cols[info.col];
             const node = info.sheet.zh_tree.nodes[info.row];
+            const exprInfo = getExprInfo(col.field);
+            if (exprInfo) {
+                if (node[exprInfo.expr] && node[exprInfo.expr] !== '') {
+                    info.sheet.getCell(info.row, info.col).text(node[exprInfo.expr]);
+                }
+            }
             switch (col.field) {
                 case 'contract_qty':
                 case 'qc_qty':
@@ -983,12 +992,14 @@ $(document).ready(() => {
     slSpread.bind(spreadNS.Events.ButtonClicked, stageTreeSpreadObj.buttonClicked);
     SpreadJsObj.addDeleteBind(slSpread, stageTreeSpreadObj.deletePress);
     if (!readOnly) {
-        $('#bills-expr').bind('change mouseleave', function () {
+        $('#bills-expr').bind('change onblur', function () {
             if (this.readOnly) return;
 
             const expr = $(this);
-            const sheet = slSpread.getActiveSheet();
-            const select = SpreadJsObj.getSelectObject(sheet);
+            const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
+            const select = stageTree.getItemsByIndex(row);
+            if (!select) return;
+
             const field = expr.attr('field'), orgValue = expr.attr('org'), updateData = {};
             let newValue = expr.val();
 
@@ -1042,12 +1053,15 @@ $(document).ready(() => {
                     const exprInfo = getExprInfo(col.field);
                     const value = exprInfo && data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field];
                     $('#pos-expr').val(value).attr('field', col.field).attr('org', data[col.field])
-                        .attr('row', sel.row).attr('readOnly', readOnly || cell.locked());
+                        .attr('readOnly', readOnly || cell.locked());
+                    $('#pos-expr').attr('data-row', sel.row);
                 } else {
                     $('#pos-expr').val('').attr('readOnly', true);
+                    $('#pos-expr').removeAttr('data-row');
                 }
             } else {
                 $('#pos-expr').val('').attr('readOnly', true);
+                $('#pos-expr').removeAttr('data-row');
             }
         },
         /**
@@ -1173,6 +1187,16 @@ $(document).ready(() => {
         },
         editStarting: function (e, info) {
             stagePosSpreadObj.stageTreeNode = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
+            const sel = info.sheet.getSelections();
+            if (!sel || !sel[0]) return;
+            const col = info.sheet.zh_setting.cols[sel[0].col];
+            const node = SpreadJsObj.getSelectObject(info.sheet);
+            const exprInfo = getExprInfo(col.field);
+            if (exprInfo) {
+                if (node[exprInfo.expr] && node[exprInfo.expr] !== '') {
+                    info.sheet.getCell(info.row, info.col).text(node[exprInfo.expr]);
+                }
+            }
         },
         clipboardPasting: function (e, info) {
             if (info.sheet.zh_setting) {
@@ -1452,13 +1476,15 @@ $(document).ready(() => {
     spSpread.bind(spreadNS.Events.SelectionChanged, stagePosSpreadObj.selectionChanged);
     SpreadJsObj.addDeleteBind(spSpread, stagePosSpreadObj.deletePress);
     if (!readOnly) {
-        $('#pos-expr').bind('change mouseleave', function () {
+        $('#pos-expr').bind('change onblur', function () {
             if (this.readOnly) return;
-            if (document.activeElement.id !== "pos-expr") return;
 
             const expr = $(this);
             const posSheet = spSpread.getActiveSheet();
-            const select = SpreadJsObj.getSelectObject(posSheet);
+            const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
+            const select = posSheet.zh_data ? posSheet.zh_data[row] : null;
+            if (!select) return;
+
             const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = expr.val(), row = expr.attr('row');
             if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
 

+ 18 - 14
app/public/js/stage_pay.js

@@ -487,17 +487,23 @@ $(document).ready(() => {
             const sel = sheet.getSelections()[0];
             const col = sheet.zh_setting.cols[sel.col];
             const data = SpreadJsObj.getSelectObject(sheet);
-            if (col.field === 'tp') {
-                $('#expr').val(data.expr).attr('field', 'expr').attr('org', data.expr)
-                    .attr('readOnly', readOnly|| payBase.isSpecial(data));
-            } else if (col.field === 'sprice') {
-                $('#expr').val(data.sexpr).attr('field', 'sexpr').attr('org', data.sexpr)
-                    .attr('readOnly', readOnly|| payCol.readOnly.sprice(data));
-            } else if (col.field === 'rprice') {
-                $('#expr').val(data.rexpr).attr('field', 'rexpr').attr('org', data.rexpr)
-                    .attr('readOnly', readOnly|| payCol.readOnly.rprice(data));
+            if (data) {
+                if (col.field === 'tp') {
+                    $('#expr').val(data.expr).attr('field', 'expr').attr('org', data.expr)
+                        .attr('readOnly', readOnly|| payBase.isSpecial(data));
+                } else if (col.field === 'sprice') {
+                    $('#expr').val(data.sexpr).attr('field', 'sexpr').attr('org', data.sexpr)
+                        .attr('readOnly', readOnly|| payCol.readOnly.sprice(data));
+                } else if (col.field === 'rprice') {
+                    $('#expr').val(data.rexpr).attr('field', 'rexpr').attr('org', data.rexpr)
+                        .attr('readOnly', readOnly|| payCol.readOnly.rprice(data));
+                } else {
+                    $('#expr').val('').attr('readOnly', true);
+                }
+                $('#expr').attr('data-row', sel.row);
             } else {
                 $('#expr').val('').attr('readOnly', true);
+                $('#expr').removeAttr('data-row');
             }
         },
         add: function () {
@@ -848,11 +854,12 @@ $(document).ready(() => {
         $('#del').click(paySpreadObj.del);
         $('#up-move').click(paySpreadObj.upMove);
         $('#down-move').click(paySpreadObj.downMove);
-        $('#expr').bind('change mouseleave', function () {
+        $('#expr').bind('change onblur', function () {
             if (this.readOnly) return;
 
             const expr = $(this);
-            const select = SpreadJsObj.getSelectObject(paySpread.getActiveSheet());
+            const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
+            const select = paySpread.getActiveSheet().zh_data[row];
             const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = expr.val();
             if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
 
@@ -894,9 +901,6 @@ $(document).ready(() => {
                 SpreadJsObj.reLoadSheetData(paySpread.getActiveSheet());
             });
         });
-        // $('#expr').bind('onpaste', function (e) {
-        //     console.log(e);
-        // });
     }
 
     const deadlineObj = {