|
@@ -83,6 +83,8 @@ export class UserEditComponent implements OnInit {
|
|
|
};
|
|
|
userType: Array<string> = ['教师', '评审专家', '高校联系人', '工作联系人'];
|
|
|
provinces: Array<string> = provinces.options; //省份
|
|
|
+ depTitle:string = '' //关联部门标题
|
|
|
+ radio:string = ''
|
|
|
|
|
|
constructor(
|
|
|
public tbookSer: textbookServer,
|
|
@@ -116,10 +118,15 @@ export class UserEditComponent implements OnInit {
|
|
|
queryProfile.equalTo('user', id);
|
|
|
this.profile = await queryProfile.first();
|
|
|
this.profileJson = this.profile.toJSON();
|
|
|
- this.userJson.email = this.profileJson.email
|
|
|
+ this.userJson.email = this.profileJson.email;
|
|
|
this.userDataJson = {
|
|
|
companyType: this.profile?.get('companyType'),
|
|
|
- department: this.user.get('department'),
|
|
|
+ department: {
|
|
|
+ id: this.user.get('department')?.id,
|
|
|
+ name: this.user.get('department')?.get('name'),
|
|
|
+ branch: this.user.get('department')?.get('branch'),
|
|
|
+ },
|
|
|
+ node: await this.tbookSer.formatNode(this.user.get('department')?.id),
|
|
|
};
|
|
|
}
|
|
|
await this.getUnitTypes();
|
|
@@ -130,9 +137,12 @@ export class UserEditComponent implements OnInit {
|
|
|
this.tbookSer.profile.identity == '工作联系人' &&
|
|
|
arr.includes(this.profile.get('identity'))
|
|
|
) {
|
|
|
- if(this.tbookSer.profile.companyType == '省级教育行政部门' || this.tbookSer.profile.companyType == '有关部门(单位)教育司(局)'){
|
|
|
+ if (
|
|
|
+ this.tbookSer.profile.companyType == '省级教育行政部门' ||
|
|
|
+ this.tbookSer.profile.companyType == '有关部门(单位)教育司(局)'
|
|
|
+ ) {
|
|
|
this.userType = ['教师', '评审专家', '高校联系人'];
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
this.userType = ['教师', '评审专家'];
|
|
|
}
|
|
|
this.edit = true;
|
|
@@ -189,7 +199,7 @@ export class UserEditComponent implements OnInit {
|
|
|
case '删除':
|
|
|
await this.profile.destroy();
|
|
|
await this.user.destroy();
|
|
|
- this.goUserList()
|
|
|
+ this.goUserList();
|
|
|
break;
|
|
|
}
|
|
|
this.ngOnInit();
|
|
@@ -220,6 +230,8 @@ export class UserEditComponent implements OnInit {
|
|
|
//切换单位类型
|
|
|
onChangeType() {
|
|
|
this.userDataJson.department = null;
|
|
|
+ this.depTitle = ''
|
|
|
+ this.radio = ''
|
|
|
}
|
|
|
//选择部门
|
|
|
async showModalDepart() {
|
|
@@ -227,16 +239,23 @@ export class UserEditComponent implements OnInit {
|
|
|
this.message.warning('同级身份暂无权限操作');
|
|
|
return;
|
|
|
}
|
|
|
+ this.depTitle = this.userDataJson.department.name
|
|
|
+ this.radio = this.userDataJson.department.id
|
|
|
if (this.unitTypes.length == 0) {
|
|
|
await this.getUnitTypes();
|
|
|
}
|
|
|
- let parent = this.unitTypes.find(
|
|
|
- (item) => item.name == this.userDataJson.companyType
|
|
|
+ this.parentMap = await this.tbookSer.formatNode(this.user?.get('department')?.id);
|
|
|
+ let index = this.parentMap.findIndex(
|
|
|
+ (item) => this.tbookSer.profile.user.department?.objectId == item.key
|
|
|
);
|
|
|
- if (parent?.id) {
|
|
|
- this.parentMap = await this.formatNode(parent.id);
|
|
|
+ if (index != -1) {
|
|
|
+ this.parentMap.forEach((item, i) => {
|
|
|
+ if (i >= index) {
|
|
|
+ this.parentMap[i].verify = true;
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
- this.provinceChange(this.parentMap[this.parentMap.length - 1]?.id);
|
|
|
+ this.getDepart(this.parentMap[this.parentMap.length - 1]?.id);
|
|
|
this.isShowModal = true;
|
|
|
}
|
|
|
async getUnitTypes() {
|
|
@@ -251,81 +270,144 @@ export class UserEditComponent implements OnInit {
|
|
|
});
|
|
|
}
|
|
|
//根据所选单位类型获取对应单位
|
|
|
- async provinceChange(id?: string, val?: string) {
|
|
|
+ async getDepart(parent?: string, val?: string) {
|
|
|
let query = new Parse.Query('Department');
|
|
|
- query.select('name', 'branch', 'parent');
|
|
|
- if (this.tbookSer.profile.identity != '国家级管理员') {
|
|
|
- query.equalTo(
|
|
|
- 'objectId',
|
|
|
- this.tbookSer.profile?.user.department?.objectId
|
|
|
- );
|
|
|
- }
|
|
|
- if (this.tbookSer.profile.identity == '国家级管理员' || id) {
|
|
|
- query.equalTo('parent', id ? id : null);
|
|
|
- }
|
|
|
+ query.equalTo(
|
|
|
+ 'parent',
|
|
|
+ val
|
|
|
+ ? this.parentMap[this.parentMap.length - 1]?.key
|
|
|
+ : parent
|
|
|
+ ? parent
|
|
|
+ : this.tbookSer.profile.identity != '国家级管理员'
|
|
|
+ ? this.tbookSer.profile.user.department?.objectId
|
|
|
+ : null
|
|
|
+ );
|
|
|
+ query.select('code', 'name', 'branch', 'parent', 'type', 'hasChildren');
|
|
|
query.limit(100);
|
|
|
+ query.descending('createdAt');
|
|
|
+ query.notEqualTo('isDeleted', true);
|
|
|
val && query.contains('name', val);
|
|
|
- let r = await query.find();
|
|
|
- this.parentList = r;
|
|
|
- }
|
|
|
-
|
|
|
- async formatNode(id: string): Promise<Array<any>> {
|
|
|
- let arr = [];
|
|
|
- if (id) {
|
|
|
- let query = new Parse.Query('Department');
|
|
|
- query.equalTo('objectId', id);
|
|
|
- query.select('parent', 'name');
|
|
|
- let r = await query.first();
|
|
|
- arr.push({
|
|
|
- title: r?.get('name'),
|
|
|
- id: r?.id,
|
|
|
+ let res = await query.find();
|
|
|
+ let nodes: any = [];
|
|
|
+ res.forEach((item) => {
|
|
|
+ nodes.push({
|
|
|
+ title: item.get('name'),
|
|
|
+ key: item.id,
|
|
|
+ id: item.id,
|
|
|
+ branch: item.get('branch'),
|
|
|
+ parent: item.get('parent')?.id, //上级
|
|
|
+ isLeaf: !item.get('hasChildren'), //是否是最下级
|
|
|
+ type: item.get('type'),
|
|
|
});
|
|
|
- if (r?.get('parent')) {
|
|
|
- arr.unshift(...(await this.formatNode(r?.get('parent')?.id)));
|
|
|
- }
|
|
|
- }
|
|
|
- return arr;
|
|
|
+ });
|
|
|
+ this.parentList = nodes;
|
|
|
}
|
|
|
- onCheck(e: any) {
|
|
|
- console.log(e);
|
|
|
+ async onPre(data?: any, index?: number) {
|
|
|
+ if (!data) {
|
|
|
+ this.userDataJson.department = undefined;
|
|
|
+ this.depTitle = ''
|
|
|
+ this.radio = ''
|
|
|
+ await this.getDepart();
|
|
|
+ this.parentMap = [];
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (index == this.parentMap.length - 1) {
|
|
|
+ if (this.parentList.length == 0) await this.getDepart(data?.key);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this.parentMap.splice((index || 0) + 1);
|
|
|
this.userDataJson.department = undefined;
|
|
|
- this.provinceChange();
|
|
|
+ this.depTitle = ''
|
|
|
+ this.radio = ''
|
|
|
+ await this.getDepart(data?.key);
|
|
|
}
|
|
|
- parent: string = ''; //搜索时传入的id
|
|
|
//选择部门
|
|
|
- async onCheckedDepart(e: any) {
|
|
|
- console.log(e);
|
|
|
- if (e?.get('parent')?.id) {
|
|
|
- this.userDataJson.department = e;
|
|
|
- this.parent = e?.get('parent')?.id;
|
|
|
- } else {
|
|
|
- this.provinceChange(e.id);
|
|
|
- this.parent = e?.id;
|
|
|
+ async onCheckedDepart(e: any, checked?: boolean) {
|
|
|
+ console.log(e, checked);
|
|
|
+ this.userDataJson.department = null;
|
|
|
+ this.depTitle = ''
|
|
|
+ this.parentMap = await this.tbookSer.formatNode(e.id);
|
|
|
+ if (this.tbookSer.profile.identity != '国家级管理员') {
|
|
|
+ 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 && e.branch) {
|
|
|
+ this.pushValue(e);
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (e.isLeaf) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this.radio = ''
|
|
|
+ await this.getDepart(e?.key);
|
|
|
+ }
|
|
|
+ pushValue(e: any) {
|
|
|
+ this.userDataJson.department = {
|
|
|
+ name: e.title,
|
|
|
+ branch: e.branch,
|
|
|
+ title: e.title,
|
|
|
+ id: e.key,
|
|
|
+ };
|
|
|
+ this.depTitle = e.title
|
|
|
+ console.log(this.depTitle);
|
|
|
+ this.radio = e.key
|
|
|
+ if (this.tbookSer.profile.identity == '国家级管理员') {
|
|
|
+ this.userType = this.unitTypes.some((item) => e.parent == item.id)
|
|
|
+ ? !e.type
|
|
|
+ ? ['工作联系人']
|
|
|
+ : ['评审专家', '工作联系人', '教师']
|
|
|
+ : e.type == '单位'
|
|
|
+ ? ['评审专家', '高校联系人', '教师']
|
|
|
+ : ['评审专家', '教师'];
|
|
|
+ } else if (this.tbookSer.profile.identity == '工作联系人') {
|
|
|
+ this.userType = this.unitTypes.some((item) => e.parent == item.id)
|
|
|
+ ? !e.type
|
|
|
+ ? ['评审专家', '教师', '高校联系人']
|
|
|
+ : ['评审专家', '教师']
|
|
|
+ : e.type == '单位'
|
|
|
+ ? ['评审专家', '高校联系人', '教师']
|
|
|
+ : ['评审专家', '教师'];
|
|
|
}
|
|
|
- this.parentMap = await this.formatNode(e.id);
|
|
|
}
|
|
|
- handleCancel(): void {
|
|
|
- console.log('Button cancel clicked!');
|
|
|
+
|
|
|
+ async handleCancel() {
|
|
|
this.userDataJson = {
|
|
|
companyType: this.profile?.get('companyType'),
|
|
|
- department: this.user.get('department'),
|
|
|
+ department: {
|
|
|
+ id: this.user.get('department')?.id,
|
|
|
+ name: this.user.get('department')?.get('name'),
|
|
|
+ branch: this.user.get('department')?.get('branch'),
|
|
|
+ },
|
|
|
+ node: await this.tbookSer.formatNode(this.user.get('department')?.id),
|
|
|
};
|
|
|
+ this.depTitle = ''
|
|
|
+ this.radio = ''
|
|
|
this.isShowModal = false;
|
|
|
- this.parent = '';
|
|
|
}
|
|
|
async completeChange(): Promise<void> {
|
|
|
if (!this.userDataJson.department?.id) {
|
|
|
this.message.warning('请选择部门');
|
|
|
return;
|
|
|
}
|
|
|
- this.userDataJson.companyType = this.userDataJson.department.get('branch');
|
|
|
+ this.userDataJson.companyType = this.userDataJson.department?.branch;
|
|
|
this.profile?.set('companyType', this.userDataJson.companyType);
|
|
|
await this.profile?.save();
|
|
|
- this.user?.set('department', this.userDataJson.department?.toPointer());
|
|
|
+ this.user?.set('department', {
|
|
|
+ __type: 'Pointer',
|
|
|
+ className: 'Department',
|
|
|
+ objectId: this.userDataJson.department?.id,
|
|
|
+ });
|
|
|
await this.user?.save();
|
|
|
this.ngOnInit();
|
|
|
this.isShowModal = false;
|
|
|
- this.parent = '';
|
|
|
}
|
|
|
openUrl(url: string) {
|
|
|
if (!/\.(jpg|jpeg|png|GIF|JPG|PNG)$/.test(url)) {
|
|
@@ -344,7 +426,7 @@ export class UserEditComponent implements OnInit {
|
|
|
}
|
|
|
/* 修改账号 */
|
|
|
loading: boolean = false;
|
|
|
- submitForm(type: string) {
|
|
|
+ async submitForm(type: string) {
|
|
|
if (this.loading) return;
|
|
|
this.loading = true;
|
|
|
if (type == 'save') {
|
|
@@ -354,8 +436,15 @@ export class UserEditComponent implements OnInit {
|
|
|
this.profileJson = this.profile.toJSON();
|
|
|
this.userDataJson = {
|
|
|
companyType: this.profile?.get('companyType'),
|
|
|
- department: this.user.get('department'),
|
|
|
+ department: {
|
|
|
+ id: this.user.get('department')?.id,
|
|
|
+ name: this.user.get('department')?.get('name'),
|
|
|
+ branch: this.user.get('department')?.get('branch'),
|
|
|
+ },
|
|
|
+ node: await this.tbookSer.formatNode(this.user.get('department')?.id),
|
|
|
};
|
|
|
+ this.depTitle = this.user.get('department')?.get('name')
|
|
|
+ this.radio = this.user.get('department')?.id
|
|
|
this.loading = false;
|
|
|
}
|
|
|
}
|