implementation.component.ts 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. import { Component, OnInit } from '@angular/core';
  2. import { NzModalRef, NzMessageService, NzNotificationService } 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 { ProjectNodeTree } from '../../project-node-tree';
  7. import { DatePipe } from '@angular/common';
  8. @Component({
  9. selector: 'app-project-manage-archives-update-implementation',
  10. templateUrl: './implementation.component.html',
  11. })
  12. export class ProjectManageArchivesUpdateImplementationComponent implements OnInit {
  13. constructor(
  14. private datePipe: DatePipe,
  15. private baseArchivesMilestoneService: BaseArchivesMilestoneService,
  16. private nzNotificationService: NzNotificationService,
  17. ) {}
  18. ngOnInit(): void {
  19. this.getTreeList();
  20. }
  21. projectManageArchives: ProjectManageArchives = {}; //项目档案主表实体
  22. listOfMapData: any = []; //树形集合
  23. personnelList = []; //人员下拉列表
  24. remittanceInformation: any = {}; //回款信息实体
  25. /**
  26. * 获取树形集合
  27. */
  28. getTreeList() {
  29. // let baseArchivesMilestone=new BaseArchivesMilestone();
  30. // baseArchivesMilestone.pkOrg=sessionStorage.getItem("pkOrg");//组织
  31. // baseArchivesMilestone.typeId="2";
  32. // this.baseArchivesMilestoneService.getTreeList(baseArchivesMilestone).then((response)=>{
  33. // if(response.result){
  34. // this.listOfMapData=response.result
  35. // this.getLoding();
  36. // }
  37. // })
  38. }
  39. /**
  40. * 初始化树形
  41. */
  42. getLoding() {
  43. this.listOfMapData.forEach(item => {
  44. this.mapOfExpandedData[item.key] = this.convertTreeToList(item);
  45. });
  46. }
  47. /**
  48. * 新增父级
  49. */
  50. //uuid
  51. S4() {
  52. return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
  53. }
  54. guid() {
  55. return this.S4() + this.S4() + this.S4() + this.S4() + this.S4() + this.S4() + this.S4() + this.S4();
  56. }
  57. // 随机数
  58. add() {
  59. return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
  60. }
  61. adding() {
  62. return this.add() + this.add() + this.add() + this.add() + this.add() + this.add() + this.add() + this.add();
  63. }
  64. addParent() {
  65. this.listOfMapData.forEach(item => {
  66. console.log(this.mapOfExpandedData[item.key]);
  67. });
  68. this.listOfMapData = [...this.listOfMapData, { key: this.adding(), planTime: 0 }];
  69. // this.getLoding();
  70. this.initialValue();
  71. }
  72. /**
  73. * 新增子集
  74. * @param parentId 父级id
  75. * @param data 操作对象
  76. */
  77. addChild(parentId) {
  78. this.getChild(this.listOfMapData, parentId);
  79. this.initialValue();
  80. }
  81. /**
  82. * 递归查询子集增加
  83. */
  84. getChild(children, parentId) {
  85. var keyId = this.adding();
  86. children.forEach(element => {
  87. // 是否和点击的数据相等
  88. // 相等则在此条数据加子数据
  89. if (element.key == parentId) {
  90. // 是否存在自数据不存在则创建child
  91. if (element.children == null) {
  92. element.children = [];
  93. }
  94. // 添加一条空的子数据到child
  95. element.children = [...element.children, { key: keyId, parentId: parentId, children: null, planTime: 0 }];
  96. // this.mapOfExpandedData[element.key] = this.convertTreeToList(null);
  97. // this.initialValue();
  98. } else {
  99. if (element.children != null) {
  100. this.getChild(element.children, parentId);
  101. }
  102. }
  103. });
  104. }
  105. /**
  106. * 删除行
  107. */
  108. deleteRow(array: ProjectNodeTree[], data: ProjectNodeTree, key) {
  109. this.getdeleteRow(key, this.listOfMapData);
  110. this.initialValue();
  111. }
  112. /**
  113. * 递归删除
  114. * @param itemsId 对象id
  115. * @param list 需要删除对象的集合
  116. * @param parent 父级对象
  117. */
  118. getdeleteRow(itemsId: string, list?: any, parent?: any) {
  119. list.forEach((element, i) => {
  120. //判断选中得数据是否有找到
  121. if (element.key == itemsId) {
  122. //找到则先判断对象是否有子集,有则删除
  123. if (element.children != null && element.children.length > 0) {
  124. element.children.splice(0, element.children.length);
  125. }
  126. //然后删除父极对象
  127. list.splice(i, 1);
  128. //判断父极是否存在子集
  129. if (list.length == 0 && parent) {
  130. parent.children = null;
  131. }
  132. this.listOfMapData = [...this.listOfMapData];
  133. // this.getDataInitialization2();
  134. // this.initialValue();
  135. } else {
  136. //没有则判断是否有子集 有则递归同样判断
  137. if (element.children != null && element.children.length > 0) {
  138. this.getdeleteRow(itemsId, element.children, element);
  139. }
  140. }
  141. });
  142. }
  143. initialValue() {
  144. this.listOfMapData.forEach(item => {
  145. const data = this.mapOfExpandedData[item.key];
  146. this.mapOfExpandedData[item.key] = this.convertTreeToList(item);
  147. const mapData = this.mapOfExpandedData[item.key];
  148. if (data && mapData) {
  149. mapData.forEach(el => {
  150. data.forEach(element => {
  151. if (element.key === el.key) {
  152. el.muilesId = element.muilesId;
  153. el.muilesName = element.muilesName;
  154. el.startDate = element.startDate;
  155. el.endDate = element.endDate;
  156. el.planTime = element.planTime;
  157. el.executors = element.executors;
  158. el.realTime = element.realTime;
  159. }
  160. });
  161. });
  162. }
  163. });
  164. }
  165. /**
  166. * 时间选择事件
  167. * 验证开始时间和结束时间是否在父级时间的范围内
  168. */
  169. startChange(item, date) {
  170. if (item.parent) {
  171. let parent = item.parent; //父级对象
  172. if (parent.startDate && parent.endDate) {
  173. let startDatePar = new Date(this.datePipe.transform(parent.startDate, 'yyyy-MM-dd')); //父级开始时间
  174. let endDatePar = new Date(this.datePipe.transform(parent.endDate, 'yyyy-MM-dd')); //父级结束时间
  175. let d = new Date(this.datePipe.transform(date, 'yyyy-MM-dd')); //选择的时间
  176. let isb = false;
  177. if (d.getTime() < startDatePar.getTime()) {
  178. //不能小于父级开始时间
  179. this.nzNotificationService.warning('不能小于父级开始时间', '');
  180. isb = true;
  181. }
  182. if (d.getTime() > endDatePar.getTime()) {
  183. //不能大于父级结束时间
  184. this.nzNotificationService.warning('不能大于父级结束时间', '');
  185. isb = true;
  186. }
  187. //如果验证到错误则清空时间
  188. if (isb) {
  189. //如果是操作的开始时间则清除开始时间
  190. if (d.getTime() === new Date(this.datePipe.transform(item.startDate, 'yyyy-MM-dd')).getTime()) {
  191. item.startDate = null;
  192. }
  193. //如果是操作的结束时间则清除结束时间
  194. if (d.getTime() === new Date(this.datePipe.transform(item.endDate, 'yyyy-MM-dd')).getTime()) {
  195. item.endDate = null;
  196. }
  197. this.initialValue();
  198. }
  199. }
  200. }
  201. }
  202. /**
  203. * 计划人天鼠标离开事件
  204. * 验证子级计划人天不得大于父级计划人天
  205. */
  206. planTimeKeyup(item) {
  207. if (item.parent) {
  208. let parent = item.parent; //父级对象
  209. //判断父级计划人天是否为空
  210. if (parent.planTime) {
  211. let planTimePar = Number(parent.planTime); //父级计划人天
  212. //循环父级的所有子集数据
  213. let planTimeChildTotal = 0; //所有子集计划人天
  214. //循环父级节点下的子级
  215. this.mapOfExpandedData[item.parent.key].forEach(child => {
  216. //判断是否父级下的子级 排除子子级
  217. if(child.level===parent.level+1){
  218. planTimeChildTotal = planTimeChildTotal + Number(child.planTime);
  219. }
  220. });
  221. //判断是否大于父级的计划人天
  222. if (planTimeChildTotal > planTimePar) {
  223. //子级计划人天总和不能大于父级计划人天
  224. this.nzNotificationService.warning('子级计划人天总和不能大于父级计划人天', '');
  225. item.planTime = 0;
  226. }
  227. }
  228. }
  229. }
  230. ///////////////////////////树形配置
  231. mapOfExpandedData: { [key: string]: ProjectNodeTree[] } = {};
  232. collapse(array: ProjectNodeTree[], data: ProjectNodeTree, $event: boolean): void {
  233. if (!$event) {
  234. if (data.children) {
  235. data.children.forEach(d => {
  236. const target = array.find(a => a.key === d.key)!;
  237. target.expand = false;
  238. this.collapse(array, target, false);
  239. });
  240. } else {
  241. return;
  242. }
  243. }
  244. }
  245. convertTreeToList(root: ProjectNodeTree): ProjectNodeTree[] {
  246. const stack: ProjectNodeTree[] = [];
  247. const array: ProjectNodeTree[] = [];
  248. const hashMap = {};
  249. stack.push({ ...root, level: 0, expand: true });
  250. while (stack.length !== 0) {
  251. const node = stack.pop()!;
  252. this.visitNode(node, hashMap, array);
  253. if (node.children) {
  254. for (let i = node.children.length - 1; i >= 0; i--) {
  255. stack.push({ ...node.children[i], level: node.level! + 1, expand: true, parent: node });
  256. }
  257. }
  258. }
  259. return array;
  260. }
  261. visitNode(node: ProjectNodeTree, hashMap: { [key: string]: boolean }, array: ProjectNodeTree[]): void {
  262. if (!hashMap[node.key]) {
  263. hashMap[node.key] = true;
  264. array.push(node);
  265. }
  266. }
  267. }