浏览代码

code sync for stage check

TonyKang 5 年之前
父节点
当前提交
a8af6c2da8
共有 4 个文件被更改,包括 75 次插入133 次删除
  1. 5 0
      app/controller/report_controller.js
  2. 1 1
      app/public/report/js/rpt_main.js
  3. 56 125
      app/reports/public/treeUtil.js
  4. 13 7
      app/view/report/index.ejs

+ 5 - 0
app/controller/report_controller.js

@@ -30,6 +30,7 @@ module.exports = app => {
                 // console.log(tender.info);
                 let stage_id = -1;
                 let stage_order = -1;
+                let sorder = -1;
                 let stage_times = -1;
                 let stage_status = -1;
                 const treeNodes = await ctx.service.rptTreeNode.getNodesByProjectId([-1, tender.data.project_id]);
@@ -42,6 +43,7 @@ module.exports = app => {
                 if (stage !== null && stage !== undefined) {
                     stage_id = stage.id;
                     stage_order = stage.order;
+                    sorder = stage.curOrder;
                     stage_times = stage.times;
                     stage_status = stage.status;
                 }
@@ -58,6 +60,7 @@ module.exports = app => {
                     tender_name: tender.data.name,
                     stg_id: stage_id,
                     stg_order: stage_order,
+                    cur_order: sorder,
                     stg_times: stage_times,
                     stg_status: stage_status,
                     stage_list: JSON.stringify(stageList),
@@ -320,6 +323,8 @@ async function getReportData(ctx, params, filters) {
                     break;
                 case 'stage_pay':
                     runnableRst.push(ctx.service.stagePay.getAuditorStageData(params.stage_id, params.stage_times, params.stage_order));
+                    // console.log('params:');
+                    // console.log(params);
                     runnableKey.push('stage_pay');
                     break;
                 case 'mem_stage_im_zl':

+ 1 - 1
app/public/report/js/rpt_main.js

@@ -712,7 +712,7 @@ function getStageId() {
 }
 
 function getStageOrder() {
-    return current_stage_order;
+    return CUR_ORDER;
 }
 
 function getStageTimes() {

+ 56 - 125
app/reports/public/treeUtil.js

@@ -1,165 +1,96 @@
+'use strict';
+
 /**
  * Created by Tony on 2017/3/14.
  */
 
-// import fs from 'fs';
-//
-// function getTreeNodeUtil() {
-//     let tmpRst = null;
-//     let data = fs.readFileSync(__dirname + '/web/treeDataHelper.js', 'utf8', 'r');
-//     //console.log(data);
-//     eval(data + ' ; tmpRst = tree_Data_Helper; ');
-//     return tmpRst;
-// }
-//
-// const treeNodeUtil = getTreeNodeUtil();
-
+const NODE_ID = 'ledger_id';
+const P_ID = 'ledger_pid';
+const NEXT_ID = 'NextSiblingID';
+const ADHOC_PRE_ID = 'Previous_ID';
+const ORDER_ID = 'order';
+const CHILDREN_NODE = 'items';
+const SUB_ID = 'sub_ids';
+const EMPTY_ID_VAL = -1;
+const TREE_LEVEL = 'treeLevel';
+const TOP_BILL_ID = 'topBillID';
+const TREE_FLAT_SERIAL_ORDER = 'treeFlatSerialOrder';
 
-const NODE_ID = "ID", P_ID = "ParentID", NEXT_ID = "NextSiblingID", ADHOC_PRE_ID="Previous_ID", CHILDREN_NODE = "items", SUB_ID = "sub_ids",
-    EMPTY_ID_VAL = -1, TREE_LEVEL = 'treeLevel', TOP_BILL_ID = "topBillID", TREE_FLAT_SERIAL_ORDER = "treeFlatSerialOrder";
+function sortOder(item1, item2) {
+    return parseInt(item1[ORDER_ID]) - parseInt(item2[ORDER_ID]);
+}
 
-let tree_Data_Helper = {
+const tree_Data_Helper = {
     buildTreeNodeDirectly: function(data, addLevel) {
-        let topArr = [], rst = [], tmpNodes = {}, prefix = "id_";
-        let private_getStartNode = function (idArr) {
-            let tmpNodeRst = null;
-            for (let i = 0; i < idArr.length; i++) {
-                if (parseInt(tmpNodes[prefix + idArr[i]][ADHOC_PRE_ID]) === EMPTY_ID_VAL) {
-                    tmpNodeRst = tmpNodes[prefix + idArr[i]];
-                    break;
-                }
-            }
-            return tmpNodeRst;
-        };
-        let private_buildNodeData = function(parentItem, idArr, treeLevel, tbID) {
-            let iter = [], nextNode = private_getStartNode(idArr), pushedIds = [];
-            while (nextNode !== null && nextNode !== undefined ) {
-                if (parentItem) {
-                    parentItem[CHILDREN_NODE].push(nextNode);
-                } else {
-                    rst.push(nextNode);
-                }
-                iter.push(nextNode);
-                pushedIds.push(nextNode[NODE_ID]);
-                nextNode[TOP_BILL_ID] = tbID;
-                if (parentItem === null) {
-                    nextNode[TOP_BILL_ID] = nextNode[NODE_ID];
-                    if (nextNode.flags && nextNode.flags.length > 0) {
-                        for (let flag of nextNode.flags) {
-                            if (flag.fieldName === "fixed") {
-                                nextNode[TOP_BILL_ID] = flag.flag;
-                                break;
-                            }
-                        }
-                    }
-                }
-                if (addLevel) nextNode[TREE_LEVEL] = treeLevel;
-                nextNode = tmpNodes[prefix + nextNode[NEXT_ID]];
-                if (nextNode === null || nextNode === undefined) {
-                    //备注: 考虑到实际数据的健壮性,有些节点会掉链子,需要用 parentItem[SUB_ID] 比对已经加上的节点,如发现加上的节点数量不够,那就得在这里补充上去
-                    if (parentItem) {
-                        if (parentItem[SUB_ID].length > iter.length) {
-                            for (let subId of parentItem[SUB_ID]) {
-                                if (pushedIds.indexOf(subId) < 0) {
-                                    let restNode = tmpNodes[prefix + subId];
-                                    if (addLevel) restNode[TREE_LEVEL] = treeLevel;
-                                    restNode[TOP_BILL_ID] = tbID;
-                                    parentItem[CHILDREN_NODE].push(restNode);
-                                    iter.push(restNode);
-                                }
-                            }
-                        }
-                    } else {
-                        if (idArr.length > iter.length) {
-                            for (let topId of idArr) {
-                                if (pushedIds.indexOf(topId) < 0) {
-                                    let restNode = tmpNodes[prefix + topId];
-                                    if (addLevel) restNode[TREE_LEVEL] = treeLevel;
-                                    restNode[TOP_BILL_ID] = restNode[NODE_ID];
-                                    if (restNode.flags && restNode.flags.length > 0) {
-                                        for (let flag of restNode.flags) {
-                                            if (flag.fieldName === "fixed") {
-                                                restNode[TOP_BILL_ID] = flag.flag;
-                                                break;
-                                            }
-                                        }
-                                    }
-                                    rst.push(restNode);
-                                    iter.push(restNode);
-                                }
-                            }
-                        }
-                    }
-                }
+        const topArr = [];
+        const rst = [];
+        const nodeCache = {};
+        const prefix = 'id_';
+        const private_buildNodeData = function(node, treeLevel, tbID) {
+            const stbID = (tbID === -1) ? node[NODE_ID] : tbID;
+            node[TOP_BILL_ID] = stbID;
+            if (addLevel) {
+                node[TREE_LEVEL] = treeLevel;
             }
-            pushedIds = [];
-            for (let i = 0; i < iter.length; i++) {
-                let rtbID = tbID;
-                if (parentItem === null) {
-                    rtbID = iter[i][TOP_BILL_ID];
+            if (node[CHILDREN_NODE].length > 0) {
+                node[CHILDREN_NODE].sort(sortOder);
+                for (const subNode of node[CHILDREN_NODE]) {
+                    private_buildNodeData(subNode, treeLevel + 1, tbID);
                 }
-                private_buildNodeData(iter[i], iter[i][SUB_ID], (treeLevel + 1), rtbID);
             }
         };
-        //1. 给每个节点设置key, 顺便找Top Node
+        // 1. 给每个节点设置key, 顺便找Top Node
         for (let i = 0; i < data.length; i++) {
-            tmpNodes[prefix + data[i][NODE_ID]] = data[i];
-            data[i][ADHOC_PRE_ID] = EMPTY_ID_VAL;
-            data[i][SUB_ID] = [];
+            nodeCache[prefix + data[i][NODE_ID]] = data[i];
             data[i][CHILDREN_NODE] = [];
             if (parseInt(data[i][P_ID]) === EMPTY_ID_VAL) {
-                topArr.push(data[i][NODE_ID]);
+                topArr.push(data[i]);
             }
         }
-        //2. 通过key,设置好兄弟/父子关系
+        // 2. 通过key,设置父子关系,然后通过order来排序
         for (let psi = 0; psi < data.length; psi++) {
-            if (parseInt(data[psi][NEXT_ID]) !== EMPTY_ID_VAL) {
-                if (tmpNodes[prefix + data[psi][NEXT_ID]] !== undefined){
-                    if (tmpNodes[prefix + data[psi][NEXT_ID]][P_ID] === data[psi][P_ID]) {
-                        tmpNodes[prefix + data[psi][NEXT_ID]][ADHOC_PRE_ID] = data[psi][NODE_ID];
-                    } else {
-                        tmpNodes[prefix + data[psi][NEXT_ID]][ADHOC_PRE_ID] = EMPTY_ID_VAL;
-                        data[psi][NEXT_ID] = EMPTY_ID_VAL;
-                    }
-                }
-            }
             if (parseInt(data[psi][P_ID]) !== EMPTY_ID_VAL) {
-                tmpNodes[prefix + data[psi][P_ID]][SUB_ID].push(data[psi][NODE_ID]);
+                const pNode = nodeCache[prefix + data[psi][P_ID]];
+                if (pNode) {
+                    pNode[CHILDREN_NODE].push(data[psi]);
+                } else {
+                    console.log('warning: no parent node was found!');
+                }
             }
         }
-        //3. 开build
-        private_buildNodeData(null, topArr, 0, -1);
-        //try to release and return
-        tmpNodes = null;
+        // 3. 开build
+        topArr.sort(sortOder);
+        for (const topNode of topArr) {
+            private_buildNodeData(topNode, 0, -1);
+        }
+        // try to release and return
+        // nodeCache = null;
         topArr.length = 0;
         return rst;
     },
 
-    getFlatArray: function (srcArr, destArr, addSerialOrder) {
+    getFlatArray: function(srcArr, destArr, addSerialOrder) {
         let serialStartOrder = 0;
-        let private_put = function (parentItem) {
+        const private_put = function(parentItem) {
             if (addSerialOrder) {
                 parentItem[TREE_FLAT_SERIAL_ORDER] = serialStartOrder;
                 serialStartOrder++;
-                //说明:当清单通过树排序后,为了后续的排序方便,有必要加这个序号,并作为指标提供
+                // 说明:当清单通过树排序后,为了后续的排序方便,有必要加这个序号,并作为指标提供
             }
             destArr.push(parentItem);
-            if (parentItem.items) {
-                for (let subItem of parentItem.items) {
+            if (parentItem[CHILDREN_NODE]) {
+                for (const subItem of parentItem[CHILDREN_NODE]) {
                     private_put(subItem);
                 }
             }
         }
-        for (let node of srcArr) {
+        for (const node of srcArr) {
             private_put(node);
         }
-        for (let item of destArr) {
+        for (const item of destArr) {
             delete item[CHILDREN_NODE];
-            delete item[SUB_ID];
-            delete item[ADHOC_PRE_ID];
         }
-    }
+    },
 };
 
-
-module.exports = tree_Data_Helper;
+module.exports = tree_Data_Helper;

+ 13 - 7
app/view/report/index.ejs

@@ -206,6 +206,7 @@
     const TENDER_NAME = '<%- tender_name %>';
     const STAGE_ID = <%- stg_id %>;
     const STAGE_ORDER = <%- stg_order %>;
+    const CUR_ORDER = <%- cur_order %>;
     const STAGE_TIMES = <%- stg_times %>;
     const STAGE_LIST = <%- stage_list %>;
     const PRJ_ACCOUNT_LIST = <%- prj_account_list %>;
@@ -310,13 +311,18 @@
     }
 
     function buildStageSelection() {
-        $("#btnCurrentStage")[0].innerText = '第' + current_stage_order + '期';
-        $("#optionSelectableStages").empty();
-        if (STAGE_LIST.length > 0) {
-            for (let i = STAGE_LIST.length; i > 0; i--) {
-                if (parseInt(STAGE_LIST[i - 1].order) !== current_stage_order) {
-                    const str = '<a class="dropdown-item" style="cursor:pointer" onclick="changeCurrentStage(this)" stg_id = "' + STAGE_LIST[i - 1].id + '" stg_order="' + STAGE_LIST[i - 1].order + '">第' + STAGE_LIST[i - 1].order + '期</a>';
-                    $("#optionSelectableStages").append(str);
+        if (STAGE_LIST.length === 0) {
+            $("#optionSelectableStages")[0].style.display = 'none';
+        } else {
+            $("#optionSelectableStages")[0].style.display = '';
+            $("#btnCurrentStage")[0].innerText = '第' + current_stage_order + '期';
+            $("#optionSelectableStages").empty();
+            if (STAGE_LIST.length > 0) {
+                for (let i = STAGE_LIST.length; i > 0; i--) {
+                    if (parseInt(STAGE_LIST[i - 1].order) !== current_stage_order) {
+                        const str = '<a class="dropdown-item" style="cursor:pointer" onclick="changeCurrentStage(this)" stg_id = "' + STAGE_LIST[i - 1].id + '" stg_order="' + STAGE_LIST[i - 1].order + '">第' + STAGE_LIST[i - 1].order + '期</a>';
+                        $("#optionSelectableStages").append(str);
+                    }
                 }
             }
         }