浏览代码

1. 加密js后,树结构绘制单元格,文字错位
2. 台账、部位明细,重写编辑响应事件

MaiXinRong 6 年之前
父节点
当前提交
b60dd87785
共有 3 个文件被更改,包括 47 次插入42 次删除
  1. 26 24
      app/public/js/ledger.js
  2. 6 4
      app/public/js/spreadjs_rela/spreadjs_zh.js
  3. 15 14
      app/public/js/stage.js

+ 26 - 24
app/public/js/ledger.js

@@ -633,63 +633,65 @@ $(document).ready(function() {
          * @param {Object} e
          * @param {Object} info
          */
-        editEnding: function (e, info) {
+        editEnded: function (e, info) {
             if (info.sheet.zh_setting) {
-                const orgText = info.sheet.getCell(info.row, info.col).text();
-                if (orgText === info.editingText || ((!orgText || orgText === '') && (info.editingText === ''))) {
+                const posData = info.sheet.zh_data ? info.sheet.zh_data[info.row] : null;
+                const col = info.sheet.zh_setting.cols[info.col];
+                const orgText = posData ? posData[col.field] : null;
+                const newText = info.sheet.getCell(info.row, info.col).text();
+                if (orgText === newText || ((!orgText || orgText === '') && (newText === ''))) {
                     return;
                 }
+
                 const node = treeOperationObj.getSelectNode(ledgerSpread.getActiveSheet());
                 if (!node) {
-                    toast('数据错误, 请刷新页面后再试', 'warning')
-                    info.cancel = true;
+                    toast('数据错误,请选择台账节点后再试', 'error');
+                    SpreadJsObj.reLoadRowData(info.sheet, info.row);
                     return;
-                } else if (info.editingText !== '' && node.children && node.children > 0) {
+                } else if (newText && newText !== '' && node.children && node.children.length > 0) {
                     toast('父节点不可插入部位明细', 'error');
-                    info.cancel = true;
+                    SpreadJsObj.reLoadRowData(info.sheet, info.row);
                     return;
-                } else if (info.editingText !== '' && node.code && node.code !== '') {
+                } else if (newText && newText !== '' && (!node.b_code || node.b_code === '')) {
                     toast('项目节不可插入部位明细', 'error');
-                    info.cancel = true;
+                    SpreadJsObj.reLoadRowData(info.sheet, info.row);
                     return;
                 }
-                const curPosData = pos.getLedgerPos(node.id);
-                const position = curPosData ? curPosData[info.row] : null;
-                const col = info.sheet.zh_setting.cols[info.col];
+
                 const data = {};
                 if (col.field === 'name') {
-                    if (info.editingText === '' && position) {
+                    if (newText === '' && posData) {
                         toast('部位名称不可为空', 'error', 'exclamation-circle');
-                        info.cancel = true;
+                        SpreadJsObj.reLoadRowData(info.sheet, info.row);
                         return;
-                    } else if (!position) {
-                        if (info.editingText !== '') {
+                    } else if (!posData) {
+                        if (newText && newText !== '') {
                             data.updateType = 'add';
-                            data.updateData = { name: info.editingText, lid: node.id, tid: tender.id };
+                            data.updateData = { name: newText, lid: node.id, tid: tender.id};
                         } else {
                             return;
                         }
                     } else {
                         data.updateType = 'update';
-                        data.updateData = {id: position.id, name: info.editingText};
+                        data.updateData = {id: posData.id, name: newText};
                     }
-                } else if (!position) {
+                } else if (!posData) {
                     toast('新增部位请先输入名称', 'warning');
-                    info.cancel = true;
+                    SpreadJsObj.reLoadRowData(info.sheet, info.row);
                     return;
                 } else {
                     data.updateType = 'update';
                     data.updateData = {id: position.id};
-                    data.updateData[col.field] = col.type === 'Number' ? parseFloat(info.editingText) : info.editingText;
+                    data.updateData[col.field] = col.type === 'Number' ? parseFloat(newText) : newText;
                 }
                 postData('/tender/' + getTenderId() + '/pos/update', data, function (result) {
                     pos.updateDatas(result.pos);
-                    posOperationObj.loadCurPosData();
+                    SpreadJsObj.reLoadRowData(info.sheet, info.row);
                     ledgerTree.loadPostData(result.ledger, function (loadResult) {
                         treeOperationObj.refreshTree(ledgerSpread.getActiveSheet(), loadResult);
                     });
                 }, function () {
-                    posOperationObj.loadCurPosData();
+                    SpreadJsObj.reLoadRowData(info.sheet, info.row);
                 });
             }
         },
@@ -809,7 +811,7 @@ $(document).ready(function() {
     posOperationObj.loadCurPosData();
     if (!posSpreadSetting.readOnly) {
         SpreadJsObj.addDeleteBind(posSpread, posOperationObj.deletePress);
-        posSpread.bind(GC.Spread.Sheets.Events.EditEnding, posOperationObj.editEnding);
+        posSpread.bind(GC.Spread.Sheets.Events.EditEnded, posOperationObj.editEnded);
         posSpread.bind(GC.Spread.Sheets.Events.ClipboardPasted, posOperationObj.clipboardPasted);
         // 右键菜单
         $.contextMenu({

+ 6 - 4
app/public/js/spreadjs_rela/spreadjs_zh.js

@@ -26,8 +26,9 @@ proto.dottedLine = function (x1, y1, x2, y2, interval = 4) {
         progress += interval;
     }
 };
-
+// 简写Spread常量
 const spreadNS = GC.Spread.Sheets;
+// SpreadJs常用方法
 const SpreadJsObj = {
     DataType: {
         Data: 'data',
@@ -730,12 +731,13 @@ const SpreadJsObj = {
                             }
                         };
                         // 重定位x
-                        x = x + (node.level + 1) * indent + (node.level) * levelIndent;
-                        w = w - (node.level + 1) * indent - (node.level) * levelIndent;
+                        const move = (node.level + 1) * indent + (node.level) * levelIndent;
+                        x = x + move;
+                        w = w - move;
                     }
                 }
                 // Drawing Text
-                spreadNS.CellTypes.Text.prototype.paint.apply(this, arguments);
+                spreadNS.CellTypes.Text.prototype.paint.apply(this, [canvas, value, x, y, w, h, style, options]);
             };
             /**
              * 获取点击信息

+ 15 - 14
app/public/js/stage.js

@@ -114,7 +114,7 @@ $(document).ready(() => {
             }
             SpreadJsObj.reLoadRowsData(sheet, rows);
         },
-        editEnding: function (e, info) {
+        editEnded: function (e, info) {
             if (info.sheet.zh_setting) {
                 const col = info.sheet.zh_setting.cols[info.col];
                 const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
@@ -122,13 +122,13 @@ $(document).ready(() => {
 
                 if (node.children && node.children.length > 0) {
                     toast('清单父项不可计量', 'error');
-                    info.cancel = true;
+                    SpreadJsObj.reLoadRowData(info.sheet, info.row);
                     return;
                 } else {
                     const nodePos = stagePos.getLedgerPos(node.id);
                     if (nodePos && nodePos.length > 0) {
                         toast('该清单有部位明细,请在部位明细处计量', 'error');
-                        info.cancel = true;
+                        SpreadJsObj.reLoadRowData(info.sheet, info.row);
                         return;
                     }
                 }
@@ -239,7 +239,7 @@ $(document).ready(() => {
             }
         }
     };
-    slSpread.bind(spreadNS.Events.EditEnding, stageTreeSpreadObj.editEnding);
+    slSpread.bind(spreadNS.Events.EditEnded, stageTreeSpreadObj.editEnded);
     slSpread.bind(spreadNS.Events.SelectionChanged, stageTreeSpreadObj.selectionChanged);
     slSpread.bind(spreadNS.Events.ClipboardPasting, stageTreeSpreadObj.clipboardPasting);
     slSpread.bind(spreadNS.Events.ClipboardPasted, stageTreeSpreadObj.clipboardPasted);
@@ -258,17 +258,17 @@ $(document).ready(() => {
                 SpreadJsObj.loadSheetData(spSpread.getActiveSheet(), 'data', []);
             }
         },
-        editEnding: function(e, info) {
+        editEdited: function (e, info) {
             if (info.sheet.zh_setting) {
                 // 未改变过,则直接跳过
-                const orgText = info.sheet.getCell(info.row, info.row).value();
+                const posData = info.sheet.zh_data ? info.sheet.zh_data[info.row] : null;
+                const col = info.sheet.zh_setting.cols[info.col];
+                const orgText = posData ? posData[col.field] : null;
                 if (orgText === info.editingText || ((!orgText || orgText === '') && (info.editingText === ''))) {
-                    info.cancel = true;
                     return;
                 }
                 // 台账模式下,不可新增
-                const pos = info.sheet.zh_data ? info.sheet.zh_data[info.row] : null;
-                if (checkTzMeasureType() && !pos) {
+                if (checkTzMeasureType() && !posData) {
                     toast('台账模式不可新增部位明细数据', 'error');
                     info.cancel = true;
                     return ;
@@ -277,18 +277,18 @@ $(document).ready(() => {
                 const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
                 if (!node) {
                     toast('数据错误, 请刷新页面后再试', 'warning');
-                    info.cancel = true;
+                    SpreadJsObj.reLoadRowData(info.sheet, info.row);
                     return;
                 } else if (info.editingText !== '' && node.children && node.children > 0) {
                     toast('父节点不可插入部位明细', 'error');
-                    info.cancel = true;
+                    SpreadJsObj.reLoadRowData(info.sheet, info.row);
                     return;
                 } else if (info.editingText !== '' && !node.b_code || node.b_code === '') {
                     toast('项目节不可插入部位明细', 'error');
-                    info.cancel = true;
+                    SpreadJsObj.reLoadRowData(info.sheet, info.row);
                     return;
                 }
-                const col = info.sheet.zh_setting.cols[info.col];
+                // 生成提交数据
                 const data = {};
                 if (col.field === 'name') {
                     if (info.editingText === '' && pos) {
@@ -313,6 +313,7 @@ $(document).ready(() => {
                     data.updateData = {pid: pos.id, lid: pos.lid};
                     data.updateData[col.field] = col.type === 'Number' ? parseFloat(info.editingText) : info.editingText;
                 }
+                // 提交数据到服务器
                 postData(window.location.pathname + '/update', {pos: data}, function (result) {
                     if (result.pos) {
                         stagePos.updateDatas(result.pos.pos);
@@ -479,7 +480,7 @@ $(document).ready(() => {
         }
         stagePosSpreadObj.loadCurPosData();
     });
-    spSpread.bind(spreadNS.Events.EditEnding, stagePosSpreadObj.editEnding);
+    spSpread.bind(spreadNS.Events.EditEnded, stagePosSpreadObj.editEnded);
     spSpread.bind(spreadNS.Events.ClipboardPasting, stagePosSpreadObj.clipboardPasting);
     spSpread.bind(spreadNS.Events.ClipboardPasted, stagePosSpreadObj.clipboardPasted);
     SpreadJsObj.addDeleteBind(spSpread, stagePosSpreadObj.deletePress);