Browse Source

调用变更令后,更新中间计量数据

MaiXinRong 5 years ago
parent
commit
fd2cad854a

+ 1 - 1
app/const/tender.js

@@ -59,7 +59,7 @@ const measureType = {
 const imType = {
     zl: { value: 0, name: '总量控制' },
     tz: { value: 1, name: '0号台账' },
-    bw: { value: 2, name: '清单部位' },
+    bw: { value: 2, name: '计量单元' },
 };
 
 const typeString = [];

+ 6 - 0
app/controller/stage_controller.js

@@ -392,8 +392,14 @@ module.exports = app => {
                 let result;
                 if (data.target.pos) {
                     result = await ctx.service.stageChange.posChange(data.target.pos, data.change);
+                    result.change = { target: {lid: data.target.pos.lid, pid: data.target.pos.id } };
+                    result.change.data = await ctx.service.stageChange.getLastestStageData(ctx.tender.id,
+                        ctx.stage.id, data.target.pos.lid, data.target.pos.id);
                 } else {
                     result = await ctx.service.stageChange.billsChange(data.target.bills, data.change);
+                    result.change = { target: { lid: data.target.bills.id, pid: '-1' } };
+                    result.change.data = await ctx.service.stageChange.getLastestStageData(ctx.tender.id,
+                        ctx.stage.id, data.target.bills.id, '-1');
                 }
                 await ctx.service.stage.updateCheckCalcFlag(ctx.stage.id, true);
                 ctx.body = {err: 0, msg: '', data: result};

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

@@ -312,7 +312,7 @@ $(document).ready(() => {
                     const nodes = stageTree.loadPostStageData(result.bills);
                     stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
                     stagePosSpreadObj.loadCurPosData();
-                    detail.loadStageLedgerUpdateData(result);
+                    detail.loadStageChangeUpdateData(result);
                     self.obj.modal('hide');
                 });
             })
