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() {
- // let baseArchivesMilestone=new BaseArchivesMilestone();
- // baseArchivesMilestone.pkOrg=sessionStorage.getItem("pkOrg");//组织
- // baseArchivesMilestone.typeId="2";
- // this.baseArchivesMilestoneService.getTreeList(baseArchivesMilestone).then((response)=>{
- // if(response.result){
- // this.listOfMapData=response.result
- // this.getLoding();
- // }
- // })
- }
- /**
- * 初始化树形
- */
- getLoding(){
- this.listOfMapData.forEach(item => {
- this.mapOfExpandedData[item.key] = this.convertTreeToList(item);
- });
- }
- /**
- * 新增父级
- */
- //uuid
- 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.getLoding();
- this.initialValue();
- }
- /**
- * 新增子集
- * @param parentId 父级id
- * @param data 操作对象
- */
- addChild(parentId){
- this.getChild(this.listOfMapData, parentId);
- this.initialValue();
- }
- /**
- * 递归查询子集增加
- */
- getChild(children, parentId) {
- var keyId = this.adding();
- children.forEach(element => {
- // 是否和点击的数据相等
- // 相等则在此条数据加子数据
- if (element.key == parentId) {
- // 是否存在自数据不存在则创建child
- if (element.children == null) {
- element.children = []
- }
- // 添加一条空的子数据到child
- element.children = [
- ...element.children,
- { key: keyId, parentId: parentId,children:null}
- ]
- // this.mapOfExpandedData[element.key] = this.convertTreeToList(null);
- // this.initialValue();
- } else {
- if (element.children != null) {
- this.getChild(element.children, parentId);
- }
- }
- });
- }
- /**
- * 删除行
- */
- deleteRow(array: ProjectNodeTree[], data: ProjectNodeTree, key){
- this.getdeleteRow(key, this.listOfMapData);
- this.initialValue()
- }
- /**
- * 递归删除
- * @param itemsId 对象id
- * @param list 需要删除对象的集合
- * @param parent 父级对象
- */
- 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
- ]
- // this.getDataInitialization2();
- // this.initialValue();
- } 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);
- }
- }
- }
|