serviceta.component.ts 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. import { Component, OnInit } from '@angular/core';
  2. import { NzModalRef, NzMessageService } from 'ng-zorro-antd';
  3. import { _HttpClient } from '@delon/theme';
  4. import { BaseArchivesMilestoneService } from 'app/services/basedata/base-archives-milestone.service';
  5. import { ProjectManageArchives } from 'app/entity/project-manage-archives/project-manage-archives';
  6. import { BaseArchivesMilestone } from 'app/entity/basedata/base-archives-milestone';
  7. import { ProjectNodeTree } from '../../project-node-tree';
  8. @Component({
  9. selector: 'app-project-manage-archives-add-serviceta',
  10. templateUrl: './serviceta.component.html',
  11. })
  12. export class ProjectManageArchivesAddServicetaComponent implements OnInit {
  13. constructor(private baseArchivesMilestoneService: BaseArchivesMilestoneService) {}
  14. ngOnInit(): void {
  15. this.getTreeList();
  16. }
  17. projectManageArchives: ProjectManageArchives = {}; //项目档案主表实体
  18. listOfMapData: any = []; //树形集合
  19. personnelList = []; //人员下拉列表
  20. remittanceInformation: any = {}; //回款信息实体
  21. /**
  22. * 获取树形集合
  23. */
  24. getTreeList() {
  25. // let baseArchivesMilestone = new BaseArchivesMilestone();
  26. // baseArchivesMilestone.pkOrg = sessionStorage.getItem('pkOrg'); //组织
  27. // baseArchivesMilestone.typeId = '4';
  28. // this.baseArchivesMilestoneService.getTreeList(baseArchivesMilestone).then(response => {
  29. // if (response.result) {
  30. // this.listOfMapData = response.result;
  31. // this.getLoding();
  32. // }
  33. // });
  34. }
  35. /**
  36. * 初始化树形
  37. */
  38. getLoding() {
  39. this.listOfMapData.forEach(item => {
  40. this.mapOfExpandedData[item.key] = this.convertTreeToList(item);
  41. });
  42. }
  43. /**
  44. * 新增父级
  45. */
  46. //uuid
  47. S4() {
  48. return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
  49. }
  50. guid() {
  51. return this.S4() + this.S4() + this.S4() + this.S4() + this.S4() + this.S4() + this.S4() + this.S4();
  52. }
  53. // 随机数
  54. add() {
  55. return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
  56. }
  57. adding() {
  58. return this.add() + this.add() + this.add() + this.add() + this.add() + this.add() + this.add() + this.add();
  59. }
  60. addParent() {
  61. this.listOfMapData.forEach(item => {
  62. console.log(this.mapOfExpandedData[item.key]);
  63. });
  64. this.listOfMapData = [...this.listOfMapData, { key: this.adding() }];
  65. // this.getLoding();
  66. this.initialValue();
  67. }
  68. /**
  69. * 新增子集
  70. * @param parentId 父级id
  71. * @param data 操作对象
  72. */
  73. addChild(parentId) {
  74. this.getChild(this.listOfMapData, parentId);
  75. this.initialValue();
  76. }
  77. /**
  78. * 递归查询子集增加
  79. */
  80. getChild(children, parentId) {
  81. var keyId = this.adding();
  82. children.forEach(element => {
  83. // 是否和点击的数据相等
  84. // 相等则在此条数据加子数据
  85. if (element.key == parentId) {
  86. // 是否存在自数据不存在则创建child
  87. if (element.children == null) {
  88. element.children = [];
  89. }
  90. // 添加一条空的子数据到child
  91. element.children = [...element.children, { key: keyId, parentId: parentId }];
  92. // this.mapOfExpandedData[element.key] = this.convertTreeToList(null);
  93. // this.initialValue();
  94. } else {
  95. if (element.children != null) {
  96. this.getChild(element.children, parentId);
  97. }
  98. }
  99. });
  100. }
  101. /**
  102. * 删除行
  103. */
  104. deleteRow(array: ProjectNodeTree[], data: ProjectNodeTree, key) {
  105. this.getdeleteRow(key, this.listOfMapData);
  106. this.initialValue();
  107. }
  108. /**
  109. * 递归删除
  110. * @param itemsId 对象id
  111. * @param list 需要删除对象的集合
  112. * @param parent 父级对象
  113. */
  114. getdeleteRow(itemsId: string, list?: any, parent?: any) {
  115. list.forEach((element, i) => {
  116. //判断选中得数据是否有找到
  117. if (element.key == itemsId) {
  118. //找到则先判断对象是否有子集,有则删除
  119. if (element.children != null && element.children.length > 0) {
  120. element.children.splice(0, element.children.length);
  121. }
  122. //然后删除父极对象
  123. list.splice(i, 1);
  124. //判断父极是否存在子集
  125. if (list.length == 0 && parent) {
  126. parent.children = null;
  127. }
  128. this.listOfMapData = [...this.listOfMapData];
  129. // this.getDataInitialization2();
  130. // this.initialValue();
  131. } else {
  132. //没有则判断是否有子集 有则递归同样判断
  133. if (element.children != null && element.children.length > 0) {
  134. this.getdeleteRow(itemsId, element.children, element);
  135. }
  136. }
  137. });
  138. }
  139. initialValue() {
  140. this.listOfMapData.forEach(item => {
  141. const data = this.mapOfExpandedData[item.key];
  142. this.mapOfExpandedData[item.key] = this.convertTreeToList(item);
  143. const mapData = this.mapOfExpandedData[item.key];
  144. if (data && mapData) {
  145. mapData.forEach(el => {
  146. data.forEach(element => {
  147. if (element.key === el.key) {
  148. el.code=element.code;
  149. el.name=element.name;
  150. el.muilesId = element.muilesId;
  151. el.muilesName = element.muilesName;
  152. el.startDate = element.startDate;
  153. el.endDate = element.endDate;
  154. el.planTime = element.planTime;
  155. el.executors = element.executors;
  156. el.realTime = element.realTime;
  157. }
  158. });
  159. });
  160. }
  161. });
  162. }
  163. ///////////////////////////树形配置
  164. mapOfExpandedData: { [key: string]: ProjectNodeTree[] } = {};
  165. collapse(array: ProjectNodeTree[], data: ProjectNodeTree, $event: boolean): void {
  166. if (!$event) {
  167. if (data.children) {
  168. data.children.forEach(d => {
  169. const target = array.find(a => a.key === d.key)!;
  170. target.expand = false;
  171. this.collapse(array, target, false);
  172. });
  173. } else {
  174. return;
  175. }
  176. }
  177. }
  178. convertTreeToList(root: ProjectNodeTree): ProjectNodeTree[] {
  179. const stack: ProjectNodeTree[] = [];
  180. const array: ProjectNodeTree[] = [];
  181. const hashMap = {};
  182. stack.push({ ...root, level: 0, expand: true });
  183. while (stack.length !== 0) {
  184. const node = stack.pop()!;
  185. this.visitNode(node, hashMap, array);
  186. if (node.children) {
  187. for (let i = node.children.length - 1; i >= 0; i--) {
  188. stack.push({ ...node.children[i], level: node.level! + 1, expand: true, parent: node });
  189. }
  190. }
  191. }
  192. return array;
  193. }
  194. visitNode(node: ProjectNodeTree, hashMap: { [key: string]: boolean }, array: ProjectNodeTree[]): void {
  195. if (!hashMap[node.key]) {
  196. hashMap[node.key] = true;
  197. array.push(node);
  198. }
  199. }
  200. }