123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286 |
- import { Component, OnInit } from '@angular/core';
- import { NzModalRef, NzMessageService, NzNotificationService } from 'ng-zorro-antd';
- import { _HttpClient } from '@delon/theme';
- import { BaseArchivesMilestoneService } from 'app/services/basedata/base-archives-milestone.service';
- import { ProjectManageArchives } from 'app/entity/project-manage-archives/project-manage-archives';
- import { ProjectNodeTree } from '../../project-node-tree';
- import { DatePipe } from '@angular/common';
- @Component({
- selector: 'app-project-manage-archives-update-implementation',
- templateUrl: './implementation.component.html',
- })
- export class ProjectManageArchivesUpdateImplementationComponent implements OnInit {
- constructor(
- private datePipe: DatePipe,
- private baseArchivesMilestoneService: BaseArchivesMilestoneService,
- private nzNotificationService: NzNotificationService,
- ) {}
- 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(), planTime: 0 }];
-
- 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, planTime: 0 }];
-
-
- } 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;
- }
- });
- });
- }
- });
- }
-
- startChange(item, date) {
- if (item.parent) {
- let parent = item.parent;
- if (parent.startDate && parent.endDate) {
- let startDatePar = new Date(this.datePipe.transform(parent.startDate, 'yyyy-MM-dd'));
- let endDatePar = new Date(this.datePipe.transform(parent.endDate, 'yyyy-MM-dd'));
- let d = new Date(this.datePipe.transform(date, 'yyyy-MM-dd'));
- let isb = false;
- if (d.getTime() < startDatePar.getTime()) {
-
- this.nzNotificationService.warning('不能小于父级开始时间', '');
- isb = true;
- }
- if (d.getTime() > endDatePar.getTime()) {
-
- this.nzNotificationService.warning('不能大于父级结束时间', '');
- isb = true;
- }
-
- if (isb) {
-
- if (d.getTime() === new Date(this.datePipe.transform(item.startDate, 'yyyy-MM-dd')).getTime()) {
- item.startDate = null;
- }
-
- if (d.getTime() === new Date(this.datePipe.transform(item.endDate, 'yyyy-MM-dd')).getTime()) {
- item.endDate = null;
- }
- this.initialValue();
- }
- }
- }
- }
-
- planTimeKeyup(item) {
- if (item.parent) {
- let parent = item.parent;
-
- if (parent.planTime) {
- let planTimePar = Number(parent.planTime);
-
- let planTimeChildTotal = 0;
-
- this.mapOfExpandedData[item.parent.key].forEach(child => {
-
- if(child.level===parent.level+1){
- planTimeChildTotal = planTimeChildTotal + Number(child.planTime);
- }
- });
-
- if (planTimeChildTotal > planTimePar) {
-
- this.nzNotificationService.warning('子级计划人天总和不能大于父级计划人天', '');
- item.planTime = 0;
- }
- }
- }
- }
-
- 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);
- }
- }
- }
|