Files
airport-chengdu-web/src/app/pages/system-management/user-management/user-management.component.ts
T

198 lines
5.5 KiB
TypeScript
Raw Normal View History

2018-10-29 16:27:34 +08:00
import { Component, OnInit } from '@angular/core';
2018-11-15 18:29:55 +08:00
import { HttpClientService } from '../../../services/http-client.service';
2018-11-20 18:29:13 +08:00
import { Router } from '@angular/router';
2018-11-21 17:58:12 +08:00
import { NzMessageService } from 'ng-zorro-antd';
2018-11-15 18:29:55 +08:00
import 'ztree';
2018-11-29 18:08:54 +08:00
declare var $: any;
2018-11-15 18:29:55 +08:00
declare var jQuery: any;
2018-10-29 16:27:34 +08:00
@Component({
selector: 'app-user-management',
templateUrl: './user-management.component.html',
2018-11-29 18:08:54 +08:00
styleUrls: ['./user-management.component.scss',]
2018-10-29 16:27:34 +08:00
})
export class UserManagementComponent implements OnInit {
2018-11-15 18:29:55 +08:00
treeSelected:any; //树模型-当前选中项
2018-11-19 20:58:55 +08:00
collectionSize:any ;
2018-11-20 18:29:13 +08:00
public tableData:any=[];
2018-11-19 20:58:55 +08:00
statusParamsTable:any={ //获取目录树接口的状态,0请求失败 1请求前 2请求中 3请求成功,有数据 4请求成功,无数据
status:1,
}
statusParamsTree:any={ //获取机构接口的状态,0请求失败 1请求前 2请求中 3请求成功,有数据 4请求成功,无数据
status:1,
}
2018-11-20 18:29:13 +08:00
statusParamsDetail:any={ //获取用户详情接口的状态,0请求失败 1请求前 2请求中 3请求成功,有数据 4请求成功,无数据
status:1,
}
2018-11-15 18:29:55 +08:00
public search:any={
page_index:'1',
page_size:'10',
real_name:'',
login_name:'',
2018-11-19 20:58:55 +08:00
orgId:'',
2018-11-15 18:29:55 +08:00
}
2018-11-20 18:29:13 +08:00
visible = false;
userDetail:any={}; //用户详情
2018-10-29 16:27:34 +08:00
2018-11-15 18:29:55 +08:00
constructor(
private http:HttpClientService,
2018-11-20 18:29:13 +08:00
private router:Router,
2018-11-21 17:58:12 +08:00
private message: NzMessageService,
2018-11-15 18:29:55 +08:00
) { }
2018-10-29 16:27:34 +08:00
2018-11-15 18:29:55 +08:00
ngOnInit() {
2018-11-29 18:08:54 +08:00
// 页面监听 动态改变表单高度
$('#tree-box').css('height',(document.documentElement.clientHeight-106+'px'));
$('#main-box').css('height',(document.documentElement.clientHeight-106+'px'));
$(window).resize(function(){
$('#tree-box').css('height',(document.documentElement.clientHeight-106+'px'));
$('#main-box').css('height',(document.documentElement.clientHeight-106+'px'));
})
2018-11-15 18:29:55 +08:00
this.initTree();
2018-11-19 20:58:55 +08:00
this.queryTable();
2018-11-21 17:58:12 +08:00
}
//删除
delectConfirm(item){
this.http.delete('/sysapi/setting/user/deleteById/'+item.uid).subscribe((json)=>{
if(json.is_success){
this.message.success(`删除成功!`);
this.queryTable();
}else{
this.message.error(`删除失败`)
}
})
}
//取消删除
delectCancel(){
2018-11-19 20:58:55 +08:00
}
2018-11-20 18:29:13 +08:00
//新增、修改 1新增 2修改
addModify(type,item?){
if(type==1){
this.router.navigate(['app/system/users/modify'],{queryParams:{operateType:1}})
}else if(type==2){
2018-11-21 17:58:12 +08:00
this.router.navigate(['app/system/users/modify'],{queryParams:{operateType:2,id:item.uid}})
2018-11-20 18:29:13 +08:00
}
}
//打开详情页面
open(item): void {
this.statusParamsDetail.status=1;
this.visible = true;
this.userDetail={};
this.http.get('/sysapi/setting/user/detail/list', { uid: item.uid }).subscribe((json)=>{
if(json.is_success){
if(json.body){
this.statusParamsDetail.status=3;
this.userDetail=json.body;
}else{
this.statusParamsDetail.status=4;
}
}else{
this.statusParamsDetail.status=0;
}
})
}
//关闭详情页面
close(): void {
this.visible = false;
}
//重置,重置搜索条件
reset(){
this.search.page_index=1;
this.search.page_size=10;
this.search.real_name='';
this.search.login_name='';
this.queryTable();
}
2018-11-19 20:58:55 +08:00
//获取列表
queryTable():void{
this.statusParamsTable.status=1;
this.http.get('/sysapi/setting/user/list',this.search).subscribe((json)=>{
if(json.is_success){
this.tableData=json.body.list;
this.collectionSize=json.body.total;
2018-11-20 18:29:13 +08:00
if(json.body.list&&json.body.list.length>0){
this.statusParamsTable.status=3;
}else{
this.statusParamsTable.status=4;
}
2018-11-19 20:58:55 +08:00
}else{
this.statusParamsTable.status=0;
}
})
2018-11-15 18:29:55 +08:00
}
2018-11-20 18:29:13 +08:00
//翻页
pageChange(event){
this.search.page_index=event;
this.queryTable();
}
2018-11-15 18:29:55 +08:00
//树模型参数设置
public zNodes: any[];
setting = {
data: {
simpleData: {
2018-11-19 20:58:55 +08:00
enable: true
2018-11-15 18:29:55 +08:00
}
},
view: {
2018-11-19 20:58:55 +08:00
showLine: true,
2018-11-15 18:29:55 +08:00
dblClickExpand: false,
showIcon:true
},
callback: {
//节点点击事件
onClick: (event, treeId, treeNode, clickFlag) => {
var zTree = $.fn.zTree.getZTreeObj("treeDemo");
this.treeSelected=treeNode;
2018-11-19 20:58:55 +08:00
let isTopNode=this.treeSelected.getParentNode(); //是否为顶级节点 true不是顶级节点 false 为顶级节点
if(isTopNode){ //子节点
this.search.orgId=this.treeSelected.id;
}else{ //顶级节点
this.search.orgId='';
2018-11-15 18:29:55 +08:00
}
2018-11-19 20:58:55 +08:00
this.queryTable();
2018-11-15 18:29:55 +08:00
},
},
};
2018-11-20 18:29:13 +08:00
//获取机构列表,树模型数据处理
2018-11-15 18:29:55 +08:00
initTree(){
//获取目录列表
2018-11-19 20:58:55 +08:00
this.statusParamsTree.status=1;
2018-11-15 18:29:55 +08:00
this.http.get("/sysapi/setting/organization/list",).subscribe(json=>{
2018-11-19 20:58:55 +08:00
if(json.is_success){
if(json.body.length>0){
this.statusParamsTree.status=3;
let children=[];
2018-11-29 18:08:54 +08:00
json.body.forEach(option=>{
2018-11-19 20:58:55 +08:00
option.name=option.organization;
if(option.pid){
option.pId=option.pid;
}else{
option.pId='hsfuhiw34239j89sauf98992h3indshv98h392hf9mplsd032fs2a2313fc';
}
2018-11-29 18:08:54 +08:00
});
2018-11-19 20:58:55 +08:00
json.body.push({
name:"全部机构",
isParent:true,
open:true,
id:'hsfuhiw34239j89sauf98992h3indshv98h392hf9mplsd032fs2a2313fc',
})
}else{
//数据为空
this.statusParamsTree.status=4;
2018-11-15 18:29:55 +08:00
}
2018-11-19 20:58:55 +08:00
}else{
//请求失败
this.statusParamsTree.status=0;
2018-11-15 18:29:55 +08:00
}
this.zNodes=json.body;
$.fn.zTree.init($("#treeDemo"), this.setting, this.zNodes);
var zTree = $.fn.zTree.getZTreeObj("treeDemo");
let node = zTree.getNodes();
})
}
2018-10-29 16:27:34 +08:00
}