Преглед на файлове

部位台账,排序问题

MaiXinRong преди 5 години
родител
ревизия
417d8c6c9c
променени са 2 файла, в които са добавени 26 реда и са изтрити 28 реда
  1. 6 10
      app/lib/bills_pos_convert.js
  2. 20 18
      app/lib/ledger.js

+ 6 - 10
app/lib/bills_pos_convert.js

@@ -180,7 +180,6 @@ class BillsPosConvert {
                     this._loadField(curXmj, node, this.tpFields);
                 }
             }
-
         }
     }
 
@@ -259,16 +258,13 @@ class BillsPosConvert {
         for (const node of nodes) {
             this._recursiveCalculateAndSort(node.children);
             if (node.unitTree) {
-                node.unitTree.sortTreeNodeCustom('b_code', function (a, b) {
-                    const numReg = /^[0-9]+$/;
-                    const aCodes = a ? a.split('-') : [], bCodes = b ? b.split('-') : [];
-                    for (let i = 0, iLength = Math.min(aCodes.length, bCodes.length); i < iLength; ++i) {
-                        const iCompare = self.ctx.helper.compareCode(aCodes[i], bCodes[i]);
-                        if (iCompare !== 0) {
-                            return iCompare;
-                        }
+                node.unitTree.sortTreeNodeCustom(function (a, b) {
+                    if (a.b_code && a.b_code !== '') {
+                        return b.b_code && b.b_code !== '' ? self.ctx.helper.compareCode(a.b_code, b.b_code) : 1;
+                    } else {
+                        return b.b_code && b.b_code !== '' ? -1 : a.order - b.order;
                     }
-                }, false);
+                });
                 this._recursiveCalcUnitNodes(node.unitTree.children);
                 this._calculateNode(node, node.unitTree.children, this.tpFields);
             } else if (node.children && node.children.length > 0) {

+ 20 - 18
app/lib/ledger.js

@@ -384,34 +384,36 @@ class filterGatherTree extends baseTree {
         return item;
     }
 
-    sortTreeNodeCustom(field, fun, isResort) {
+    generateSortNodes() {
         const self = this;
+        const addSortNode = function (node) {
+            self.nodes.push(node);
+            for (const c of node.children) {
+                addSortNode(c);
+            }
+        };
+        this.nodes = [];
+        for (const n of this.children) {
+            addSortNode(n);
+        }
+    }
+
+    sortTreeNodeCustom(fun) {
         const sortNodes = function (nodes) {
-            nodes.sort(function (a, b) {
-                return fun(a[field], b[field]);
-            });
+            nodes.sort(fun);
             for (const [i, node] of nodes.entries()) {
                 node.order = i + 1;
             }
-        };
-        const addSortNodes = function (nodes) {
-            if (!nodes) { return }
-            for (let i = 0; i < nodes.length; i++) {
-                self.nodes.push(nodes[i]);
-                nodes[i].index = self.nodes.length - 1;
-                if (!isResort) {
-                    nodes[i].children = self.getChildren(nodes[i]);
+            for (const node of nodes) {
+                if (node.children && node.children.length > 1) {
+                    sortNodes(node.children);
                 }
-                sortNodes(nodes[i].children);
-                addSortNodes(nodes[i].children);
             }
         };
         this.nodes = [];
-        if (!isResort) {
-            this.children = this.getChildren();
-        }
+        this.children = this.getChildren(null);
         sortNodes(this.children);
-        addSortNodes(this.children);
+        this.generateSortNodes();
     }
 }