Browse Source

期,部位台账,过滤数据相关

MaiXinRong 5 years atrás
parent
commit
ddd4657d6b

+ 2 - 1
app/controller/stage_controller.js

@@ -1156,12 +1156,13 @@ module.exports = app => {
 
         async loadBwtz(ctx) {
             try {
+                const data = ctx.request.body.data ? JSON.parse(ctx.request.body.data) : {};
                 const ledgerData = await this._getStageLedgerData(ctx);
                 const posData = await this._getStagePosData(ctx);
                 const changeData = await this._getStageChangeData(ctx);
                 const convert = new billsPosConvert(ctx);
                 convert.loadData(ledgerData, posData, changeData);
-                const result = convert.convert();
+                const result = convert.convert(data.filter);
                 // const wbsCodeHis = await ctx.service.externalData.getExValue(ctx.tender.id, -1,
                 //     externalDataConst.FuLong.exType, externalDataConst.FuLong.exFields.wbsCode) || [];
                 // const [result, needUpdate] = convert.convertByWbsCode(wbsCodeHis);

+ 26 - 5
app/lib/bills_pos_convert.js

@@ -312,22 +312,43 @@ class BillsPosConvert {
         return needUpdate;
     }
 
-    _getResultData() {
-        const result = this.resultTree.getDefaultDatas();
+    _getResultData(filterFun) {
+        const result = this.resultTree.getDefaultDatas(filterFun);
         for (const r of result) {
             if (r.unitTree) {
-                r.unitTreeData = r.unitTree.getDefaultDatas();
+                r.unitTreeData = r.unitTree.getDefaultDatas(filterFun);
                 delete r.unitTree;
             }
         }
         return result;
     }
     // 转换数据
-    convert() {
+    convert(filter) {
         this._recursiveConvertNode(this.bpcTree.children);
         this._calculateAndSortResult();
         this._generateCodeByWbsCode([]);
-        return this._getResultData();
+        switch (filter) {
+            case 'cur':
+                return this._getResultData(function (node) {
+                    for (const field of ['contract_tp', 'qc_tp', 'gather_tp']) {
+                        if (node[field]) {
+                            return false;
+                        }
+                    }
+                    return true;
+                });
+            case 'end':
+                return this._getResultData(function (node) {
+                    for (const field of ['end_contract_tp', 'end_qc_tp', 'end_gather_tp']) {
+                        if (node[field]) {
+                            return false;
+                        }
+                    }
+                    return true;
+                });
+            default:
+                return this._getResultData();
+        }
     }
 
     /**

+ 6 - 3
app/lib/ledger.js

@@ -189,9 +189,12 @@ class baseTree {
      * @param fields
      * @returns {Array}
      */
-    getDatasWithout (fields) {
+    getDatasWithout (fields, filter) {
         const datas = [];
         for (const node of this.nodes) {
+            if (filter && filter(node)) {
+                continue;
+            }
             if (node.b_code && node.b_code !== '') node.chapter = this.ctx.helper.getChapterCode(node.b_code);
             const data = {};
             for (const field in node) {
@@ -207,8 +210,8 @@ class baseTree {
      * 获取默认数据 剔除一些树结构需要的缓存数据
      * @returns {Array}
      */
-    getDefaultDatas() {
-        return this.getDatasWithout(['expanded', 'visible', 'children', 'index']);
+    getDefaultDatas(filter) {
+        return this.getDatasWithout(['expanded', 'visible', 'children', 'index'], filter);
     }
 
     _mapTreeNode () {

+ 38 - 20
app/public/js/stage_bwtz.js

@@ -33,27 +33,29 @@ $(document).ready(() => {
     xmjSpread.bind(spreadNS.Events.SelectionChanged, function (e, info) {
         unitTreeObj.loadCurUnitData();
     });
-
-    postData(window.location.pathname + '/load', {}, function (result) {
-        const setting = {
-            id: 'ledger_id',
-            pid: 'ledger_pid',
-            order: 'order',
-            level: 'level',
-            rootId: -1,
-            fullPath: 'full_path',
-        };
-        const xmjTree = createNewPathTree('base', setting);
-        xmjTree.loadDatas(result);
-        for (const n of xmjTree.nodes) {
-            if (n.unitTreeData) {
-                n.unitTree = createNewPathTree('base', setting);
-                n.unitTree.loadDatas(n.unitTreeData);
+    const loadData = function (dataType) {
+        postData(window.location.pathname + '/load', {filter: dataType}, function (result) {
+            const setting = {
+                id: 'ledger_id',
+                pid: 'ledger_pid',
+                order: 'order',
+                level: 'level',
+                rootId: -1,
+                fullPath: 'full_path',
+            };
+            const xmjTree = createNewPathTree('base', setting);
+            xmjTree.loadDatas(result);
+            for (const n of xmjTree.nodes) {
+                if (n.unitTreeData) {
+                    n.unitTree = createNewPathTree('base', setting);
+                    n.unitTree.loadDatas(n.unitTreeData);
+                }
             }
-        }
-        SpreadJsObj.loadSheetData(xmjSheet, SpreadJsObj.DataType.Tree, xmjTree);
-        unitTreeObj.loadCurUnitData();
-    });
+            SpreadJsObj.loadSheetData(xmjSheet, SpreadJsObj.DataType.Tree, xmjTree);
+            unitTreeObj.loadCurUnitData();
+        });
+    };
+    loadData('all');
 
     $.subMenu({
         menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
@@ -102,7 +104,23 @@ $(document).ready(() => {
                     tree.expandByCustom(() => { return true; });
                     SpreadJsObj.refreshTreeRowVisible(sheet);
                     break;
+                case "curMeasure":
+                    tree.expandByCustom(function (node) {
+                        for (const field of ['contract_tp', 'qc_tp', 'gather_tp']) {
+                            if (node[field]) {
+                                return true;
+                            }
+                        }
+                        return false;
+                    });
+                    SpreadJsObj.refreshTreeRowVisible(sheet);
+                    break;
             }
         });
     })('a[name=showLevel]', xmjSheet);
+    // 过滤数据
+    $('a[name=load-data]').click(function () {
+        const tag = $(this).attr('tag');
+        loadData(tag);
+    });
 });

+ 13 - 0
app/view/stage/bwtz.ejs

@@ -16,6 +16,19 @@
                             <a class="dropdown-item" name="showLevel" tag="4" href="javascirpt: void(0);">第四层</a>
                             <a class="dropdown-item" name="showLevel" tag="5" href="javascirpt: void(0);">第五层</a>
                             <a class="dropdown-item" name="showLevel" tag="last" href="javascirpt: void(0);">最底层</a>
+                            <!--<a class="dropdown-item" name="showLevel" tag="curMeasure" href="javascirpt: void(0);">只显示本期计量</a>-->
+                        </div>
+                    </div>
+                </div>
+                <div class="d-inline-block">
+                    <div class="dropdown">
+                        <button class="btn btn-sm btn-light dropdown-toggle text-primary" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
+                            <i class="fa fa-list-ol"></i> 过滤数据
+                        </button>
+                        <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
+                            <a class="dropdown-item" href="javascirpt: void(0);" name="load-data" tag="cur">本期</a>
+                            <a class="dropdown-item" href="javascirpt: void(0);" name="load-data" tag="end">截止本期</a>
+                            <a class="dropdown-item" href="javascirpt: void(0);" name="load-data" tag="all">显示全部</a>
                         </div>
                     </div>
                 </div>