implementation.component.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import { Component, OnInit } from '@angular/core';
  2. import { NzModalRef, NzMessageService } from 'ng-zorro-antd';
  3. import { _HttpClient } from '@delon/theme';
  4. import { ProjectManageArchives } from 'app/entity/project-manage-archives/project-manage-archives';
  5. import { ProjectNodeTree } from '../../project-node-tree';
  6. @Component({
  7. selector: 'app-project-manage-archives-view-implementation',
  8. templateUrl: './implementation.component.html',
  9. })
  10. export class ProjectManageArchivesViewImplementationComponent implements OnInit {
  11. constructor(
  12. ) { }
  13. ngOnInit(): void {
  14. }
  15. projectManageArchives: ProjectManageArchives = {}; //项目档案主表实体
  16. listOfMapData: any = []; //树形集合
  17. remittanceInformation: any = {}; //回款信息实体
  18. /**
  19. * 初始化树形
  20. */
  21. getLoding() {
  22. this.listOfMapData.forEach(item => {
  23. this.mapOfExpandedData[item.key] = this.convertTreeToList(item);
  24. });
  25. }
  26. ///////////////////////////树形配置
  27. mapOfExpandedData: { [key: string]: ProjectNodeTree[] } = {};
  28. collapse(array: ProjectNodeTree[], data: ProjectNodeTree, $event: boolean): void {
  29. if (!$event) {
  30. if (data.children) {
  31. data.children.forEach(d => {
  32. const target = array.find(a => a.key === d.key)!;
  33. target.expand = false;
  34. this.collapse(array, target, false);
  35. });
  36. } else {
  37. return;
  38. }
  39. }
  40. }
  41. convertTreeToList(root: ProjectNodeTree): ProjectNodeTree[] {
  42. const stack: ProjectNodeTree[] = [];
  43. const array: ProjectNodeTree[] = [];
  44. const hashMap = {};
  45. stack.push({ ...root, level: 0, expand: true });
  46. while (stack.length !== 0) {
  47. const node = stack.pop()!;
  48. this.visitNode(node, hashMap, array);
  49. if (node.children) {
  50. for (let i = node.children.length - 1; i >= 0; i--) {
  51. stack.push({ ...node.children[i], level: node.level! + 1, expand: true, parent: node });
  52. }
  53. }
  54. }
  55. return array;
  56. }
  57. visitNode(node: ProjectNodeTree, hashMap: { [key: string]: boolean }, array: ProjectNodeTree[]): void {
  58. if (!hashMap[node.key]) {
  59. hashMap[node.key] = true;
  60. array.push(node);
  61. }
  62. }
  63. }