Forráskód Böngészése

1. 台账分解,不显示辅材
2. 台账分解,复制粘贴整块,带附属工程量数据

MaiXinRong 1 éve
szülő
commit
329e61a04e

+ 28 - 3
app/base/base_bills_service.js

@@ -21,9 +21,10 @@ const billsUtils = require('../lib/bills_utils');
 
 class BaseBillsSerivce extends TreeService {
 
-    constructor (ctx, setting, relaPosName) {
+    constructor (ctx, setting, relaPosName, relaAncGclName) {
         super(ctx, setting);
         this.relaPosService = relaPosName;
+        this.relaAncGclService = relaAncGclName;
     }
 
     async getFinalData(mid, columns) {
@@ -41,6 +42,14 @@ class BaseBillsSerivce extends TreeService {
         return this.ctx.service[this._posName];
     }
 
+    set relaAncGclService(ancGclName) {
+        this._ancGclName = ancGclName;
+    }
+
+    get relaAncGclService() {
+        return this._ancGclName ? this.ctx.service[this._ancGclName] : undefined;
+    }
+
     // 继承方法
     clearParentingData(data) {
         data.unit_price = null;
@@ -570,12 +579,13 @@ class BaseBillsSerivce extends TreeService {
             });
             if (pd[0].ledger_pid !== pasteData[0][0].ledger_pid) throw '复制数据错误:仅可操作同层节点';
         }
+        const userId = this.ctx.session.sessionUser.accountId;
         this.newBills = false;
         const selectData = await this.getDataByKid(tid, sid);
         if (!selectData) throw '粘贴数据错误';
         const newParentPath = selectData.full_path.replace(selectData.ledger_id, '');
 
-        const pasteBillsData = [], pastePosData = [], leafBillsId = [];
+        const pasteBillsData = [], pastePosData = [], pasteAncGclData = [], leafBillsId = [];
         const tpDecimal = this.ctx.tender.info.decimal.tp;
         let maxId = await this._getMaxLid(this.ctx.tender.id);
         for (const [i, pd] of pasteData.entries()) {
@@ -665,6 +675,19 @@ class BaseBillsSerivce extends TreeService {
                 newBills.total_price = this.ctx.helper.mul(newBills.quantity, newBills.unit_price, tpDecimal);
                 newBills.deal_tp = this.ctx.helper.mul(newBills.deal_qty, newBills.unit_price, tpDecimal);
                 if (defaultData) this.ctx.helper._.assignIn(newBills, defaultData);
+                if (d.ancGcl && d.ancGcl.length > 0) {
+                    for (const gcl of d.ancGcl) {
+                        const newAncGcl = {
+                            id: this.uuid.v4(), tid: tid, lid: newBills.id,
+                            add_user_id: userId, update_user_id: userId,
+                            name: gcl.name, unit: gcl.unit, g_order: gcl.g_order, is_aux: gcl.is_aux,
+                            quantity: gcl.quantity, expr: gcl.expr,
+                            drawing_code: gcl.drawing_code, memo: gcl.memo,
+                        };
+                        if (defaultData) this.ctx.helper._.assignIn(newAncGcl, defaultData);
+                        pasteAncGclData.push(newAncGcl);
+                    }
+                }
                 pbd.push(newBills);
             }
             for (const d of pbd) {
@@ -692,6 +715,7 @@ class BaseBillsSerivce extends TreeService {
             if (pastePosData.length > 0) {
                 await this.transaction.insert(this.relaPosService.tableName, pastePosData);
             }
+            if (pasteAncGclData.length > 0 && this.relaAncGclService) await this.transaction.insert(this.relaAncGclService.tableName, pasteAncGclData);
             await this.transaction.commit();
         } catch (err) {
             await this.transaction.rollback();
@@ -700,9 +724,10 @@ class BaseBillsSerivce extends TreeService {
 
         // 查询应返回的结果
         const updateData = await this.getNextsData(selectData.tender_id, selectData.ledger_pid, selectData.order + pasteData.length);
+        const ancGcl = this.relaAncGclService ? { add: pasteAncGclData } : undefined;
         return {
             ledger: { create: pasteBillsData, update: updateData },
-            pos: pastePosData,
+            pos: pastePosData, ancGcl,
         };
     }
 

+ 39 - 1
app/public/js/ledger.js

@@ -420,7 +420,10 @@ $(document).ready(function() {
                 deleteAfterHint(function () {
                     postData(window.location.pathname + '/update', data, function (result) {
                         const refreshNode = tree.loadPostData(result);
-                        for (const d of refreshNode.delete) pos.removeDatasByMasterId(d.id);
+                        for (const d of refreshNode.delete) {
+                            pos.removeDatasByMasterId(d.id);
+                            ancGcl.removeDatasByMasterId(d.id);
+                        }
                         self.refreshTree(sheet, refreshNode);
                         self.refreshOperationValid(sheet);
                         posOperationObj.loadCurPosData();
@@ -890,6 +893,7 @@ $(document).ready(function() {
                 }
             }, function (data) {
                 pos.updateDatas(data.pos);
+                if (data.ancGcl) ancGcl.updateDatas(data.ancGcl);
                 const result = tree.loadPostData(data.ledger);
                 self.refreshTree(sheet, result);
                 sheet.setSelection(result.create[0].index, sel.col, sel.rowCount, sel.colCount);
@@ -1449,6 +1453,8 @@ $(document).ready(function() {
                 for (const b of cbl) {
                     const posRange = pos.getLedgerPos(b.id);
                     if (posRange && posRange.length > 0) b.pos = posRange;
+                    const gclRange = ancGcl.getPartData(b.id);
+                    if (gclRange && gclRange.length > 0) b.ancGcl = gclRange;
                 }
             }
             setLocalCache(copyBlockTag, JSON.stringify({block: copyBlockList}));
@@ -2681,11 +2687,33 @@ $(document).ready(function() {
                 SpreadJsObj.reLoadRowData(info.sheet, info.row);
             });
         },
+        buttonClicked: function (e, info) {
+            const setting = info.sheet.zh_setting;
+            if (!setting) return;
+
+            const node = SpreadJsObj.getSelectObject(info.sheet);
+            if (!node) {
+                toastr.warning('请先添加附属工程量再设置辅材');
+                SpreadJsObj.reLoadRowData(info.sheet, info.row);
+                return;
+            }
+
+            const col = setting.cols[info.col];
+            const updateData = { id: node.id };
+            updateData[col.field] = node[col.field] ? 0 : 1;
+            postData('/tender/' + getTenderId() + '/anc-gcl/update', { update: [updateData]}, function (result) {
+                ancGcl.updateDatas(result);
+                ancGclObj.loadCurAncillaryGcl();
+            }, function () {
+                SpreadJsObj.reLoadRowData(info.sheet, info.row);
+            });
+        },
     };
     SpreadJsObj.addDeleteBind(ancGclSpread, ancGclObj.deletePress);
     ancGclSpread.bind(spreadNS.Events.EditStarting, ancGclObj.editStarting);
     ancGclSpread.bind(spreadNS.Events.EditEnded, ancGclObj.editEnded);
     ancGclSpread.bind(spreadNS.Events.ClipboardPasting, ancGclObj.clipboardPasting);
+    ancGclSpread.bind(spreadNS.Events.ButtonClicked, ancGclObj.buttonClicked);
     $.contextMenu({
         selector: '#anc-gcl-spread',
         build: function ($trigger, e) {
@@ -2745,6 +2773,16 @@ $(document).ready(function() {
             },
         }
     });
+    $('#filter-anc-gcl').change(function() {
+        if (this.checked) {
+            const condition = {};
+            condition[this.getAttribute('name')] = parseInt(this.value);
+            ancGcl.filter = condition;
+        } else {
+            ancGcl.filter = null;
+        }
+        ancGclObj.loadCurAncillaryGcl();
+    });
 
     postData(window.location.pathname + '/load', {}, function (data) {
         ledgerTree.loadDatas(data.bills);

+ 20 - 0
app/public/js/path_tree.js

@@ -2088,6 +2088,18 @@ const createAncillaryGcl = function (setting) {
             }
         }
 
+        filterPart(partData) {
+            const check = this._filter;
+            partData.forEach(x => {
+                x.visible = true;
+                if (check) {
+                    for (const prop in check) {
+                        if (x[prop] !== check[prop]) x.visible = false;
+                    }
+                }
+            });
+        }
+
         /**
          * 加载数据
          * @param datas
@@ -2167,6 +2179,7 @@ const createAncillaryGcl = function (setting) {
             if (data.update) this._updateDatas(data.update, resort);
             for (const s of resort) {
                 this.resortPart(this.masterIndex[s]);
+                this.filterPart(this.masterIndex[s]);
             }
         }
 
@@ -2201,6 +2214,13 @@ const createAncillaryGcl = function (setting) {
                 this.resortPart(this.masterIndex[key]);
             }
         }
+
+        set filter(condition) {
+            this._filter = condition;
+            for (const key in this.masterIndex) {
+                this.filterPart(this.masterIndex[key]);
+            }
+        }
     }
 
     return new AncillaryGcl(setting);

+ 8 - 0
app/service/ancillary_gcl.js

@@ -35,10 +35,12 @@ module.exports = app => {
                     add_user_id: user_id, update_user_id: user_id,
                     lid: d.lid, g_order: d.g_order,
                 };
+                if (d.is_aux !== undefined) nd.is_aux = d.is_aux;
                 if (d.name) nd.name = d.name || '';
                 if (d.unit) nd.unit = d.unit || '';
                 if (d.quantity) nd.quantity = this.ctx.helper.round(d.quantity || 0, qtyDecimal);
                 if (d.expr) nd.expr = d.expr || '';
+                if (d.drawing_code !== undefined) nd.drawing_code = d.drawing_code;
                 if (d.memo) nd.memo = d.memo || '';
                 insertData.push(nd);
             }
@@ -96,11 +98,13 @@ module.exports = app => {
                 if (!od) continue;
 
                 const nd = { id: od.id, update_user_id: user_id };
+                if (d.is_aux !== undefined) nd.is_aux = d.is_aux;
                 if (d.name !== undefined) nd.name = d.name;
                 if (d.g_order !== undefined) nd.g_order = d.g_order;
                 if (d.unit !== undefined) nd.unit = d.unit;
                 if (d.quantity !== undefined) nd.quantity = this.ctx.helper.round(d.quantity, qtyDecimal);
                 if (d.expr !== undefined) nd.expr = d.expr || '';
+                if (d.drawing_code !== undefined) nd.drawing_code = d.drawing_code;
                 if (d.memo !== undefined) nd.memo = d.memo || '';
                 uDatas.push(nd);
             }
@@ -134,6 +138,10 @@ module.exports = app => {
                 }
             }
         }
+
+        async deletePartData(transaction, tid, lid) {
+            await transaction.delete(this.tableName, { tid: tid, lid: lid });
+        }
     }
 
     return AncillaryGcl;

+ 2 - 1
app/service/ledger.js

@@ -52,7 +52,7 @@ module.exports = app => {
                 fullPath: 'full_path',
                 keyPre: 'ledger_bills_maxLid:',
                 uuid: true,
-            }, 'pos');
+            }, 'pos', 'ancillaryGcl');
             this.depart = ctx.app.config.table_depart.heavy;
             this.tableName = 'ledger';
         }
@@ -283,6 +283,7 @@ module.exports = app => {
          */
         async _deleteRelaData(mid, deleteData) {
             await this.ctx.service.pos.deletePosData(this.transaction, mid, this._.map(deleteData, 'id'));
+            await this.ctx.service.ancillaryGcl.deletePartData(this.transaction, mid, this._.map(deleteData, 'id'));
         }
 
         _checkField(data, field) {