|  | @@ -0,0 +1,110 @@
 | 
	
		
			
				|  |  | +const associationOprObj = {
 | 
	
		
			
				|  |  | +  treeObj: null,
 | 
	
		
			
				|  |  | +  iniAssociateNodes: function(allTopTplNodes) {
 | 
	
		
			
				|  |  | +    // 同类表初始化
 | 
	
		
			
				|  |  | +    const me = associationOprObj;
 | 
	
		
			
				|  |  | +    zTreeHelper.createTreeDirectly(
 | 
	
		
			
				|  |  | +      allTopTplNodes,
 | 
	
		
			
				|  |  | +      associationSetting,
 | 
	
		
			
				|  |  | +      "tpl_data_info_association",
 | 
	
		
			
				|  |  | +      associationOprObj
 | 
	
		
			
				|  |  | +    );
 | 
	
		
			
				|  |  | +    me.treeObj.expandAll(true);
 | 
	
		
			
				|  |  | +    const topNodes = me.treeObj.getNodes();
 | 
	
		
			
				|  |  | +    const private_setup_checked = function (itemNode) {
 | 
	
		
			
				|  |  | +      if (itemNode.nodeType === RT.NodeType.NODE) {
 | 
	
		
			
				|  |  | +        me.treeObj.setChkDisabled(itemNode, true);
 | 
	
		
			
				|  |  | +      } else if (itemNode.nodeType === RT.NodeType.TEMPLATE) {
 | 
	
		
			
				|  |  | +        me.treeObj.checkNode(itemNode, false); // 在初始化时,默认是不选;只有用户选择了具体的某一个表时,才会更新选择
 | 
	
		
			
				|  |  | +      }
 | 
	
		
			
				|  |  | +      if (itemNode.items && itemNode.items.length > 0) {
 | 
	
		
			
				|  |  | +        for (let subItem of itemNode.items) {
 | 
	
		
			
				|  |  | +          private_setup_checked(subItem);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +      }
 | 
	
		
			
				|  |  | +    };
 | 
	
		
			
				|  |  | +    for (let node of topNodes) {
 | 
	
		
			
				|  |  | +      me.treeObj.setChkDisabled(node, true);
 | 
	
		
			
				|  |  | +      if (node.items && node.items.length > 0) {
 | 
	
		
			
				|  |  | +        for (let item of node.items) {
 | 
	
		
			
				|  |  | +          me.treeObj.setChkDisabled(item, true);
 | 
	
		
			
				|  |  | +          private_setup_checked(item);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +      }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +  },
 | 
	
		
			
				|  |  | +  refreshNodes: function (refNode) {
 | 
	
		
			
				|  |  | +    const me = this;
 | 
	
		
			
				|  |  | +    // 不管三七二十一,先把所有节点的check给清除
 | 
	
		
			
				|  |  | +    const setUnCheck = (itemNode) => {
 | 
	
		
			
				|  |  | +      me.treeObj.checkNode(itemNode, false);
 | 
	
		
			
				|  |  | +      if (itemNode.items && itemNode.items.length > 0) {
 | 
	
		
			
				|  |  | +        for (let subItem of itemNode.items) {
 | 
	
		
			
				|  |  | +          setUnCheck(subItem);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +      }
 | 
	
		
			
				|  |  | +    };
 | 
	
		
			
				|  |  | +    const topNodes = me.treeObj.getNodes();
 | 
	
		
			
				|  |  | +    topNodes.forEach(node => {
 | 
	
		
			
				|  |  | +      setUnCheck(node);
 | 
	
		
			
				|  |  | +    });
 | 
	
		
			
				|  |  | +    const checkRefTpl = (itemNodes, associateRefIds) => {
 | 
	
		
			
				|  |  | +      for (const itemNode of itemNodes) {
 | 
	
		
			
				|  |  | +        if (itemNode.nodeType === RT.NodeType.TEMPLATE) {
 | 
	
		
			
				|  |  | +          if (associateRefIds.includes(itemNode.refId)) {
 | 
	
		
			
				|  |  | +            me.treeObj.checkNode(itemNode, true);
 | 
	
		
			
				|  |  | +          }
 | 
	
		
			
				|  |  | +        } else {
 | 
	
		
			
				|  |  | +          if (itemNode.items && itemNode.items.length > 0) {
 | 
	
		
			
				|  |  | +            checkRefTpl(itemNode.items, associateRefIds);
 | 
	
		
			
				|  |  | +          }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +      }
 | 
	
		
			
				|  |  | +    };
 | 
	
		
			
				|  |  | +    $("#hasAssociationChk").get(0).checked = false;
 | 
	
		
			
				|  |  | +    if (refNode && refNode.nodeType === RT.NodeType.TEMPLATE) {
 | 
	
		
			
				|  |  | +      if (refNode.associateRefIds && refNode.associateRefIds.length > 0) {
 | 
	
		
			
				|  |  | +        $("#hasAssociationChk").get(0).checked = true;
 | 
	
		
			
				|  |  | +        checkRefTpl(topNodes, refNode.associateRefIds);
 | 
	
		
			
				|  |  | +      }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +  },
 | 
	
		
			
				|  |  | +  getCheckedRefIds: function() {
 | 
	
		
			
				|  |  | +    const me = associationOprObj;
 | 
	
		
			
				|  |  | +    const rst = [];
 | 
	
		
			
				|  |  | +    const getCheckedId = (itemNodes) => {
 | 
	
		
			
				|  |  | +      for (const itemNode of itemNodes) {
 | 
	
		
			
				|  |  | +        if (itemNode.nodeType === RT.NodeType.TEMPLATE && itemNode.checked) {
 | 
	
		
			
				|  |  | +          rst.push(itemNode.refId);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        if (itemNode.items && itemNode.items.length > 0) {
 | 
	
		
			
				|  |  | +          getCheckedId(itemNode.items);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +      }
 | 
	
		
			
				|  |  | +    };
 | 
	
		
			
				|  |  | +    if (me.treeObj) {
 | 
	
		
			
				|  |  | +      const topNodes = me.treeObj.getNodes();
 | 
	
		
			
				|  |  | +      getCheckedId(topNodes);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +    return rst;
 | 
	
		
			
				|  |  | +  },
 | 
	
		
			
				|  |  | +  onCheck: function(event, treeId, treeNode) {
 | 
	
		
			
				|  |  | +    const me = associationOprObj;
 | 
	
		
			
				|  |  | +    if (zTreeOprObj.currentNode) {
 | 
	
		
			
				|  |  | +      // 不考虑细节交互了,直接从头到尾扫一遍,重新整理associateRefIds信息,最后更新
 | 
	
		
			
				|  |  | +      zTreeOprObj.currentNode.associateRefIds = me.getCheckedRefIds();
 | 
	
		
			
				|  |  | +      if (zTreeOprObj.currentNode.associateRefIds.length > 0) {
 | 
	
		
			
				|  |  | +        $("#hasAssociationChk").get(0).checked = true;
 | 
	
		
			
				|  |  | +      } else {
 | 
	
		
			
				|  |  | +        $("#hasAssociationChk").get(0).checked = false;
 | 
	
		
			
				|  |  | +      }
 | 
	
		
			
				|  |  | +      const topPNode = zTreeOprObj.getParentNodeByNodeLevel(zTreeOprObj.currentNode, NODE_LEVEL_COMPILATION_NEW);
 | 
	
		
			
				|  |  | +      const newTopNode = zTreeOprObj.buildRootNodeDoc(topPNode);
 | 
	
		
			
				|  |  | +      zTreeOprObj.updateTreeRootNode(newTopNode, true, function (rst) {
 | 
	
		
			
				|  |  | +        if (!rst) {
 | 
	
		
			
				|  |  | +          alert("修改同类表请求失败!");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +      });
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +  },
 | 
	
		
			
				|  |  | +};
 |