|
@@ -109,6 +109,7 @@ export class PageRoleComponent implements OnInit {
|
|
|
companyType: '',
|
|
|
};
|
|
|
userType: Array<string> = ['个人'];
|
|
|
+ parents: Array<any> = []; //所有一级列表
|
|
|
|
|
|
constructor(
|
|
|
public tbookSer: textbookServer,
|
|
@@ -119,51 +120,52 @@ export class PageRoleComponent implements OnInit {
|
|
|
private message: NzMessageService
|
|
|
) {
|
|
|
this.user = Parse.User.current();
|
|
|
- this.className = this.Department.className;
|
|
|
- this.fieldsArray = this.Department.fieldsArray;
|
|
|
- this.queryParams = {
|
|
|
- where: {
|
|
|
- // user:this.user?.toPointer(),
|
|
|
- isDeleted: { $ne: true },
|
|
|
- },
|
|
|
- };
|
|
|
+ // this.className = this.Department.className;
|
|
|
+ // this.fieldsArray = this.Department.fieldsArray;
|
|
|
+ // this.queryParams = {
|
|
|
+ // where: {
|
|
|
+ // // user:this.user?.toPointer(),
|
|
|
+ // isDeleted: { $ne: true },
|
|
|
+ // },
|
|
|
+ // };
|
|
|
}
|
|
|
|
|
|
ngOnInit(): void {
|
|
|
this.activeRoute.paramMap.subscribe(async (params) => {
|
|
|
- // let isDeleted = params.get('isDeleted');
|
|
|
- // if (isDeleted) {
|
|
|
- // this.queryParams.where['isDeleted'] = { $eq: true };
|
|
|
- // } else {
|
|
|
- // this.queryParams.where['isDeleted'] = { $ne: true };
|
|
|
- // }
|
|
|
- // this.list?.ngOnInit();
|
|
|
- if (!this.tbookSer.profile.user.department?.objectId) {
|
|
|
- this.message.warning('权限不足');
|
|
|
- history.back();
|
|
|
- return;
|
|
|
- }
|
|
|
- let query = new Parse.Query('Department')
|
|
|
- query.equalTo('objectId', this.tbookSer.profile.user.department?.objectId)
|
|
|
- query.select('hasChildren','branch')
|
|
|
- let r = await query.first()
|
|
|
-
|
|
|
- this.nodes = [
|
|
|
- {
|
|
|
- title: this.tbookSer.profile.user.department.name,
|
|
|
- key: this.tbookSer.profile.user.department?.objectId,
|
|
|
- children: [
|
|
|
- ...(await this.getDepart(
|
|
|
- this.tbookSer.profile.user.department?.objectId
|
|
|
- )),
|
|
|
- ],
|
|
|
- isParent: !r?.get('hasChildren'),
|
|
|
- isLeaf: !r?.get('hasChildren'),
|
|
|
- branch:r?.get('branch')
|
|
|
- },
|
|
|
- ];
|
|
|
+ this.refresh();
|
|
|
});
|
|
|
}
|
|
|
+ async refresh() {
|
|
|
+ if (!this.tbookSer.profile.user.department?.objectId) {
|
|
|
+ this.message.warning('权限不足');
|
|
|
+ history.back();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ let query = new Parse.Query('Department');
|
|
|
+ query.equalTo('objectId', this.tbookSer.profile.user.department?.objectId);
|
|
|
+ query.select('code', 'name', 'branch', 'parent', 'type', 'hasChildren');
|
|
|
+ let r = await query.first();
|
|
|
+ this.nodes = [
|
|
|
+ {
|
|
|
+ title: this.tbookSer.profile.user.department.name,
|
|
|
+ key: this.tbookSer.profile.user.department?.objectId,
|
|
|
+ children: [
|
|
|
+ ...(await this.getDepart(
|
|
|
+ this.tbookSer.profile.user.department?.objectId
|
|
|
+ )),
|
|
|
+ ],
|
|
|
+ isParent: !r?.get('hasChildren'),
|
|
|
+ isLeaf: !r?.get('hasChildren'),
|
|
|
+ branch: r?.get('branch'),
|
|
|
+ parent: r?.get('parent')?.id, //上级
|
|
|
+ type: r?.get('branch'),
|
|
|
+ },
|
|
|
+ ];
|
|
|
+ let query2 = new Parse.Query('Department');
|
|
|
+ query2.select('name');
|
|
|
+ query2.equalTo('parent', null);
|
|
|
+ this.parents = await query2.find();
|
|
|
+ }
|
|
|
async getDepart(
|
|
|
parent?: string,
|
|
|
searchValue?: string,
|
|
@@ -176,12 +178,12 @@ export class PageRoleComponent implements OnInit {
|
|
|
}
|
|
|
searchValue && query.contains('name', searchValue);
|
|
|
query.notEqualTo('isDeleted', true);
|
|
|
- query.select('code', 'name', 'branch', 'parent', 'type','hasChildren');
|
|
|
+ query.select('code', 'name', 'branch', 'parent', 'type', 'hasChildren');
|
|
|
query.descending('createdAt');
|
|
|
- query.equalTo('branch',this.tbookSer.profile.companyType)
|
|
|
+ query.equalTo('branch', this.tbookSer.profile.companyType);
|
|
|
console.log(searchValue);
|
|
|
- if(searchValue && searchValue != undefined){
|
|
|
- query.equalTo('parent',this.tbookSer.profile.user.department?.objectId)
|
|
|
+ if (searchValue && searchValue != undefined) {
|
|
|
+ query.equalTo('parent', this.tbookSer.profile.user.department?.objectId);
|
|
|
}
|
|
|
query.limit(100);
|
|
|
if (this.activeDepart) query.notEqualTo('objectId', this.activeDepart?.id);
|
|
@@ -192,7 +194,9 @@ export class PageRoleComponent implements OnInit {
|
|
|
key: item.id,
|
|
|
children: [],
|
|
|
branch: item.get('branch'),
|
|
|
+ parent: item.get('parent')?.id, //上级
|
|
|
isLeaf: !item.get('hasChildren') ? true : false, //是否是最下级
|
|
|
+ type: item.get('type'),
|
|
|
});
|
|
|
});
|
|
|
return nodes;
|
|
@@ -207,6 +211,7 @@ export class PageRoleComponent implements OnInit {
|
|
|
}
|
|
|
//添加成员
|
|
|
addMember() {
|
|
|
+ this.radio = ''
|
|
|
this.parentList = this.nodes;
|
|
|
this.account = {
|
|
|
name: '',
|
|
@@ -232,7 +237,6 @@ export class PageRoleComponent implements OnInit {
|
|
|
let data = await this.getDepart(node.key);
|
|
|
node.addChildren(data);
|
|
|
}
|
|
|
- console.log(this.nodes);
|
|
|
} else {
|
|
|
// if (node.origin.isParent) {
|
|
|
this.currentDepart = node.origin;
|
|
@@ -313,6 +317,7 @@ export class PageRoleComponent implements OnInit {
|
|
|
}
|
|
|
//新建打开弹窗
|
|
|
async showModalDepart(type: string) {
|
|
|
+ this.radio = ''
|
|
|
this.parentList = this.nodes;
|
|
|
this.editObject = {
|
|
|
name: '',
|
|
@@ -365,7 +370,7 @@ export class PageRoleComponent implements OnInit {
|
|
|
//格式化链
|
|
|
async formatNode(id: string): Promise<Array<any>> {
|
|
|
let query = new Parse.Query('Department');
|
|
|
- query.select('name', 'parent','hasChildren');
|
|
|
+ query.select('name', 'parent', 'hasChildren');
|
|
|
let r = await query.get(id);
|
|
|
let arr = [
|
|
|
{
|
|
@@ -380,25 +385,42 @@ export class PageRoleComponent implements OnInit {
|
|
|
return arr;
|
|
|
}
|
|
|
async onPre(data?: any, index?: number) {
|
|
|
+ console.log(data);
|
|
|
if (!data?.key || !data.hasChildren) {
|
|
|
// this.parentList = await this.getDepart();
|
|
|
// this.parentMap = []
|
|
|
return;
|
|
|
}
|
|
|
// if(index == this.parentMap.length-1) return
|
|
|
- if (index !== 0 && !index) this.parentMap.splice(index || 0 + 1);
|
|
|
+ this.parentMap.splice((index || 0) + 1);
|
|
|
this.parentList = await this.getDepart(data?.key);
|
|
|
}
|
|
|
//选择所属类别下级列表
|
|
|
async onCheckedDepart(type: string, e: any, checked?: boolean) {
|
|
|
this.radio = e.key;
|
|
|
console.log(e);
|
|
|
+ if (type == 'account') this.account.identity = '';
|
|
|
this.parentMap = await this.formatNode(e.key);
|
|
|
+ let index = this.parentMap.findIndex(
|
|
|
+ (item) => this.tbookSer.profile.user.department?.objectId == item.key
|
|
|
+ );
|
|
|
+ if (index != -1) {
|
|
|
+ this.parentMap.forEach((item, i) => {
|
|
|
+ if (i >= index) {
|
|
|
+ this.parentMap[i].verify = true;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
if (checked) {
|
|
|
// this.editObject.name = e.title
|
|
|
if (type == 'account') {
|
|
|
this.account.department = { title: e.title, id: e.key };
|
|
|
this.account.companyType = e.branch || e.title;
|
|
|
+ this.userType = this.parents.some((item) => e.parent == item.id)
|
|
|
+ ? ['评审专家', '个人']
|
|
|
+ : e.type
|
|
|
+ ? ['评审专家', '高校联系人', '个人']
|
|
|
+ : ['评审专家', '个人'];
|
|
|
} else {
|
|
|
this.editObject.parent = {
|
|
|
title: e.title,
|
|
@@ -411,10 +433,6 @@ export class PageRoleComponent implements OnInit {
|
|
|
if (e.isLeaf) {
|
|
|
return;
|
|
|
}
|
|
|
- // this.parentMap.push({
|
|
|
- // title: e.title,
|
|
|
- // key: e.key,
|
|
|
- // });
|
|
|
this.parentList = await this.getDepart(e?.key);
|
|
|
}
|
|
|
async handleOk(): Promise<void> {
|
|
@@ -446,22 +464,22 @@ export class PageRoleComponent implements OnInit {
|
|
|
this.activeDepart?.set('branch', this.editObject.branch);
|
|
|
}
|
|
|
await this.activeDepart?.save();
|
|
|
- await this.updateChildren()
|
|
|
+ await this.updateChildren();
|
|
|
this.isVisible = false;
|
|
|
this.message.success(this.editType == 'edit' ? '保存' : '添加' + '成功');
|
|
|
this.activeDepart = undefined;
|
|
|
- this.ngOnInit()
|
|
|
+ this.ngOnInit();
|
|
|
}
|
|
|
//更新上级children字段
|
|
|
- async updateChildren(){
|
|
|
- let query = new Parse.Query('Department')
|
|
|
- query.equalTo('objectId', this.editObject.parent?.id)
|
|
|
- let r = await query.first()
|
|
|
- if(r?.id && !r.get('hasChildren')){
|
|
|
- r?.set('hasChildren', true)
|
|
|
- await r.save()
|
|
|
+ async updateChildren() {
|
|
|
+ let query = new Parse.Query('Department');
|
|
|
+ query.equalTo('objectId', this.editObject.parent?.id);
|
|
|
+ let r = await query.first();
|
|
|
+ if (r?.id && !r.get('hasChildren')) {
|
|
|
+ r?.set('hasChildren', true);
|
|
|
+ await r.save();
|
|
|
}
|
|
|
- return
|
|
|
+ return;
|
|
|
}
|
|
|
handleCancel(): void {
|
|
|
console.log('Button cancel clicked!');
|
|
@@ -481,18 +499,7 @@ export class PageRoleComponent implements OnInit {
|
|
|
this.route.navigate(['/nav-admin/manage/user/edit', { id: id }]);
|
|
|
}
|
|
|
randomPassword() {
|
|
|
- let sCode =
|
|
|
- 'A,B,C,E,F,G,H,J,K,L,M,N,P,Q,R,S,T,W,X,Y,Z,1,2,3,4,5,6,7,8,9,0,q,w,e,r,t,y,u,i,o,p,a,s,d,f,g,h,j,k,l,z,x,c,v,b,n,m';
|
|
|
- let aCode = sCode.split(',');
|
|
|
- let aLength = aCode.length; //获取到数组的长度
|
|
|
- let str = [];
|
|
|
- for (let i = 0; i <= 16; i++) {
|
|
|
- let j = Math.floor(Math.random() * aLength); //获取到随机的索引值
|
|
|
- let txt = aCode[j]; //得到随机的一个内容
|
|
|
- str.push(txt);
|
|
|
- }
|
|
|
- this.account.password = str.join('');
|
|
|
- console.log(this.account.password);
|
|
|
+ this.account.password = this.tbookSer.randomPassword();
|
|
|
}
|
|
|
/* 添加账号 */
|
|
|
async accountComplete() {
|
|
@@ -513,13 +520,19 @@ export class PageRoleComponent implements OnInit {
|
|
|
this.message.error('请填写正确手机号');
|
|
|
return;
|
|
|
}
|
|
|
+ this.account.email = this.account?.email.trim();
|
|
|
+ this.account.phone = this.account?.phone.trim();
|
|
|
+ if (!this.account?.email && !this.account?.phone) {
|
|
|
+ this.message.error('邮箱或手机号必须填写一项');
|
|
|
+ return;
|
|
|
+ }
|
|
|
try {
|
|
|
let obj = Parse.Object.extend('_User');
|
|
|
let user = new obj();
|
|
|
- user?.set('username', this.account?.email);
|
|
|
+ user?.set('username', this.account?.email || this.account?.phone);
|
|
|
user?.set('name', this.account?.name);
|
|
|
user?.set('phone', this.account?.phone);
|
|
|
- user?.set('email', this.account?.email);
|
|
|
+ this.account?.email && user?.set('email', this.account?.email);
|
|
|
user?.set('password', this.account.password);
|
|
|
user?.set('accountState', '已认证');
|
|
|
user?.set('department', {
|