Browse Source

归档报表预付款树结构问题及加载

ellisran 10 months ago
parent
commit
e8dfe79640
3 changed files with 130 additions and 49 deletions
  1. 36 2
      app/public/report/js/rpt_archive.js
  2. 8 1
      app/service/advance.js
  3. 86 46
      app/view/report/index_archive.ejs

+ 36 - 2
app/public/report/js/rpt_archive.js

@@ -27,10 +27,42 @@ let rptArchiveObj = {
         for (let aItem of ARCHIVE_LIST) {
             archivedRptIds.push(parseInt(aItem.rpt_id));
         }
+        const _chkIfShouldFilter = function(rptItem, currentRptType = 'normal') {
+            let rst = (!(rptItem.released) && rptItem.nodeType === 2 || rptItem.hidden); //未发布判断 或 故意隐藏
+            if (!rst) {
+                // 根据当前业务类型判断及检测其他非同类报表,如动态决算类型、支付审批类型
+                switch(currentRptType) {
+                    case 'normal':
+                        // 检测:预付款
+                        if (CURRENT_SELECTED_BIZ_TYPE && CURRENT_SELECTED_BIZ_TYPE === 'change_prepay' && rptItem.nodeType === 2) {
+                            rst = true;
+                            if (rptItem.flags && rptItem.flags.rptTplType) {
+                                if (current_advance_id > 0) {
+                                    rst = !((rptItem.flags.rptTplType || '') === getAdvanceType2());
+                                }
+                            }
+                        }
+                        break;
+                    case 'juesuan':
+                        break;
+                    case 'zhifushenpi':
+                        break;
+                    default:
+                        break;
+                }
+            }
+            return rst;
+        };
         let private_remove_hide_item = function (items, nlv) {
             if (items && items.length > 0) {
                 for (let i = items.length - 1; i >= 0; i--) {
-                    if (!(items[i].released) && items[i].nodeType === 2) {
+                    // if (!(items[i].released) && items[i].nodeType === 2) {
+                    //     if (archivedRptIds.indexOf(items[i].refId) < 0) {
+                    //         // 备注:这里还要再判断是否存在已经归档的报表,如果有,需要保留。否则才真正剔除
+                    //         items.splice(i, 1);
+                    //     }
+                    // } else {
+                    if (_chkIfShouldFilter(items[i])) {
                         if (archivedRptIds.indexOf(items[i].refId) < 0) {
                             // 备注:这里还要再判断是否存在已经归档的报表,如果有,需要保留。否则才真正剔除
                             items.splice(i, 1);
@@ -1009,7 +1041,9 @@ let rptArchiveObj = {
         }
     }
 };
-
+function getAdvanceType2() {
+    return current_advance_type !== -1 ? ('tplType_prePay' + (current_advance_type + 1)) : '';
+}
 /**
  * 获取 blob
  * @param  {String} url 目标文件地址

+ 8 - 1
app/service/advance.js

@@ -1,6 +1,7 @@
 'use strict';
 
 const auditConst = require('../const/audit').advance;
+const advanceConst = require('../const/advance');
 const path = require('path');
 const fs = require('fs');
 
@@ -274,7 +275,13 @@ module.exports = app => {
                 ' c.tid = ? AND c.id in (' + this.ctx.helper.getInArrStrSqlFilter(ids) + ') AND c.status = ? ORDER BY ca.end_time DESC';
             const params = [this.tableName, this.ctx.service.advanceAudit.tableName, tid, tid, auditConst.status.checked];
             const list = await this.db.query(sql, params);
-            return list;
+            // 再按预付款顺序再进行一次排列
+            const advances = [];
+            for (const tc of advanceConst.typeCol) {
+                const typeList = list.filter(item => item.type === tc.type);
+                advances.push(...typeList);
+            }
+            return advances;
         }
     }
     return Advance;

+ 86 - 46
app/view/report/index_archive.ejs

@@ -83,12 +83,8 @@
                 </div>
                 <div class="d-inline-block">
                     <div class="dropdown" style="display: none" id="divSelectableAdvances">
-                        <button class="btn btn-sm btn-light dropdown-toggle text-primary" type="button" id="btnCurrentAdvance" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><%- advanceConst.typeCol[0].name %></button>
-                        <div class="dropdown-menu" aria-labelledby="allPrepayButton" id="optionSelectableAdvances">
-                            <% for (const type of advanceConst.typeCol) { %>
-                            <a class="dropdown-item" href="javascript:void(0);" data-type="<%- type.key %>" <% if (type.value === 0) { %>style="display: none"<% } %>><%- type.name %></a>
-                            <% } %>
-                        </div>
+                        <button class="btn btn-sm btn-light dropdown-toggle text-primary" type="button" id="btnCurrentAdvance" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"></button>
+                        <div class="dropdown-menu" aria-labelledby="allPrepayButton" id="optionSelectableAdvances"></div>
                     </div>
                 </div>
                 <div class="d-inline-block">
@@ -271,10 +267,13 @@
     let CHANGE_LIST = [], current_change_id = -1, current_change_code = '';
     let CHANGE_ID = -1, BUSINESS_ID = -1;
     let current_advance_id = -1;  // 预付款期id
+    let current_advance_type = -1;// 预付款报表类型
     let current_material_id = -1; // 材差期id
     let current_material_order = -1; // 材差期order
     let ADVANCE_LIST = [];
     let MATERIAL_LIST = [];
+    let CURRENT_SELECTED_BIZ_TYPE = '';
+    const ADVANCE_TYPECOL = JSON.parse(unescape('<%- escape(JSON.stringify(advanceConst.typeCol)) %>'));
 
     const FOLDER_SEPERATER = '->';
 
@@ -426,27 +425,85 @@
         // }
     }
 
-    function buildAdvancePaySelection(adList) {
+    function buildAdvanceSelection() {
+        $('#optionSelectableAdvances').html('');
+        $("#btnCurrentAdvance")[0].innerText = '';
+        const advanceCols = [];
+        for (const advance of ADVANCE_LIST) {
+            if (advanceCols.indexOf(advance.type) === -1) {
+                advanceCols.push(advance.type);
+            }
+        }
+        for (const advanceAdj of ADVANCE_TYPECOL) {
+            const ad = _.includes(advanceCols, advanceAdj.type);
+            if (ad) {
+                let dispStr = '';
+                if (current_advance_type === -1 || current_advance_type === advanceAdj.type) {
+                    current_advance_type = advanceAdj.type;
+                    current_advance_id = -1;
+                    $("#btnCurrentAdvance")[0].innerText = advanceAdj.name;
+                    dispStr = ';display:none';
+                }
+                const str = `<a class="dropdown-item" style="cursor:pointer${dispStr}" onclick="changeCurrentAdvance(this)" data-type = "${advanceAdj.type}">${advanceAdj.name}</a>`;
+                $("#optionSelectableAdvances").append(str);
+            }
+        }
+        buildAdvancePaySelection(current_advance_type, true);
+    }
+
+    function changeCurrentAdvance(ele) {
+        $('#optionSelectableAdvances a').show();
+        $(ele).hide();
+        current_advance_type = +ele.attributes[3].value;
+        $('#optionSelectableAdvances').siblings('button').text($(ele).text());
+        // BUSINESS_ID = material_id;
+        buildAdvanceSelection();
+    }
+
+    function buildAdvancePaySelection(current_advance_type, needClick = false) {
         $("#optionSelectableAdvancePays").empty();
         $("#btnCurrentAdvancePay")[0].innerText = '';
-        let hasMatch = false;
-        if (current_advance_id !== -1) {}
+        const adList = _.orderBy(_.filter(ADVANCE_LIST, { type: current_advance_type }), ['order'], ['desc']);
         for (const advance of adList) {
-            if (current_advance_id === advance.id) {
-                hasMatch = true; // 预付款有好几种类型,需要考虑不同类型的转换检测
-                break;
-            }
-        }
-        adList.forEach((advance, adIndex) => {
             let dispStr = '';
-            if (!hasMatch && adIndex === 0 || current_advance_id === advance.id) {
+            if (current_advance_id === -1 || current_advance_id === advance.id) {
                 current_advance_id = advance.id;
-                $("#btnCurrentAdvancePay")[0].innerText = `第${adIndex + 1}期`;
+                $("#btnCurrentAdvancePay")[0].innerText = `第${advance.order}期`;
                 dispStr = ';display:none';
             }
-            const str = `<a class="dropdown-item" style="cursor:pointer${dispStr}" onclick="changeCurrentAdvance(this)" advance_id = "${advance.id}">第${adIndex + 1}期</a>`;
+            const str = `<a class="dropdown-item" style="cursor:pointer${dispStr}" onclick="changeCurrentAdvancePays(this)" advance_id = "${advance.id}">第${advance.order}期</a>`;
             $("#optionSelectableAdvancePays").append(str);
-        });
+        }
+        if (needClick) {
+            changeCurrentAdvancePays($("#optionSelectableAdvancePays a")[0]);
+        }
+    }
+
+    function changeCurrentAdvancePays(ele) {
+        $('#optionSelectableAdvancePays a').show();
+        $(ele).hide();
+        current_advance_id = +ele.attributes[3].value;
+        $('#optionSelectableAdvancePays').siblings('button').text($(ele).text());
+        // BUSINESS_ID = material_id;
+        buildAdvancePaySelection(current_advance_type);
+        //还有必要触发归档报表刷新!
+        //rptArchiveObj.onClick(null, null, rptArchiveObj.currentNode);
+        const params = {tenderId: TENDER_ID, business_type, bzId: current_advance_id};
+        $.bootstrapLoading.start();
+        CommonAjax.postXsrfEx("/tender/report_api/getReportArchive4bz", params, 10000, true, getCookie('csrfToken_j'),
+            function(result){
+                $.bootstrapLoading.end();
+                ARCHIVE_LIST = result.data;
+                ARCHIVE_ENCRYPTION_LIST = result.encryptionData;
+                TOP_TREE_NODES = JSON.parse(JSON.stringify(result.rpt_tpl_data));
+                buildTplTree();
+                rptArchiveObj.iniPage();
+            }, function(err){
+                $.bootstrapLoading.end();
+            }, function(ex){
+                $.bootstrapLoading.end();
+            }
+        );
     }
 
     function buildMaterialSelection() {
@@ -632,27 +689,6 @@
             }
         });
 
-        function advancePayClick(ele = null) {
-            $('#optionSelectableAdvances a').show();
-            const thisEle = ele === null ? this : ele;
-            $(thisEle).hide();
-            $('#optionSelectableAdvances').siblings('button').text($(thisEle).text());
-            const type = $(thisEle).data('type');
-            const typeStr = ['start', 'material', 'safe', 'dust'];
-            const tIdx = typeStr.indexOf(type)
-            const adList = [];
-            ADVANCE_LIST.forEach(advance => {
-                if (advance.type === tIdx) {
-                    adList.push(advance);
-                }
-            });
-            buildAdvancePaySelection(adList);
-        }
-
-        $('#optionSelectableAdvances a').on('click', function (){
-            advancePayClick(this);
-        });
-
         $('#select-item a').on('click', function () {
            $('#select-item a').show();
            $(this).hide();
@@ -661,6 +697,8 @@
            business_type = type;
            CHANGE_ID = -1;
            BUSINESS_ID = -1;
+           current_advance_type = -1;
+           CURRENT_SELECTED_BIZ_TYPE = '';
            if (type === 'stage') {
                $('#divSelectableStages').show();
                $('#divSelectableChanges').hide();
@@ -682,6 +720,7 @@
                //rptArchiveObj.onClick(null, null, rptArchiveObj.currentNode);
                const params = {prjId: PROJECT_ID, stgId: current_stage_id};
                $.bootstrapLoading.start();
+               ARCHIVE_LIST = [];
                CommonAjax.postXsrfEx("/tender/report_api/getReportArchive", params, 10000, true, getCookie('csrfToken_j'),
                    function(result){
                        $.bootstrapLoading.end();
@@ -698,7 +737,7 @@
                        $.bootstrapLoading.end();
                    }
                );
-           } else if (_.indexOf(type, 'change') !== -1) {
+           } else if (_.includes(type, 'change')) {
                $('#divSelectableStages').hide();
                $('#divSelectableAdvances').hide();
                $('#divSelectableAdvancePays').hide();
@@ -708,7 +747,7 @@
                //rptArchiveObj.onClick(null, null, rptArchiveObj.currentNode);
                const params = {tenderId: TENDER_ID, business_type: type};
                $.bootstrapLoading.start();
-               // ARCHIVE_LIST = [];
+               ARCHIVE_LIST = [];
                // ARCHIVE_ENCRYPTION_LIST = [];
                // TOP_TREE_NODES = JSON.parse(JSON.stringify(ORG_TOP_TREE_NODES));
                // rptArchiveObj.iniPage();
@@ -735,6 +774,7 @@
                    }
                );
            } else if (type === 'advance') {
+               CURRENT_SELECTED_BIZ_TYPE = 'change_prepay'
                $('#divSelectableStages').hide();
                $('#divSelectableChanges').hide();
                $('#divSelectableAdvances').show();
@@ -744,7 +784,7 @@
                //rptArchiveObj.onClick(null, null, rptArchiveObj.currentNode);
                const params = {tenderId: TENDER_ID, business_type: type};
                $.bootstrapLoading.start();
-               // ARCHIVE_LIST = [];
+               ARCHIVE_LIST = [];
                // ARCHIVE_ENCRYPTION_LIST = [];
                // TOP_TREE_NODES = JSON.parse(JSON.stringify(ORG_TOP_TREE_NODES));
                // rptArchiveObj.iniPage();
@@ -755,10 +795,10 @@
                        ARCHIVE_LIST = result.data;
                        ARCHIVE_ENCRYPTION_LIST = result.encryptionData;
                        ADVANCE_LIST = result.changes;
-                       current_advance_id = ADVANCE_LIST.length > 0 ? ADVANCE_LIST[0].id : -1;
+                       // current_advance_id = ADVANCE_LIST.length > 0 ? ADVANCE_LIST[0].id : -1;
                        TOP_TREE_NODES = JSON.parse(JSON.stringify(result.rpt_tpl_data));
                        BUSINESS_ID = ADVANCE_LIST.length > 0 ? ADVANCE_LIST[0].id : -1;
-                       advancePayClick( $('#optionSelectableAdvances a')[0]);
+                       buildAdvanceSelection();
                        buildTplTree();
                        rptArchiveObj.iniPage();
                        current_stage_id = result.stgId;
@@ -778,7 +818,7 @@
                //rptArchiveObj.onClick(null, null, rptArchiveObj.currentNode);
                const params = {tenderId: TENDER_ID, business_type: type};
                $.bootstrapLoading.start();
-               // ARCHIVE_LIST = [];
+               ARCHIVE_LIST = [];
                // ARCHIVE_ENCRYPTION_LIST = [];
                // TOP_TREE_NODES = JSON.parse(JSON.stringify(ORG_TOP_TREE_NODES));
                // rptArchiveObj.iniPage();