瀏覽代碼

台账分解,台账修订,记住选择的标准清单、项目节

MaiXinRong 5 年之前
父節點
當前提交
5ecb36efdc
共有 3 個文件被更改,包括 27 次插入17 次删除
  1. 2 2
      app/public/js/ledger.js
  2. 0 2
      app/public/js/revise.js
  3. 25 13
      app/public/js/std_lib.js

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

@@ -1619,13 +1619,13 @@ $(document).ready(function() {
             if (tab.attr('content') === '#std-xmj') {
                 if (!stdXmj) {
                     stdXmj = new stdLib(stdXmjSetting);
-                    stdXmj.loadLib($('select', '#std-xmj').val());
+                    //stdXmj.loadLib($('select', '#std-xmj').val());
                 }
                 stdXmj.spread.refresh();
             } else if (tab.attr('content') === '#std-gcl') {
                 if (!stdGcl) {
                     stdGcl = new stdLib(stdGclSetting);
-                    stdGcl.loadLib($('select', '#std-gcl').val());
+                    //stdGcl.loadLib($('select', '#std-gcl').val());
                 }
                 stdGcl.spread.refresh();
             } else if (tab.attr('content') === '#deal-bills') {

+ 0 - 2
app/public/js/revise.js

@@ -1543,13 +1543,11 @@ $(document).ready(() => {
             if (tab.attr('content') === '#std-xmj') {
                 if (!stdXmj) {
                     stdXmj = new stdLib(stdXmjSetting);
-                    stdXmj.loadLib($('select', '#std-xmj').val());
                 }
                 stdXmj.spread.refresh();
             } else if (tab.attr('content') === '#std-gcl') {
                 if (!stdGcl) {
                     stdGcl = new stdLib(stdGclSetting);
-                    stdGcl.loadLib($('select', '#std-gcl').val());
                 }
                 stdGcl.spread.refresh();
             } else if (tab.attr('content') === '#deal-bills') {

+ 25 - 13
app/public/js/std_lib.js

@@ -8,14 +8,9 @@
  * @version
  */
 
-// setting = {
-//     selector,
-//     stdType,
-//     treeSetting,
-//     spreadSetting,
-//     cellDoubleClick,
-//     page,
-// };
+/**
+ * setting = { selector, stdType, treeSetting, spreadSetting, cellDoubleClick, page, };
+ */
 
 class stdLib {
     constructor(setting) {
@@ -32,26 +27,41 @@ class stdLib {
         this.spread.getActiveSheet().bind(spreadNS.Events.CellDoubleClick, setting.cellDoubleClick);
         this.spread.getActiveSheet().bind(spreadNS.Events.SelectionChanged, function (e, info) {
             if (!info.oldSelections[0] || info.newSelections[0].row !== info.oldSelections[0].row) {
-                SpreadJsObj.saveTopAndSelect(info.sheet, self.cacheKey);
+                SpreadJsObj.saveTopAndSelect(info.sheet, self.cacheKey.node);
             }
         });
         this.spread.getActiveSheet().bind(spreadNS.Events.TopRowChanged, function (e, info) {
-            SpreadJsObj.saveTopAndSelect(info.sheet, self.cacheKey);
+            SpreadJsObj.saveTopAndSelect(info.sheet, self.cacheKey.node);
         });
         this.pathTree = createNewPathTree('base', this.treeSetting);
         this.cacheLib = [];
+        this.cacheKey = {
+            lib: this.setting.page + '-' + this.setting.stdType,
+        };
         $('select', setting.selector).change(function () {
             self.loadLib(parseInt(this.value), true);
         });
+        this._loadCacheLib();
+    }
+
+    _loadCacheLib() {
+        let libId = getLocalCache(this.cacheKey.lib);
+        if (libId) {
+            $('select', this.setting.selector).val(libId);
+            this.loadLib(parseInt(libId));
+        } else {
+            this.loadLib(parseInt($('select', this.setting.selector).val()));
+        }
     }
+
     loadLib (listId, reload = false) {
-        this.cacheKey = this.setting.page + '-' + this.setting.stdType + '-' + listId;
+        this.cacheKey.node = this.setting.page + '-' + this.setting.stdType + '-' + listId;
         const self = this;
         const locateMemory = function () {
             if (!reload) {
-                SpreadJsObj.loadTopAndSelect(self.spread.getActiveSheet(), self.cacheKey);
+                SpreadJsObj.loadTopAndSelect(self.spread.getActiveSheet(), self.cacheKey.node);
             } else {
-                removeLocalCache(self.cacheKey);
+                removeLocalCache(self.cacheKey.node);
             }
         };
         const cacheData = this.cacheLib.find(function (lib) {
@@ -61,12 +71,14 @@ class stdLib {
             this.pathTree.loadDatas(cacheData.data);
             SpreadJsObj.loadSheetData(this.spread.getActiveSheet(), 'tree', this.pathTree);
             locateMemory();
+            setLocalCache(this.cacheKey.lib, listId);
         } else {
             postData('/std-lib/get-data', {stdType: this.stdType, list_id: listId}, function (data) {
                 self.cacheLib.push({id: listId, data: data});
                 self.pathTree.loadDatas(data);
                 SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'tree', self.pathTree);
                 locateMemory();
+                setLocalCache(self.cacheKey.lib, listId);
             });
         }
     }