瀏覽代碼

fix: 清单分类算法,要考虑父、祖...非必填,子项必填的情况

vian 3 年之前
父節點
當前提交
298a56ca6a

+ 9 - 6
modules/std_billsGuidance_lib/facade/facades.js

@@ -459,22 +459,25 @@ function isOptionNode(node) {
 
 // 从指引节点,获取分类特征数据
 function getItemCharacterData(nodes, prefix) {
-    const processNodes = nodes.filter(node => isProcessNode(node) && node.data.required);
+    const processNodes = nodes.filter(node => isProcessNode(node));
     const classGroups = []; // 同层必填选项的数组(二维数组)
     processNodes.forEach(processNode => {
         const classItems = [];
         const optionNodes = processNode.children.filter(node => isOptionNode(node));
         optionNodes.forEach(optionNode => {
-            if (!optionNode.children 
+            // const name = prefix ? `${prefix}@${optionNode.data.name}` : optionNode.data.name;
+            if (optionNode.parent && optionNode.parent.data.required && (!optionNode.children 
                 || !optionNode.children.length 
                 || (optionNode.children[0].data && optionNode.children[0].data.rationID) 
-                || !optionNode.children.some(node => isProcessNode(node) && node.data.required)) {
+                || !optionNode.children.some(node => isProcessNode(node)))) {
                 classItems.push(optionNode.data.name);
             } else {
-                classItems.push(...getItemCharacterData(optionNode.children, optionNode.data.name));
+                classItems.push(...getItemCharacterData(optionNode.children, optionNode.parent && optionNode.parent.data.required ? optionNode.data.name : ''));
             }
         });
-        classGroups.push(classItems);
+        if (classItems.length) {
+            classGroups.push(classItems);
+        }
     });
     // 拼接上一文本
     if (classGroups[0] && classGroups[0].length) {
@@ -492,7 +495,7 @@ function getItemCharacterData(nodes, prefix) {
         }
         classGroups.splice(0, 2, mergedClassItems);
     }
-    return classGroups[0] || [];
+    return classGroups[0] ? [...new Set(classGroups[0])] : []; // 去重
 }
 
 // 生成清单分类

+ 0 - 2
public/web/tree_sheet/tree_sheet_helper.js

@@ -347,8 +347,6 @@ var TREE_SHEET_HELPER = {
                     TREE_SHEET_HELPER.delayShowTips(hitinfo,setting, node.data.name);
                 }
                 // const node = tree.items[hitinfo.row];
-                console.log(node);
-                console.log(hitinfo);
                 /* let textWidth = ctx.measureText(value).width;
                 console.log(textWidth); */
             }

+ 1 - 1
web/maintain/billsGuidance_lib/html/zhiyin.html

@@ -97,7 +97,7 @@
                                   <a id="downMove" href="javascript:void(0);" class="btn btn-sm lock-btn-control" data-toggle="tooltip" data-placement="bottom" title="下移"><i class="fa fa-arrow-down" aria-hidden="true"></i></a>
                                   <a id="upMove" href="javascript:void(0);" class="btn btn-sm lock-btn-control" data-toggle="tooltip" data-placement="bottom" title="上移"><i class="fa fa-arrow-up" aria-hidden="true"></i></a>
                                   <a id="expandContract" href="javascript:void(0);" class="btn btn-sm" data-toggle="tooltip" data-placement="bottom" title="收起定额"><i class="fa fa-minus-square-o" aria-hidden="true"></i> 收起定额</a>
-                                  <!-- <a id="generate-class" href="javascript:void(0);" class="btn btn-sm lock-btn-control" data-toggle="tooltip" data-placement="bottom" title="生成分类">生成分类</a> -->
+                                  <!-- <a id="generate-class" href="javascript:void(0);" class="btn btn-sm lock-btn-control" data-toggle="tooltip" data-placement="bottom" title="生成分类">测试生成分类算法</a> -->
                               </div>
                           </div>
                           <div class="main-top-content">

+ 43 - 3
web/maintain/billsGuidance_lib/js/billsGuidance.js

@@ -2548,6 +2548,46 @@ const billsGuidance = (function () {
 
     /* 生成特征分类: 测试使用 */
     function getItemCharacterData(nodes, prefix) {
+        const processNodes = nodes.filter(node => isProcessNode(node));
+        const classGroups = []; // 同层必填选项的数组(二维数组)
+        processNodes.forEach(processNode => {
+            const classItems = [];
+            const optionNodes = processNode.children.filter(node => isOptionNode(node));
+            optionNodes.forEach(optionNode => {
+                // const name = prefix ? `${prefix}@${optionNode.data.name}` : optionNode.data.name;
+                if (optionNode.parent && optionNode.parent.data.required && (!optionNode.children 
+                    || !optionNode.children.length 
+                    || (optionNode.children[0].data && optionNode.children[0].data.rationID) 
+                    || !optionNode.children.some(node => isProcessNode(node)))) {
+                    classItems.push(optionNode.data.name);
+                } else {
+                    classItems.push(...getItemCharacterData(optionNode.children, optionNode.parent && optionNode.parent.data.required ? optionNode.data.name : ''));
+                }
+            });
+            if (classItems.length) {
+                classGroups.push(classItems);
+            }
+        });
+        // 拼接上一文本
+        if (classGroups[0] && classGroups[0].length) {
+            classGroups[0] = classGroups[0].map(name => prefix ? `${prefix}@${name}` : name);
+        }
+        // 二维数组内容排列组合
+        while (classGroups.length > 1) {
+            const prevClassItems = classGroups[0];
+            const nextClassItems = classGroups[1];
+            const mergedClassItems = [];
+            for (let i = 0; i < prevClassItems.length; i++) {
+                for (let j = 0; j < nextClassItems.length; j++) {
+                    mergedClassItems.push(`${prevClassItems[i]}@${nextClassItems[j]}`);
+                }
+            }
+            classGroups.splice(0, 2, mergedClassItems);
+        }
+        return classGroups[0] ? [...new Set(classGroups[0])] : [];
+    }
+    /* function getItemCharacterData(nodes, prefix) {
+        debugger;
         const processNodes = nodes.filter(node => isProcessNode(node) && node.data.required);
         const classGroups = []; // 同层必填选项的数组(二维数组)
         processNodes.forEach(processNode => {
@@ -2583,13 +2623,13 @@ const billsGuidance = (function () {
             classGroups.splice(0, 2, mergedClassItems);
         }
         return classGroups[0] || [];
-    }
+    } */
 
     $('#generate-class').click(() => {
-        /* if (bills.tree.selected && bills.tree.selected.guidance.tree) {
+        if (bills.tree.selected && bills.tree.selected.guidance.tree) {
             const classData = getItemCharacterData(bills.tree.selected.guidance.tree.roots);
             console.log(classData);
-        } */
+        }
     });