|
|
|
import {
|
|
|
|
Component,
|
|
|
|
Input,
|
|
|
|
OnInit,
|
|
|
|
TemplateRef,
|
|
|
|
ViewChild,
|
|
|
|
ViewContainerRef,
|
|
|
|
} from "@angular/core";
|
|
|
|
import { FormBuilder, FormGroup, Validators } from "@angular/forms";
|
|
|
|
import {
|
|
|
|
NzFormatEmitEvent,
|
|
|
|
NzTreeComponent,
|
|
|
|
NzTreeNodeOptions,
|
|
|
|
} from "ng-zorro-antd/tree";
|
|
|
|
import { NzModalService } from "ng-zorro-antd/modal";
|
|
|
|
import { NzMessageService } from "ng-zorro-antd/message";
|
|
|
|
import { HttpClient } from "@angular/common/http";
|
|
|
|
import { TreeService } from "src/app/service/tree.service";
|
|
|
|
import { NzNotificationService } from "ng-zorro-antd/notification";
|
|
|
|
@Component({
|
|
|
|
selector: "app-binding",
|
|
|
|
templateUrl: "./binding.component.html",
|
|
|
|
styleUrls: ["./binding.component.scss"],
|
|
|
|
})
|
|
|
|
export class BindingComponent implements OnInit {
|
|
|
|
@Input() data?: any;
|
|
|
|
validateForm!: FormGroup;
|
|
|
|
constructor(
|
|
|
|
private fb: FormBuilder,
|
|
|
|
private modal: NzModalService,
|
|
|
|
private viewContainerRef: ViewContainerRef,
|
|
|
|
private message: NzMessageService,
|
|
|
|
private http: HttpClient,
|
|
|
|
private toTree: TreeService,
|
|
|
|
private notification: NzNotificationService,
|
|
|
|
private notificationService: NzNotificationService
|
|
|
|
) {}
|
|
|
|
|
|
|
|
level;
|
|
|
|
getAllUrl;
|
|
|
|
addUrl;
|
|
|
|
editUrl;
|
|
|
|
deleteUrl;
|
|
|
|
CountsByOrganizations;
|
|
|
|
isAdmin: boolean;
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
|
|
|
this.validateForm = this.fb.group({
|
|
|
|
search: [null],
|
|
|
|
});
|
|
|
|
this.level = JSON.parse(
|
|
|
|
sessionStorage.getItem("userdata")
|
|
|
|
).organization.level;
|
|
|
|
this.getAllUrl = "/api/services/app/User/GetAll";
|
|
|
|
this.CountsByOrganizations =
|
|
|
|
"/api/services/app/User/GetCountsByOrganizations";
|
|
|
|
this.getAllOrganization();
|
|
|
|
}
|
|
|
|
nzSelectedKeys: any[] = [];
|
|
|
|
defaultExpandedKeys = [];
|
|
|
|
IsContainsChildren = true;
|
|
|
|
searchValue = "";
|
|
|
|
totalCount: string;
|
|
|
|
//获取所有用户
|
|
|
|
usersLIst: any = [];
|
|
|
|
usersNum: string;
|
|
|
|
OrganizationUnitId;
|
|
|
|
loading: boolean;
|
|
|
|
organizationsList = [];
|
|
|
|
getAllUsers() {
|
|
|
|
this.loading = true;
|
|
|
|
let params = {
|
|
|
|
Keyword: this.validateForm.value.search
|
|
|
|
? this.validateForm.value.search
|
|
|
|
: "",
|
|
|
|
SkipCount: String(this.SkipCount),
|
|
|
|
MaxResultCount: String(this.MaxResultCount),
|
|
|
|
OrganizationUnitId: this.OrganizationUnitId,
|
|
|
|
IsContainsChildren: String(this.IsContainsChildren),
|
|
|
|
// Sorting: 'BuildingBasicInfo.Id asc'
|
|
|
|
};
|
|
|
|
this.http
|
|
|
|
.get(this.getAllUrl, {
|
|
|
|
params: params,
|
|
|
|
})
|
|
|
|
.subscribe((data: any) => {
|
|
|
|
this.usersLIst = data.result.items;
|
|
|
|
this.usersNum = data.result.totalCount;
|
|
|
|
this.loading = false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
SkipCount: number = 0; //0 16 32 48
|
|
|
|
MaxResultCount: number = 16;
|
|
|
|
pageChange($event) {
|
|
|
|
this.SkipCount = ($event - 1) * this.MaxResultCount;
|
|
|
|
this.getAllUsers();
|
|
|
|
}
|
|
|
|
|
|
|
|
//获取所有组织机构
|
|
|
|
nodes: any = [];
|
|
|
|
organization;
|
|
|
|
async getAllOrganization() {
|
|
|
|
let params = {
|
|
|
|
IsContainsChildren: "true",
|
|
|
|
};
|
|
|
|
await new Promise<void>((resolve, reject) => {
|
|
|
|
this.http
|
|
|
|
.get("/api/services/app/Organization/GetAll", {
|
|
|
|
params: params,
|
|
|
|
})
|
|
|
|
.subscribe(async (data: any) => {
|
|
|
|
this.organization = data.result.items;
|
|
|
|
await this.getuser(data.result.items);
|
|
|
|
resolve(data);
|
|
|
|
this.getAllUsers();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
async getuser(e) {
|
|
|
|
let userData = null;
|
|
|
|
if (sessionStorage.getItem("isGasStation") == "true") {
|
|
|
|
userData = JSON.parse(sessionStorage.getItem("userdataOfgasstation"));
|
|
|
|
} else {
|
|
|
|
userData = JSON.parse(sessionStorage.getItem("userdata"));
|
|
|
|
}
|
|
|
|
let OrganizationUnitId = userData.organization.id;
|
|
|
|
let OrganizationUnitIds = userData.organizations?.map((v) => v.id);
|
|
|
|
let params = {
|
|
|
|
OrganizationUnitId: OrganizationUnitId,
|
|
|
|
IsContainsChildren: "true",
|
|
|
|
IsUsersCountContainsChildren: String(this.IsContainsChildren),
|
|
|
|
};
|
|
|
|
await new Promise<void>((resolve, reject) => {
|
|
|
|
this.http
|
|
|
|
.get(this.CountsByOrganizations, {
|
|
|
|
params: params,
|
|
|
|
})
|
|
|
|
.subscribe((data: any) => {
|
|
|
|
resolve(data);
|
|
|
|
this.organizationsList = data.result;
|
|
|
|
const arrs = e.map((item) => {
|
|
|
|
const data = this.organizationsList.find(
|
|
|
|
(i) => item.id == i.organizationId
|
|
|
|
);
|
|
|
|
return {
|
|
|
|
...item,
|
|
|
|
products: data ? data : false,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
for (let index = 0; index < arrs.length; index++) {
|
|
|
|
if (OrganizationUnitIds && OrganizationUnitIds.length !== 0) {
|
|
|
|
if (OrganizationUnitIds.includes(arrs[index].id)) {
|
|
|
|
arrs[index].parentId = null;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (arrs[index].id == OrganizationUnitId) {
|
|
|
|
arrs[index].parentId = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
arrs[index].title = arrs[index].displayName;
|
|
|
|
arrs[index].key = arrs[index].id;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.nodes = [...this.toTree.toTree(arrs)];
|
|
|
|
this.defaultExpandedKeys = [this.nodes[0].id];
|
|
|
|
this.nzSelectedKeys = [this.nodes[0].id];
|
|
|
|
this.OrganizationUnitId = [this.nodes[0].id];
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
//搜索框提交
|
|
|
|
submitForm(): void {
|
|
|
|
for (const i in this.validateForm.controls) {
|
|
|
|
this.validateForm.controls[i].markAsDirty();
|
|
|
|
this.validateForm.controls[i].updateValueAndValidity();
|
|
|
|
}
|
|
|
|
this.getAllUsers();
|
|
|
|
}
|
|
|
|
nzClick(event: NzFormatEmitEvent) {
|
|
|
|
this.nzSelectedKeys[0] = event.node.origin.id;
|
|
|
|
this.nzSelectedKeys = [...this.nzSelectedKeys];
|
|
|
|
this.OrganizationUnitId = event.node.origin.id;
|
|
|
|
this.getAllUsers();
|
|
|
|
}
|
|
|
|
okbinding(item) {
|
|
|
|
this.modal.confirm({
|
|
|
|
nzTitle: "确定要绑定到此本地用户吗?",
|
|
|
|
nzOkText: "确定",
|
|
|
|
nzOkType: "primary",
|
|
|
|
nzOnOk: () => {
|
|
|
|
this.http
|
|
|
|
.post("/api/services/app/User/SetSinochemUserLocal", null, {
|
|
|
|
params: {
|
|
|
|
sinochemUserId: this.data.userId,
|
|
|
|
localUserId: item.id,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
.subscribe(() => {
|
|
|
|
this.message.create("success", "绑定成功");
|
|
|
|
});
|
|
|
|
},
|
|
|
|
nzCancelText: "取消",
|
|
|
|
nzOnCancel: () => console.log("Cancel"),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|