@@ -2385,6 +2385,11 @@ $(document).ready(() => {
             SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
             this.reLoadDetailData();
         }
+        loadStageChangeUpdateData(data) {
+            const imData = stageIm.loadUpdateChangeData(data);
+            SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
+            this.reLoadDetailData();
+        }
         reLoadDetailData() {
             const data = SpreadJsObj.getSelectObject(this.spread.getActiveSheet());
 

+ 28 - 8
app/public/js/stage_im.js

@@ -322,7 +322,7 @@ const stageIm = (function () {
             const posRange = gsPos.getLedgerPos(p.id);
             if (!posRange) {
                 for (const c of changes) {
-                    if (c.lid === p.id && c.pid == -1) {
+                    if (c.lid === p.id && c.pid == -1 && c.qty && c.qty !== 0) {
                         im.changes.push(c);
                     }
                 }
@@ -332,7 +332,7 @@ const stageIm = (function () {
                         continue;
                     }
                     for (const c of changes) {
-                        if (c.lid === p.id && c.pid === pp.id) {
+                        if (c.lid === p.id && c.pid === pp.id && c.qty && c.qty !== 0) {
                             im.changes.push(c);
                         }
                     }
@@ -411,23 +411,23 @@ const stageIm = (function () {
         if (!im.changes) {
             im.changes = [];
         }
-        if ((!node.qc_tp || node.qc_tp === 0)) {
+        if ((!node.qc_qty || node.qc_qty === 0)) {
             return;
         }
         const posRange = gsPos.getLedgerPos(node.id);
         if (!posRange) {
             for (const c of changes) {
-                if (c.lid === node.id && c.pid == -1) {
+                if (c.lid === node.id && c.pid == -1 && c.qty && c.qty !== 0) {
                     im.changes.push(c);
                 }
             }
         } else {
             for (const p of posRange) {
-                if ((!p.qc_tp || p.qc_tp === 0)) {
+                if ((!p.qc_qty || p.qc_qty === 0)) {
                     continue;
                 }
                 for (const c of changes) {
-                    if (c.lid === node.id && c.pid === p.id) {
+                    if (c.lid === node.id && c.pid === p.id && c.qty && c.qty !== 0) {
                         im.changes.push(c);
                     }
                 }
@@ -503,7 +503,7 @@ const stageIm = (function () {
                     ImData.push(im);
                     if (pp.qc_qty && pp.qc_qty !== 0) {
                         for (const c of changes) {
-                            if (c.lid === p.id && c.pid === pp.id) {
+                            if (c.lid === p.id && c.pid === pp.id && c.qty && c.qty !== 0) {
                                 im.changes.push(c);
                             }
                         }
@@ -527,7 +527,7 @@ const stageIm = (function () {
                 ImData.push(im);
                 if (p.qc_qty && p.qc_qty !== 0) {
                     for (const c of changes) {
-                        if (c.lid === p.id && c.pid == -1) {
+                        if (c.lid === p.id && c.pid == -1 && c.qty && c.qty !== 0) {
                             im.changes.push(c);
                         }
                     }
@@ -600,6 +600,12 @@ const stageIm = (function () {
 
     function loadUpdateLedgerData(data) {
         gsTree.loadPostStageData(data);
+        if (data.change) {
+            _.remove(changes, data.change.target);
+            for (const c of data.change.data) {
+                changes.push(c);
+            }
+        }
         return buildImData();
     }
     function loadUpdatePosData(data) {
@@ -610,6 +616,19 @@ const stageIm = (function () {
         gsTree.loadPostStageData(data.ledger);
         return buildImData();
     }
+    function loadUpdateChangeData(data) {
+        if (data.pos) {
+            gsPos.loadCurStageData(data.pos.curStageData);
+        }
+        gsTree.loadPostStageData(data.bills);
+        if (data.change) {
+            _.remove(changes, data.change.target);
+            for (const c of data.change.data) {
+                changes.push(c);
+            }
+        }
+        return buildImData();
+    }
 
     return {
         init,
@@ -619,6 +638,7 @@ const stageIm = (function () {
         loadUpdateDetailData,
         loadUpdateLedgerData,
         loadUpdatePosData,
+        loadUpdateChangeData,
         getGsTree: function () {
             return gsTree;
         },

+ 16 - 8
app/service/stage_change.js

@@ -36,13 +36,17 @@ module.exports = app => {
          * @returns {Promise<*>}
          */
         async getLastestStageData(tid, sid, lid, pid) {
-            const sql = 'SELECT c.* FROM ' + this.tableName + ' As c ' +
+            const sql = 'SELECT c.*,' +
+                '  oc.code As c_code, oc.new_code As c_new_code' +
+                '  FROM ' + this.tableName + ' As c ' +
                 '  INNER JOIN ( ' +
                 '    SELECT MAX(`stimes`) As `stimes`, MAX(`sorder`) As `sorder`, `lid`, `pid`, `sid` From ' + this.tableName +
                 '      WHERE tid = ? And sid = ? And lid = ? And pid = ?' +
                 '      GROUP By `lid`, `pid`' +
                 '  ) As m ' +
-                '  ON c.stimes = m.stimes And c.sorder = m.sorder And c.lid = m.lid And c.pid = m.pid And c.`sid` = m.`sid`';
+                '  ON c.stimes = m.stimes And c.sorder = m.sorder And c.lid = m.lid And c.pid = m.pid And c.`sid` = m.`sid`' +
+                '  LEFT JOIN ' + this.ctx.service.change.tableName + ' As oc' +
+                '  ON c.cid = oc.cid';
             const sqlParam = [tid, sid, lid, pid ? pid : -1];
             return await this.db.query(sql, sqlParam);
         }
@@ -58,7 +62,7 @@ module.exports = app => {
          * @returns {Promise<*>}
          */
         async getAuditorStageData(tid, sid, times, order, lid, pid) {
-            const sql = 'SELECT c.*' +
+            const sql = 'SELECT c.*,' +
                 '  oc.code As c_code, oc.new_code As c_new_code' +
                 '  FROM ' + this.tableName + ' As c ' +
                 '  INNER JOIN ( ' +
@@ -66,9 +70,9 @@ module.exports = app => {
                 '      WHERE tid = ? And sid = ? And (`stimes` < ? OR (`stimes` = ? AND `sorder` <= ?)) And lid = ? And pid = ?' +
                 '      GROUP By `lid`, `pid`' +
                 '  ) As m ' +
-                '  ON c.stimes = m.stimes And c.sorder = m.sorder And c.lid = m.lid And c.pid = m.pid And c.`sid` = m.`sid`'
-            '  LEFT JOIN ' + this.ctx.service.change.tableName + ' As oc' +
-            '  ON c.cid = oc.cid';
+                '  ON c.stimes = m.stimes And c.sorder = m.sorder And c.lid = m.lid And c.pid = m.pid And c.`sid` = m.`sid`' +
+                '  LEFT JOIN ' + this.ctx.service.change.tableName + ' As oc' +
+                '  ON c.cid = oc.cid';
             const sqlParam = [tid, sid, times, times, order, lid, pid ? pid : -1];
             return await this.db.query(sql, sqlParam);
         }
@@ -90,13 +94,17 @@ module.exports = app => {
         }
 
         async getAuditorAllStageData(tid, sid, times, order) {
-            const sql = 'SELECT c.* FROM ' + this.tableName + ' As c ' +
+            const sql = 'SELECT c.*, ' +
+                '  oc.code As c_code, oc.new_code As c_new_code' +
+                '  FROM ' + this.tableName + ' As c ' +
                 '  INNER JOIN ( ' +
                 '    SELECT MAX(`stimes`) As `stimes`, MAX(`sorder`) As `sorder`, `lid`, `pid`, `sid` From ' + this.tableName +
                 '      WHERE tid = ? And sid = ? And (`stimes` < ? OR (`stimes` = ? AND `sorder` <= ?))' +
                 '      GROUP By `lid`, `pid`' +
                 '  ) As m ' +
-                '  ON c.stimes = m.stimes And c.sorder = m.sorder And c.`sid` = m.`sid`';
+                '  ON c.stimes = m.stimes And c.sorder = m.sorder And c.`sid` = m.`sid`' +
+                '  LEFT JOIN ' + this.ctx.service.change.tableName + ' As oc' +
+                '  ON c.cid = oc.cid';
             const sqlParam = [tid, sid, times, times, order];
             return await this.db.query(sql, sqlParam);
         }