济南项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

303 lines
8.9 KiB

import { Component, OnInit, Input } from '@angular/core';
import { NzModalRef } from 'ng-zorro-antd/modal';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { HttpClient } from '@angular/common/http';
import { TreeService } from 'src/app/service/tree.service';
import { Observable, of } from 'rxjs';
import { catchError, map } from 'rxjs/operators';
import { NzMessageService } from 'ng-zorro-antd/message';
import { NzFormatEmitEvent, NzTreeNodeOptions } from 'ng-zorro-antd/tree';
@Component({
selector: 'app-apply',
templateUrl: './apply.component.html',
styleUrls: ['./apply.component.scss']
})
export class ApplyComponent implements OnInit {
@Input() title?: any;
@Input() nodes?: any;
@Input() supervisorList?: any;
@Input() organizationList?: any;
@Input() users?: any;
@Input() mainsupervisorList?: any;
@Input() assitantsupervisorList?: any;
validateForm!: FormGroup;
constructor(private modal: NzModalRef, private fb: FormBuilder, private http: HttpClient, private toTree: TreeService, private message: NzMessageService) { }
taskType
newTree
OrganizationId
userId
supervisorListAll = []
ngOnInit(): void {
this.OrganizationId = JSON.parse(sessionStorage.getItem('userData')).organizationId
this.userId = JSON.parse(sessionStorage.getItem('userData')).id
console.log('mainsupervisorList', this.mainsupervisorList)
console.log('assitantsupervisorList', this.assitantsupervisorList)
this.supervisorListAll = [...this.mainsupervisorList, ...this.assitantsupervisorList]
this.validateForm = this.fb.group({
taskname: [null, [Validators.required]],
organization: [null, [Validators.required]],
main: [null],
assist: [null]
});
this.newTree = this.nodes
this.getCompanies()
this.getAllOrganization()
// Promise.all([this.getCompanies(), this.getAllOrganization()])
// .then((results) => {
// let arr = [...JSON.parse(JSON.stringify(this.allOrList)), ...JSON.parse(JSON.stringify(this.unitList))]
// let nodes = [...this.toTree.toTree(arr)]
// this.unitPopover.nodes = JSON.parse(JSON.stringify(nodes))
// });
}
isLoading = false;
allOrList: any
async getAllOrganization() {
let params = {
ContainsChildren: true,
pageSize: 9999
}
return new Promise<void>((resolve, reject) => {
this.http.get('/api/Organizations', {
params: params
}).subscribe((data: any) => {
data.items.forEach(element => {
element.key = element.id
element.title = element.name
element.selectable = false
element.disableCheckbox = true
element.datatype = '机构'
element.level == 'squadron' ? element.disableCheckbox = false : null
});
data.items.forEach(element => {
if (element.id == JSON.parse(sessionStorage.getItem('userData')).organizationId) {
element.parentId = null
}
});
this.allOrList = JSON.parse(JSON.stringify(data.items))
this.nodes = [...this.toTree.toTree(JSON.parse(JSON.stringify(data.items)))]
this.unitPopover.nodes = JSON.parse(JSON.stringify(this.nodes))
console.log(6666, data.items)
resolve(data)
})
})
}
selectedUnitData = {
name: '',
id: ''
}
selectedUnit(data, e?: any) {
e ? e.stopPropagation() : null
let arr = [...data.search1Value, ...data.search2Value]
let arrSet = [...new Set(arr)]
console.log(arrSet)
console.log(this.unitPopover)
if (arrSet.length > 1) {
this.message.create('warning', '只能选择一个单位');
return
} else {
this.http.get(`/api/Companies/${arrSet[0]}`).subscribe((data: any) => {
console.log(data)
this.selectedUnitData.name = data.companyName
this.selectedUnitData.id = data.id
})
this.unitPopover.isPopover = false
}
}
//
unitPopover = {
allocated: 0,
isExpand: true,//卡片展开
isPopover: false,//选择单位气泡卡片
isLoading: false,
search1: '',//选择单位气泡卡片---单位选择列表
search1Value: [],
search2: '',//选择单位气泡卡片---组织选择列表
search2Value: [],
searchAll: [],
selectedMenu: 1,//选择单位气泡卡片
data: [
],//表格数据
nodes: [],
nodes2: [],//查询后展示的tree
isnodes: true,
unitList: []
}
isPopover(data, e?: any) {
e ? e.stopPropagation() : null
data.isPopover = !data.isPopover
}
// 弹出 tab
popoverMenuSelect(data, type) {
data.selectedMenu = type
}
//搜索框提交
submitForm(data): void {
data.unitList = []
this.PageNumber = 1
this.getCompanies(data)
}
totalCount: number
unitList = []
PageNumber = 1
async getCompanies(incomingData?: any) {
let params = {
OrganizationId: this.OrganizationId,
CompanyName: incomingData ? incomingData.search1 : '',
PageNumber: this.PageNumber,
PageSize: 50
}
return new Promise<void>((resolve, reject) => {
this.http.get('/api/Companies', {
params: params
}).subscribe((data: any) => {
this.moreDataLoading = false
this.totalCount = data.totalCount
data.items.forEach(element => {
element.label = element.companyName
element.value = element.id
element.parentId = element.organizationId
element.key = element.id
element.title = element.companyName
element.level = 4
});
this.unitList = data.items
this.unitPopover.unitList = this.unitPopover.unitList.concat(JSON.parse(JSON.stringify(data.items)));
this.unitPopover.unitList = [...this.unitPopover.unitList]
resolve(data)
})
})
}
moreDataLoading = false
moreData() {
this.moreDataLoading = true
this.PageNumber += 1
this.getCompanies()
}
onExpandChange(e: NzFormatEmitEvent): void {
const node = e.node;
if (node && node.getChildren().length === 0 && node.isExpanded && node.origin.level == 'squadron') {
this.loadNode(node.origin.id).then(data => {
node.addChildren(data);
});
} else {
node.isLoading = false
}
}
loadNode(id): Promise<NzTreeNodeOptions[]> {
return new Promise(resolve => {
let params = {
OrganizationId: id,
PageNumber: 1,
PageSize: 9999
}
this.http.get('/api/Companies', {
params: params
}).subscribe((data: any) => {
console.log(data.items)
data.items.forEach(element => {
element.key = element.id
element.title = element.companyName
element.level = 4
element.isLeaf = true
});
resolve(data.items)
})
});
}
async getCompaniesByName(incomingData) {
console.log(incomingData.search2Value)
if (incomingData.search2) {
incomingData.isnodes = false
let params = {
OrganizationId: this.OrganizationId,
CompanyName: incomingData.search2,
PageNumber: this.PageNumber,
PageSize: 9999
}
return new Promise<void>((resolve, reject) => {
this.http.get('/api/Companies', {
params: params
}).subscribe((data: any) => {
this.moreDataLoading = false
this.totalCount = data.totalCount
data.items.forEach(element => {
element.label = element.companyName
element.value = element.id
element.parentId = element.organizationId
element.key = element.id
element.title = element.companyName
element.level = 4
element.isLeaf = true
incomingData.search2Value.forEach(item => {
item == element.id ? element.isChecked = true : null
});
});
if (data.items.length == 0) {
this.message.create('warning', '没有查询到任何单位');
incomingData.isnodes = true
return
}
let allOrList = JSON.parse(JSON.stringify(this.allOrList))
allOrList.forEach(element => {
element.expanded = true
});
let arr = [...allOrList, ...data.items]
incomingData.nodes2 = [...this.toTree.toTree(arr)]
resolve(data)
})
})
} else {
// incomingData.search2Value = []
incomingData.isnodes = true
}
}
log(data) {
let arr = []
data.unitList.forEach(item => {
item.checked ? arr.push(item.id) : null
});
data.search1Value = arr
}
orcheckbox(data, $event, node) {
// search2NameValue
if ($event) {
data.search2Value.push(node.origin.id)
} else {
for (let index = 0; index < data.search2Value.length; index++) {
const element = data.search2Value[index];
if (element == node.origin.id) {
data.search2Value.splice(index, 1)
index--
}
}
}
}
}