implementation.component.ts 6.6 KB

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