Browse Source

1. 批量插入部位明细报错
2. 插入后的部位明细排序问题

MaiXinRong 6 years ago
parent
commit
8233f9689b
2 changed files with 19 additions and 7 deletions
  1. 18 6
      app/public/js/path_tree.js
  2. 1 1
      app/service/pos.js

+ 18 - 6
app/public/js/path_tree.js

@@ -44,11 +44,7 @@ class PosData {
             this.ledgerPos[masterKey].push(data);
         }
         for (const prop in this.ledgerPos) {
-            if (this.ledgerPos[prop] instanceof Array) {
-                this.ledgerPos[prop].sort(function (a, b) {
-                    return a.porder - b.porder;
-                })
-            }
+            this.resortLedgerPos(this.ledgerPos[prop]);
         }
     }
 
@@ -58,7 +54,7 @@ class PosData {
      */
     updateDatas(data) {
         const datas = data instanceof Array ? data : [data];
-        const result = { create: [], update: [] };
+        const result = { create: [], update: [] }, resort = [];
         for (const d of datas) {
             const key = itemsPre + d[this.setting.id];
             if (!this.items[key]) {
@@ -78,8 +74,16 @@ class PosData {
                 }
                 result.update.push(pos);
             }
+            const masterKey = itemsPre + d[this.setting.ledgerId];
+            if (resort.indexOf(masterKey) === -1) {
+                resort.push(masterKey);
+            }
+        }
+        for (const s of resort) {
+            this.resortLedgerPos(this.ledgerPos[s]);
         }
         return result;
+
     }
 
     /**
@@ -129,6 +133,14 @@ class PosData {
         return this.ledgerPos[itemsPre + mid];
     }
 
+    resortLedgerPos(ledgerPos) {
+        if (ledgerPos instanceof Array) {
+            ledgerPos.sort(function (a, b) {
+                return a.porder - b.porder;
+            })
+        }
+    }
+
     /**
      * 计算全部
      */

+ 1 - 1
app/service/pos.js

@@ -251,7 +251,7 @@ module.exports = app => {
                 const inD = {
                     id: this.uuid.v4(), tid: tid, lid: bills.id,
                     add_stage: 0, add_times: 0, add_user: this.ctx.session.sessionUser.accountId,
-                    in_time: new Date(), porder: d.order,
+                    in_time: new Date(), porder: data.indexOf(d) + 1,
                     name: d.name, drawing_code: d.drawing_code,
                 };
                 if (d.quantity) {