123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- import { Component, OnInit } from '@angular/core';
- import { NzModalRef, NzMessageService } from 'ng-zorro-antd';
- import { _HttpClient } from '@delon/theme';
- import { ProjectManageArchives } from 'app/entity/project-manage-archives/project-manage-archives';
- import { ProjectNodeTree } from '../../project-node-tree';
- import { BaseArchivesMilestone } from 'app/entity/basedata/base-archives-milestone';
- import { BaseArchivesMilestoneService } from 'app/services/basedata/base-archives-milestone.service';
- @Component({
- selector: 'app-project-manage-archives-add-implementation',
- templateUrl: './implementation.component.html',
- })
- export class ProjectManageArchivesAddImplementationComponent implements OnInit {
-
- constructor(
- private baseArchivesMilestoneService:BaseArchivesMilestoneService
- ) { }
- ngOnInit(): void {
- this.getTreeList();
- }
-
- projectManageArchives:ProjectManageArchives={};
- listOfMapData:any=[];
- personnelList=[];
- remittanceInformation:any={};
-
- getTreeList() {
-
-
-
-
-
-
-
-
-
- }
-
- getLoding(){
- this.listOfMapData.forEach(item => {
- this.mapOfExpandedData[item.key] = this.convertTreeToList(item);
- });
- }
-
-
- S4() {
- return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
- };
- guid() {
- return (this.S4() + this.S4() + this.S4() + this.S4() + this.S4() + this.S4() + this.S4() + this.S4());
- };
-
- add() {
- return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
- };
- adding() {
- return (this.add() + this.add() + this.add() + this.add() + this.add() + this.add() + this.add() + this.add());
- };
- addParent(){
- this.listOfMapData.forEach(item => {
- console.log(this.mapOfExpandedData[item.key]);
- });
- this.listOfMapData=[
- ...this.listOfMapData,
- {key:this.adding()}
- ]
-
- this.initialValue();
- }
-
- addChild(parentId){
- this.getChild(this.listOfMapData, parentId);
- this.initialValue();
- }
-
- getChild(children, parentId) {
- var keyId = this.adding();
- children.forEach(element => {
-
-
- if (element.key == parentId) {
-
- if (element.children == null) {
- element.children = []
- }
-
- element.children = [
- ...element.children,
- { key: keyId, parentId: parentId,children:null}
- ]
-
-
- } else {
- if (element.children != null) {
- this.getChild(element.children, parentId);
- }
- }
- });
- }
-
- deleteRow(array: ProjectNodeTree[], data: ProjectNodeTree, key){
- this.getdeleteRow(key, this.listOfMapData);
- this.initialValue()
- }
-
- getdeleteRow(itemsId: string, list?: any,parent?:any) {
- list.forEach((element, i) => {
-
- if (element.key == itemsId) {
-
- if (element.children != null && element.children.length > 0) {
- element.children.splice(0, element.children.length);
- }
-
- list.splice(i, 1);
-
- if (list.length == 0&&parent) {
- parent.children = null;
- }
- this.listOfMapData=[
- ...this.listOfMapData
- ]
-
-
- } else {
-
- if (element.children != null && element.children.length > 0) {
- this.getdeleteRow(itemsId, element.children,element);
- }
- }
- });
- }
- initialValue(){
- this.listOfMapData.forEach(item => {
- const data = this.mapOfExpandedData[item.key];
- this.mapOfExpandedData[item.key] = this.convertTreeToList(item);
- const mapData = this.mapOfExpandedData[item.key];
- if (data && mapData) {
- mapData.forEach(el => {
- data.forEach(element => {
- if (element.key === el.key) {
- el.muilesId = element.muilesId;
- el.muilesName = element.muilesName;
- el.startDate = element.startDate;
- el.endDate = element.endDate;
- el.planTime = element.planTime;
- el.executors = element.executors;
- el.realTime = element.realTime;
- }
- })
- })
- }
- });
- }
-
- mapOfExpandedData: { [key: string]: ProjectNodeTree[] } = {};
- collapse(array: ProjectNodeTree[], data: ProjectNodeTree, $event: boolean): void {
- if (!$event) {
- if (data.children) {
- data.children.forEach(d => {
- const target = array.find(a => a.key === d.key)!;
- target.expand = false;
- this.collapse(array, target, false);
- });
- } else {
- return;
- }
- }
- }
- convertTreeToList(root: ProjectNodeTree): ProjectNodeTree[] {
- const stack: ProjectNodeTree[] = [];
- const array: ProjectNodeTree[] = [];
- const hashMap = {};
- stack.push({ ...root, level: 0, expand: true });
- while (stack.length !== 0) {
- const node = stack.pop()!;
- this.visitNode(node, hashMap, array);
- if (node.children) {
- for (let i = node.children.length - 1; i >= 0; i--) {
- stack.push({ ...node.children[i], level: node.level! + 1, expand: true, parent: node });
- }
- }
- }
- return array;
- }
- visitNode(node: ProjectNodeTree, hashMap: { [key: string]: boolean }, array: ProjectNodeTree[]): void {
- if (!hashMap[node.key]) {
- hashMap[node.key] = true;
- array.push(node);
- }
- }
- }
|