Browse Source

台账分解、计量台账,页面加载优化相关

MaiXinRong 4 years ago
parent
commit
77f3bb616f

+ 6 - 2
app/public/js/ledger.js

@@ -59,6 +59,7 @@ $(document).ready(function() {
     autoFlashHeight();
     // 初始化台账
     const ledgerSpread = SpreadJsObj.createNewSpread($('#ledger-spread')[0]);
+    removeLocalCache('bills-fold');
     const treeSetting = {
         id: 'ledger_id',
         pid: 'ledger_pid',
@@ -68,8 +69,11 @@ $(document).ready(function() {
         keys: ['id', 'tender_id', 'ledger_id'],
         preUrl: '/tender/' + getTenderId() + '/ledger',
         //treeCacheKey: 'ledger_bills_fold' + '_' + getTenderId(),
-        markFoldKey: 'bills-fold',
-        markFoldSubKey: window.location.pathname.split('/')[2],
+        autoExpand: 3,
+        // markFoldKey: 'bills-fold',
+        // markFoldSubKey: window.location.pathname.split('/')[2],
+        markExpandKey: 'bills-expand',
+        markExpandSubKey: window.location.pathname.split('/')[2],
     };
     if (checkTzMeasureType()) {
         treeSetting.calcFields = ['sgfh_tp', 'sjcl_tp', 'qtcl_tp', 'total_price'];

+ 54 - 21
app/public/js/path_tree.js

@@ -275,11 +275,18 @@ const createNewPathTree = function (type, setting) {
             // 树设置
             this.setting = setting;
 
-            if (this.setting.markFoldKey) {
+            this.hasMark = false;
+            if (this.setting.markExpandKey) {
+                const markStr = getLocalCache(this.setting.markExpandKey);
+                const markData = markStr ? markStr.split('|') : ['', ''];
+                this.hasMark = markData[0] === this.setting.markExpandSubKey;
+                this.markExpand = this.hasMark && markData[1] ? _.map(markData[1].split(','), _.toInteger) : [];
+
+            } else if (this.setting.markFoldKey) {
                  const markStr = getLocalCache(this.setting.markFoldKey);
                  const markData = markStr ? markStr.split('|') : ['', ''];
-                 this.markFold = markData[0] === this.setting.markFoldSubKey && markData[1]
-                     ? _.map(markData[1].split(','), _.toInteger) : [];
+                 this.hasMark = markData[0] === this.setting.markFoldSubKey;
+                 this.markFold = this.hasMark && markData[1] ? _.map(markData[1].split(','), _.toInteger) : [];
             }
             // if (this.setting.treeCacheKey) {
             //     localforage.getItem(this.setting.treeCacheKey).then(function (v) {
@@ -355,10 +362,25 @@ const createNewPathTree = function (type, setting) {
                 return a.order - b.order;
             });
             this.sortTreeNode(true);
-            if (this.setting.autoExpand >= 0) this.expandByLevel(this.setting.autoExpand);
-            if (this.setting.markFoldKey) this.expandByCustom(function (node) {
-                return self.markFold.indexOf(node[self.setting.id]) === -1;
-            });
+            if (this.hasMark) {
+                if (this.setting.markExpandKey) {
+                    this.expandByCustom(node => {
+                        return self.markExpand.indexOf(node[self.setting.id]) >= 0;
+                    });
+                } else if (this.setting.markFoldKey) {
+                    this.expandByCustom(function (node) {
+                        return self.markFold.indexOf(node[self.setting.id]) === -1;
+                    });
+                }
+            } else {
+                if (this.setting.autoExpand >= 0) {
+                    this.expandByLevel(this.setting.autoExpand);
+                    for (const node of this.nodes) {
+                        this._markExpandFold(node);
+                    }
+                    this._saveMarkExpandFold();
+                }
+            }
         }
 
         getItemsByIndex(index) {
@@ -526,18 +548,29 @@ const createNewPathTree = function (type, setting) {
             return node[this.setting.id];
         };
 
-        _markFold(node) {
-            if (!this.setting.markFoldKey || !this.setting.markFoldSubKey) return;
-            // if (!this.setting.treeCacheKey) return;
-
-            if (!node.expanded) {
-                if (this.markFold.indexOf(node[this.setting.id]) === -1) this.markFold.push(node[this.setting.id]);
-            } else {
-                if (this.markFold.indexOf(node[this.setting.id]) >= 0) this.markFold.splice(this.markFold.indexOf(node[this.setting.id]), 1);
+        _markExpandFold(node) {
+            if (this.setting.markExpandKey && this.setting.markExpandSubKey) {
+                if (node.expanded) {
+                    if (this.markExpand.indexOf(node[this.setting.id]) === -1)
+                        this.markExpand.push(node[this.setting.id]);
+                } else {
+                    if (this.markExpand.indexOf(node[this.setting.id]) >= 0)
+                        this.markExpand.splice(this.markExpand.indexOf(node[this.setting.id]), 1);
+                }
+            } else if (this.setting.markFoldKey && this.setting.markFoldSubKey) {
+                if (!node.expanded) {
+                    if (this.markFold.indexOf(node[this.setting.id]) === -1)
+                        this.markFold.push(node[this.setting.id]);
+                } else {
+                    if (this.markFold.indexOf(node[this.setting.id]) >= 0)
+                        this.markFold.splice(this.markFold.indexOf(node[this.setting.id]), 1);
+                }
             }
         }
-        _saveMarkFold() {
-            if (this.setting.markFoldKey && this.setting.markFoldSubKey) {
+        _saveMarkExpandFold() {
+            if (this.setting.markExpandKey && this.setting.markExpandSubKey) {
+                setLocalCache(this.setting.markExpandKey, this.setting.markExpandSubKey + '|' + this.markExpand.join(','));
+            } else if (this.setting.markFoldKey && this.setting.markFoldSubKey) {
                 setLocalCache(this.setting.markFoldKey, this.setting.markFoldSubKey + '|' + this.markFold.join(','));
             }
             // if (this.setting.treeCacheKey) {
@@ -570,9 +603,9 @@ const createNewPathTree = function (type, setting) {
          */
         setExpanded(node, expanded) {
             node.expanded = expanded;
-            this._markFold(node);
+            this._markExpandFold(node);
             this._refreshChildrenVisible(node);
-            this._saveMarkFold();
+            this._saveMarkExpandFold();
         };
         /**
          * 递归 设置节点展开状态
@@ -586,7 +619,7 @@ const createNewPathTree = function (type, setting) {
                 const expanded = checkFun(node);
                 if (node.expanded !== expanded) {
                     node.expanded = expanded;
-                    this._markFold(node);
+                    this._markExpandFold(node);
                 }
                 node.visible = parent ? (parent.expanded && parent.visible) : true;
                 this._recursiveExpand(node.children, node, checkFun);
@@ -598,7 +631,7 @@ const createNewPathTree = function (type, setting) {
          */
         expandByCustom(checkFun) {
             this._recursiveExpand(this.children, null, checkFun);
-            this._saveMarkFold();
+            this._saveMarkExpandFold();
         }
         /**
          * 展开到第几层

+ 18 - 1
app/public/js/spreadjs_rela/spreadjs_zh.js

@@ -506,6 +506,10 @@ const SpreadJsObj = {
     _loadRowData: function (sheet, data, row) {
         // 单元格重新写入数据
         if (!data) { return }
+        if (!data.visible && data.waitingLoading === undefined) {
+            data.waitingLoading = true;
+            return;
+        }
         sheet.zh_setting.cols.forEach(function (col, j) {
             const cell = sheet.getCell(row, j);
             if (col.getValue && Object.prototype.toString.apply(col.getValue) === "[object Function]") {
@@ -550,6 +554,7 @@ const SpreadJsObj = {
             cell.backColor(SpreadJsObj._getBackColor(sheet, data, row, col));
 
             cell.setBorder(sheet.borderLine, {all: true});
+            data.waitingLoading = false;
         });
     },
     _addActivePaintEvents: function (sheet, cellType) {
@@ -1067,8 +1072,14 @@ const SpreadJsObj = {
         for (const iRow in sortData) {
             const node = sortData[iRow];
             if (node.visible !== undefined && node.visible !== null) {
+                if (node.visible && node.waitingLoading) {
+                    SpreadJsObj._loadRowData(sheet, node, parseInt(iRow));
+                }
                 sheet.setRowVisible(iRow, node.visible);
             } else {
+                if (node.waitingLoading) {
+                    this._loadRowData(sheet, node, parseInt(iRow));
+                }
                 sheet.setRowVisible(iRow, true);
             }
         }
@@ -1392,7 +1403,13 @@ const SpreadJsObj = {
                         SpreadJsObj.massOperationSheet(hitinfo.sheet, function () {
                             const posterity = tree.getPosterity(node);
                             for (const child of posterity) {
-                                hitinfo.sheet.setRowVisible(tree.nodes.indexOf(child), child.visible, hitinfo.sheetArea);
+                                const cIndex = tree.getNodeIndex(child);
+                                if (child.visible && child.waitingLoading) {
+                                    SpreadJsObj._loadRowData(hitinfo.sheet, child, cIndex);
+                                }
+                                //if (child.visible !== hitinfo.sheet.getRowVisible(cIndex, hitinfo.sheetArea)) {
+                                    hitinfo.sheet.setRowVisible(cIndex, child.visible, hitinfo.sheetArea);
+                                //}
                             }
                         });
                         hitinfo.sheet.repaint();

+ 6 - 2
app/public/js/stage.js

@@ -238,6 +238,7 @@ $(document).ready(() => {
     // 界面布局
     autoFlashHeight();
     // 初始化 台账树结构 数据结构
+    removeLocalCache('bills-fold');
     const stageTreeSetting = {
         id: 'ledger_id',
         pid: 'ledger_pid',
@@ -246,8 +247,11 @@ $(document).ready(() => {
         rootId: -1,
         keys: ['id', 'tender_id', 'ledger_id'],
         stageId: 'id',
-        markFoldKey: 'bills-fold',
-        markFoldSubKey: window.location.pathname.split('/')[2],
+        autoExpand: 3,
+        // markFoldKey: 'bills-fold',
+        // markFoldSubKey: window.location.pathname.split('/')[2],
+        markExpandKey: 'bills-expand',
+        markExpandSubKey: window.location.pathname.split('/')[2],
     };
     // 台账树结构计算相关设置
     stageTreeSetting.updateFields = ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'postil', 'used', 'contract_expr'];