MaiXinRong 5 years ago
parent
commit
517dc169b7
1 changed files with 95 additions and 0 deletions
  1. 95 0
      app/public/js/shares/tenders2tree.js

+ 95 - 0
app/public/js/shares/tenders2tree.js

@@ -0,0 +1,95 @@
+'use strict';
+
+/**
+ *
+ *
+ * @author Mai
+ * @date
+ * @version
+ */
+
+const Tender2Tree = (function () {
+    const treeSetting = {
+        id: 'tmt_id',
+        pid: 'tmt_pid',
+        order: 'order',
+        level: 'level',
+        rootId: -1,
+        fullPath: 'full_path',
+    };
+    const tenderTree = createNewPathTree('gather', treeSetting);
+
+    // 查询方法
+    function findNode (key, value, arr) {
+        for (const a of arr) {
+            if (a[key] && a[key] === value) {
+                return a;
+            }
+        }
+    }
+
+    function findCategoryTreeNode(cid, value, array) {
+        for (const a of array) {
+            if (a.cid === cid && a.vid === value) {
+                return a;
+            }
+        }
+    }
+
+    function getCategoryTreeNode (category, value, parent) {
+        const array = parent ?  parent.children : tenderTree.children;
+        let cate = findCategoryTreeNode(category.id, value, array);
+        if (!cate) {
+            const cateValue = findNode('id', value, category.value);
+            if (!cateValue) return null;
+
+            cate = tenderTree.addNode({
+                cid: category.id,
+                vid: value,
+                name: cateValue.value,
+            }, parent);
+        }
+        return cate;
+    }
+
+    function loadCategoryTreeNode ( tender, levelCate) {
+        let tenderCategory = null;
+        for (const [i, lc] of levelCate.entries()) {
+            const tenderCate = findNode('cid', lc.id, tender.category);
+
+            if (tenderCate) {
+                tenderCategory = getCategoryTreeNode(lc, tenderCate.value, tenderCategory);
+            } else {
+                if (i === 0 && tender.category) {
+                    for (const [j, c] of tender.category.entries()) {
+                        const cate = findNode('id', c.cid, category);
+                        tenderCategory = getCategoryTreeNode(cate, c.value, tenderCategory);
+                    }
+                }
+                return tenderCategory;
+            }
+        }
+        return tenderCategory;
+    }
+
+    function convert (category, tenders) {
+        tenderTree.clearDatas();
+
+        const levelCategory = category.filter(function (c) {
+            return c.level && c.level > 0;
+        });
+
+        for (const t of tenders) {
+            const parent = (t.category && levelCategory.length > 0) ? loadCategoryTreeNode(t, levelCategory) : null;
+            tenderTree.addNode({
+                tid: t.id,
+                name: t.name,
+                phase: t.lastStage ? '第' + t.lastStage.order + '期' : '台账',
+                //status: node.lastStage ? auditConst.stage.statusString[node.lastStage.status] : auditConst.ledger.statusString[node.ledger_status]
+            }, parent);
+        }
+        tenderTree.sortTreeNode(false);
+        return tenderTree;
+    }
+    return { convert }
+})();