page-user.component.ts 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. import { Component, OnInit, ViewChild } from '@angular/core';
  2. import { ActivatedRoute, Router, RouterOutlet } from '@angular/router';
  3. import { CompTableListComponent } from '../../../app/comp-table/comp-table-list/comp-table-list.component';
  4. // import _User from '../../../schemas/_User';
  5. import * as Parse from 'parse';
  6. import { CommonModule } from '@angular/common';
  7. import { NzPageHeaderModule } from 'ng-zorro-antd/page-header';
  8. import { NzBreadCrumbModule } from 'ng-zorro-antd/breadcrumb';
  9. import { NzSpaceModule } from 'ng-zorro-antd/space';
  10. import { CommonCompModule } from '../../../services/common.modules';
  11. // import { Profile } from '../../../schemas/Profile-list';
  12. import { NzEmptyModule } from 'ng-zorro-antd/empty';
  13. import { NzModalService } from 'ng-zorro-antd/modal';
  14. import { textbookServer } from '../../../services/textbook';
  15. import { NzMessageService } from 'ng-zorro-antd/message';
  16. @Component({
  17. selector: 'app-page-user',
  18. templateUrl: './page-user.component.html',
  19. styleUrls: ['./page-user.component.scss'],
  20. imports: [
  21. CommonModule,
  22. RouterOutlet,
  23. NzSpaceModule,
  24. NzPageHeaderModule,
  25. CompTableListComponent,
  26. NzBreadCrumbModule,
  27. CommonCompModule,
  28. NzEmptyModule,
  29. ],
  30. standalone: true,
  31. })
  32. export class PageUserComponent implements OnInit {
  33. @ViewChild(CompTableListComponent) list: CompTableListComponent | undefined;
  34. // _User = _User;
  35. // ProfileList = Profile;
  36. // className: string | undefined;
  37. // queryParams: any | undefined;
  38. // fieldsArray: Array<any> | undefined;
  39. user: Parse.User | undefined;
  40. profiles: Array<Parse.Object> = [];
  41. profileLength: number = 0; //总数据
  42. pageSize: number = 10;
  43. pageIndex: number = 1;
  44. checkedAll: boolean = false; //全选
  45. indeterminate = false;
  46. loading = false;
  47. searchValue: string = ''; //搜索内容
  48. setOfCheckedId = new Set<string>();
  49. constructor(
  50. public tbookSer: textbookServer,
  51. private modal: NzModalService,
  52. private route: Router,
  53. private message: NzMessageService,
  54. private activeRoute: ActivatedRoute
  55. ) {
  56. this.user = Parse.User.current();
  57. // this.className = this.ProfileList.className;
  58. // this.fieldsArray = this.ProfileList.fieldsArray;
  59. // this.queryParams = {
  60. // where: {
  61. // // user:this.user?.toPointer(),
  62. // isDeleted: { $ne: true },
  63. // },
  64. // };
  65. }
  66. ngOnInit(): void {
  67. this.activeRoute.paramMap.subscribe(async (params) => {
  68. this.getProfile();
  69. });
  70. }
  71. async getProfile() {
  72. this.profiles = [];
  73. this.loading = true;
  74. let queryParams: any = {
  75. where: {
  76. $or: [
  77. {
  78. user: {
  79. $inQuery: {
  80. where: {
  81. $or: [
  82. {
  83. name: { $regex: `.*${this.searchValue}.*` },
  84. },
  85. {
  86. username: { $regex: `.*${this.searchValue}.*` },
  87. },
  88. {
  89. phone: { $regex: `.*${this.searchValue}.*` },
  90. },
  91. {
  92. email: { $regex: `.*${this.searchValue}.*` },
  93. },
  94. ],
  95. },
  96. className: '_User',
  97. },
  98. },
  99. }
  100. ],
  101. },
  102. };
  103. if (
  104. this.tbookSer.profile.identity != '国家级管理员'
  105. ) {
  106. this.tbookSer.profile.user.department;
  107. queryParams['where']['$or'][0]['user']['$inQuery']['where'][
  108. 'department'
  109. ] = {
  110. $eq: this.tbookSer.profile.user.department?.objectId,
  111. };
  112. }
  113. let query = Parse.Query.fromJSON('Profile', queryParams);
  114. query.include('user');
  115. query.notEqualTo('identity', '国家级管理员');
  116. query.descending('createdAt')
  117. if(this.tbookSer.profile.identity == '工作联系人'){
  118. query.containedIn('identity', ['个人', '评审专家','高校联系人']);
  119. }else if(this.tbookSer.profile.identity == '高校联系人'){
  120. query.containedIn('identity', ['个人','评审专家']);
  121. }
  122. this.profileLength = await query.count();
  123. query.limit(this.pageSize);
  124. query.skip((this.pageIndex - 1) * this.pageSize);
  125. let r = await query.find();
  126. this.profiles = r;
  127. this.loading = false;
  128. }
  129. //分页切换
  130. pageIndexChange(e: any) {
  131. console.log(e);
  132. this.pageIndex = e;
  133. this.getProfile();
  134. }
  135. createUser() {
  136. this.route.navigate(['/nav-admin/manage/user/create'])
  137. }
  138. onItemChecked(id: string, e: boolean) {
  139. if (e) {
  140. this.setOfCheckedId.add(id);
  141. } else {
  142. this.setOfCheckedId.delete(id);
  143. }
  144. this.checkedAll = this.profiles.every((item) =>
  145. this.setOfCheckedId.has(item.id)
  146. );
  147. }
  148. onAllChecked(checked: boolean): void {
  149. this.profiles.forEach((item) => {
  150. if (checked) {
  151. this.setOfCheckedId.add(item.id);
  152. } else {
  153. this.setOfCheckedId.delete(item.id);
  154. }
  155. });
  156. this.checkedAll = checked;
  157. }
  158. resetChange(){
  159. this.setOfCheckedId = new Set<string>();
  160. this.checkedAll = false;
  161. }
  162. async updateUser(data: Parse.Object, type: string) {
  163. console.log(type);
  164. if(this.tbookSer.profile.identity != '国家级管理员'
  165. && (data?.get('identity') == '工作联系人' || data?.get('identity') == '高校联系人')
  166. ){
  167. this.message.warning('暂无权限')
  168. return
  169. }
  170. this.modal.confirm({
  171. nzTitle: '操作提示',
  172. nzContent: `确定${type}吗?`,
  173. nzOkText: '确认',
  174. nzOkType: 'primary',
  175. nzOkDanger: type == '删除' ? true : false,
  176. nzOnOk: async () => {
  177. let query = new Parse.Query('_User');
  178. query.equalTo('objectId', data?.get('user')?.id);
  179. let r = await query.first();
  180. if (r?.id) {
  181. switch (type) {
  182. case '通过认证':
  183. r?.set('accountState', '已认证');
  184. break;
  185. case '禁用':
  186. r?.set('accountState', '已禁用');
  187. break;
  188. case '删除':
  189. // r?.set('isDeleted', true);
  190. await data.destroy()
  191. await r.destroy()
  192. break;
  193. }
  194. await r?.save();
  195. }
  196. this.getProfile();
  197. },
  198. nzCancelText: '取消',
  199. nzOnCancel: () => console.log('Cancel'),
  200. });
  201. }
  202. deleteSelected() {
  203. this.modal.confirm({
  204. nzTitle: '批量删除',
  205. nzContent: `删除后数据不可恢复,请谨慎操作`,
  206. nzOkText: '确认',
  207. nzOkType: 'primary',
  208. nzOkDanger: true,
  209. nzOnOk: async () => {
  210. let selectedList = this.profiles.filter((item: any) =>
  211. this.setOfCheckedId.has(item?.id)
  212. );
  213. let deletePromiseList = selectedList.map((item: any) => {
  214. return new Promise((resolve) => {
  215. // item.set('isDeleted', true);
  216. // item.save();
  217. item.destroy().then(()=> resolve)
  218. });
  219. });
  220. try {
  221. await Promise.all(deletePromiseList);
  222. this.getProfile();
  223. } catch (err) {}
  224. },
  225. nzCancelText: '取消',
  226. nzOnCancel: () => console.log('Cancel'),
  227. });
  228. }
  229. goDateil(id: string) {
  230. this.route.navigate(['/nav-admin/manage/user/edit', { id: id }]);
  231. }
  232. }