page-role.component.ts 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924
  1. import { Component, OnInit, ViewChild } from '@angular/core';
  2. import { ActivatedRoute, Route, Router, RouterOutlet } from '@angular/router';
  3. import { CompTableListComponent } from '../../../app/comp-table/comp-table-list/comp-table-list.component';
  4. import _Role from '../../../schemas/_Role';
  5. // import { TranslateService } from '@ngx-translate/core';
  6. import * as Parse from 'parse';
  7. import { CommonModule } from '@angular/common';
  8. import { Department } from '../../../schemas/Department';
  9. import { NzSpaceModule } from 'ng-zorro-antd/space';
  10. import { NzPageHeaderModule } from 'ng-zorro-antd/page-header';
  11. import { NzBreadCrumbModule } from 'ng-zorro-antd/breadcrumb';
  12. import { CommonCompModule } from '../../../services/common.modules';
  13. import { NzModalModule, NzModalService } from 'ng-zorro-antd/modal';
  14. import {
  15. NzFormatEmitEvent,
  16. NzTreeModule,
  17. NzTreeNode,
  18. } from 'ng-zorro-antd/tree';
  19. import {
  20. NzContextMenuService,
  21. NzDropdownMenuComponent,
  22. } from 'ng-zorro-antd/dropdown';
  23. import { NzCheckboxModule } from 'ng-zorro-antd/checkbox';
  24. import { NzEmptyModule } from 'ng-zorro-antd/empty';
  25. import { NzRadioModule } from 'ng-zorro-antd/radio';
  26. import { NzMessageService } from 'ng-zorro-antd/message';
  27. import { textbookServer } from '../../../services/textbook';
  28. import { NzSelectModule } from 'ng-zorro-antd/select';
  29. import { NzSpinModule } from 'ng-zorro-antd/spin';
  30. interface nodes {
  31. title: string;
  32. key: string;
  33. isLeaf?: boolean;
  34. isParent?: boolean;
  35. children?: Array<any>;
  36. }
  37. interface depart {
  38. name: string;
  39. id?: string;
  40. code?: string;
  41. desc?: string;
  42. parent?: object | any;
  43. branch: string;
  44. }
  45. @Component({
  46. selector: 'app-page-role',
  47. templateUrl: './page-role.component.html',
  48. styleUrls: ['./page-role.component.scss'],
  49. imports: [
  50. CommonModule,
  51. CommonCompModule,
  52. RouterOutlet,
  53. CompTableListComponent,
  54. NzSpaceModule,
  55. NzPageHeaderModule,
  56. NzBreadCrumbModule,
  57. NzTreeModule,
  58. NzCheckboxModule,
  59. NzEmptyModule,
  60. NzModalModule,
  61. NzRadioModule,
  62. NzSelectModule,NzSpinModule
  63. ],
  64. standalone: true,
  65. })
  66. export class PageRoleComponent implements OnInit {
  67. @ViewChild(CompTableListComponent) list: CompTableListComponent | undefined;
  68. // _Role = _Role
  69. Department = Department;
  70. user?: Parse.User;
  71. className: string | undefined;
  72. queryParams: any | undefined;
  73. fieldsArray: Array<any> | undefined;
  74. searchValue: string = ''; //搜索内容
  75. nodes: Array<nodes | any> = [];
  76. currentDepart: nodes | any = null;
  77. profiles: Array<any> = [];
  78. checkedShowFilter: boolean = false;
  79. checkedAll: boolean = false; //全选
  80. indeterminate = false;
  81. loading = false;
  82. pageSize: number = 10;
  83. pageIndex: number = 1;
  84. profileLength:number = 0
  85. isVisible: boolean = false;
  86. activatedNode: NzTreeNode | any; //当前选择节点
  87. editType: string = 'add'; //弹窗类型
  88. activeDepart?: Parse.Object; //当前编辑部门
  89. editObject: depart = {
  90. name: '',
  91. code: '',
  92. desc: '',
  93. parent: {},
  94. branch: '',
  95. };
  96. parentMap: Array<any> = [];
  97. parentList: Array<any> = [];
  98. radio: string = '';
  99. /* 添加账号 */
  100. accountIsVisible: boolean = false;
  101. account: any = {
  102. name: '',
  103. phone: '',
  104. email: '',
  105. password: '',
  106. identity: '',
  107. department: {},
  108. companyType: '',
  109. };
  110. userType: Array<string> = ['教师'];
  111. parents: Array<any> = []; //所有一级列表
  112. setOfCheckedId = new Set<string>();
  113. profileVisible: boolean = false; //用户部门变更
  114. profileAccount: Parse.Object | undefined; //变更部门用户
  115. profileEdit: any = {
  116. //变更部门用户json
  117. department: {},
  118. companyType: '',
  119. identity: '',
  120. };
  121. eduProcess?: Parse.Object;
  122. editLoading:boolean = true
  123. constructor(
  124. public tbookSer: textbookServer,
  125. private route: Router,
  126. private modal: NzModalService,
  127. private activeRoute: ActivatedRoute,
  128. private nzContextMenuService: NzContextMenuService,
  129. private message: NzMessageService
  130. ) {
  131. this.user = Parse.User.current();
  132. // this.className = this.Department.className;
  133. // this.fieldsArray = this.Department.fieldsArray;
  134. // this.queryParams = {
  135. // where: {
  136. // // user:this.user?.toPointer(),
  137. // isDeleted: { $ne: true },
  138. // },
  139. // };
  140. }
  141. ngOnInit(): void {
  142. this.activeRoute.paramMap.subscribe(async (params) => {
  143. this.refresh();
  144. });
  145. }
  146. async refresh() {
  147. if (!this.tbookSer.profile.user.department?.objectId) {
  148. this.message.warning('权限不足');
  149. // history.back();
  150. return;
  151. }
  152. let queryEduProcess = new Parse.Query('EduProcess');
  153. queryEduProcess.notEqualTo('isDeleted', true);
  154. queryEduProcess.equalTo('department', this.tbookSer.profile.user.department?.objectId)
  155. if(this.tbookSer.profile.identity == '工作联系人'){
  156. queryEduProcess.equalTo('profileSubmitted',this.tbookSer?.profile?.objectId)
  157. }
  158. queryEduProcess.select('objectId')
  159. this.eduProcess = await queryEduProcess.first();
  160. this.editLoading = false
  161. let query = new Parse.Query('Department');
  162. query.equalTo('objectId', this.tbookSer.profile.user.department?.objectId);
  163. query.select('code', 'name', 'branch', 'parent', 'type', 'hasChildren');
  164. let r = await query.first();
  165. let n = [
  166. {
  167. title: this.tbookSer.profile.user.department.name,
  168. key: this.tbookSer.profile.user.department?.objectId,
  169. children: [
  170. ...(await this.getDepart(this.tbookSer.profile.user.department?.objectId)),
  171. ],
  172. isParent: !r?.get('hasChildren'),
  173. isLeaf: !r?.get('hasChildren'),
  174. branch: r?.get('branch'),
  175. parent: r?.get('parent')?.id, //上级
  176. type: r?.get('branch'),
  177. },
  178. ];
  179. this.nodes = n
  180. let query2 = new Parse.Query('Department');
  181. query2.select('name');
  182. query2.equalTo('parent', null);
  183. this.parents = await query2.find();
  184. }
  185. async getDepart(
  186. parent?: string,
  187. searchValue?: string
  188. ): Promise<Array<nodes>> {
  189. console.log(searchValue);
  190. let nodes: any = [];
  191. let query = new Parse.Query('Department');
  192. query.equalTo('parent', parent ? parent : this.tbookSer.profile.user.department?.objectId);
  193. searchValue && query.contains('name', searchValue);
  194. query.notEqualTo('isDeleted', true);
  195. query.select('code', 'name', 'branch', 'parent', 'type', 'hasChildren');
  196. query.descending('createdAt');
  197. query.equalTo('branch', this.tbookSer.profile.companyType);
  198. // if (searchValue && searchValue != undefined) {
  199. // query.equalTo('parent', this.tbookSer.profile.user.department?.objectId);
  200. // }
  201. query.limit(100);
  202. if (this.activeDepart) query.notEqualTo('objectId', this.activeDepart?.id);
  203. let res = await query.find();
  204. res.forEach((item) => {
  205. nodes.push({
  206. title: item.get('name'),
  207. key: item.id,
  208. children: [],
  209. branch: item.get('branch'),
  210. parent: item.get('parent')?.id, //上级
  211. isLeaf: !item.get('hasChildren') ? true : false, //是否是最下级
  212. type: item.get('type')
  213. });
  214. });
  215. return nodes;
  216. }
  217. //搜索
  218. async onSearchNodes(e: string, modal?: boolean, id?:string) {
  219. if (modal) {
  220. this.parentList = await this.getDepart(id, e);
  221. return;
  222. }
  223. this.nodes = await this.getDepart('', e);
  224. }
  225. //搜索失去焦点
  226. onblur(type:string){
  227. console.log(type);
  228. if (type == 'account' || type == 'profileEdit') {
  229. this.modalValue = this.account.department?.title;
  230. this.modalValue = this.account.profileEdit?.title;
  231. } else if (type == 'editObject') {
  232. this.modalValue = this.editObject.parent?.title
  233. }
  234. }
  235. reset(type:string){
  236. this.modalValue = ''
  237. this.parentList = this.nodes;
  238. this.parentMap = []
  239. if (type == 'account' || type == 'profileEdit') {
  240. this.account.department = {};
  241. this.account.identity = '';
  242. this.account.profileEdit = {};
  243. this.account.profileEdit = '';
  244. }else if(type == 'editObject'){
  245. this.editObject.parent = {}
  246. }
  247. }
  248. //添加成员
  249. addMember() {
  250. this.modalValue = '';
  251. this.radio = ''
  252. this.parentList = this.nodes;
  253. this.account = {
  254. name: '',
  255. phone: '',
  256. email: '',
  257. password: '',
  258. identity: '',
  259. department: {},
  260. companyType: '',
  261. };
  262. this.accountIsVisible = true;
  263. }
  264. //展开/合并
  265. async nzEvent(event: NzFormatEmitEvent): Promise<void> {
  266. console.log(event);
  267. let node: any = event.node;
  268. if (event.eventName === 'expand') {
  269. // if (node.origin.isParent) {
  270. // node.addChildren([]);
  271. // return;
  272. // }
  273. if (node?._children.length <= 0) {
  274. let data = await this.getDepart(node.key);
  275. node.addChildren(data);
  276. }
  277. } else {
  278. // if (node.origin.isParent) {
  279. this.pageIndex = 1
  280. this.currentDepart = node.origin;
  281. this.getProfile();
  282. // }
  283. }
  284. }
  285. async getProfile() {
  286. this.profiles = [];
  287. this.loading = true;
  288. let childrens = [this.currentDepart.key]
  289. if(!this.checkedShowFilter){
  290. childrens = await this.tbookSer.getChild(this.currentDepart.key)
  291. }
  292. let queryParams = {
  293. where: {
  294. $or: [
  295. {
  296. user: {
  297. $inQuery: {
  298. where: {
  299. $or: [
  300. {
  301. department: { $in: [childrens] },
  302. },
  303. ],
  304. },
  305. className: '_User',
  306. },
  307. },
  308. },
  309. ],
  310. },
  311. };
  312. let query = Parse.Query.fromJSON('Profile', queryParams);
  313. query.include('user');
  314. if(this.tbookSer.profile.identity == '工作联系人'){
  315. query.containedIn('identity',['教师','高校联系人','评审专家'])
  316. }else if(this.tbookSer.profile.identity == '高校联系人'){
  317. query.containedIn('identity',['教师','评审专家'])
  318. }
  319. query.notEqualTo('identity', '国家级管理员');
  320. query.notEqualTo('isDeleted', true);
  321. this.profileLength = await query.count()
  322. query.limit(this.pageSize)
  323. query.skip((this.pageIndex - 1) * this.pageSize)
  324. let r = await query.find();
  325. // let profiles: any[] = [];
  326. // r.forEach((item) => {
  327. // let _item = item.toJSON();
  328. // _item['checked'] = false;
  329. // profiles.push(_item);
  330. // });
  331. this.profiles = r;
  332. this.loading = false;
  333. }
  334. //分页切换
  335. pageIndexChange(e: any) {
  336. console.log(e);
  337. this.pageIndex = e;
  338. this.getProfile();
  339. }
  340. onChecked(){
  341. this.pageIndex = 1;
  342. this.getProfile()
  343. }
  344. //搜索触发
  345. onSearch(event: NzFormatEmitEvent) {
  346. console.log(event);
  347. }
  348. contextMenu(
  349. $event: MouseEvent,
  350. menu: NzDropdownMenuComponent,
  351. node?: any
  352. ): void {
  353. console.log(node);
  354. this.activatedNode = node;
  355. this.nzContextMenuService.create($event, menu);
  356. }
  357. //删除部门
  358. onDelDepart() {
  359. console.log(this.activatedNode);
  360. this.modal.confirm({
  361. nzTitle: '删除',
  362. nzContent: '删除后数据不可恢复,请谨慎操作',
  363. nzOkText: '确认',
  364. nzOkType: 'primary',
  365. nzOkDanger: true,
  366. nzOnOk: async () => {
  367. new Promise(async (resolve, reject) => {
  368. if (this.activatedNode?.key) {
  369. let query = new Parse.Query('Department');
  370. let r = await query.get(this.activatedNode?.key);
  371. if (r?.id) {
  372. r.set('isDeleted', true);
  373. await r.save();
  374. }
  375. this.message.success('删除成功');
  376. this.ngOnInit();
  377. resolve(true);
  378. }
  379. }).catch(() => console.log('Oops errors!'));
  380. },
  381. nzCancelText: '取消',
  382. nzOnCancel: () => console.log('Cancel'),
  383. });
  384. }
  385. onAllChecked(checked: boolean): void {
  386. this.profiles.forEach((item) => {
  387. if (checked) {
  388. this.setOfCheckedId.add(item.id);
  389. } else {
  390. this.setOfCheckedId.delete(item.id);
  391. }
  392. });
  393. this.checkedAll = checked;
  394. }
  395. onItemChecked(id: string, e: boolean) {
  396. if (e) {
  397. this.setOfCheckedId.add(id);
  398. } else {
  399. this.setOfCheckedId.delete(id);
  400. }
  401. this.checkedAll = this.profiles.every((item) =>
  402. this.setOfCheckedId.has(item.id)
  403. );
  404. }
  405. //新建打开弹窗
  406. async showModalDepart(type: string) {
  407. this.radio = ''
  408. this.parentList = this.nodes;
  409. this.editObject = {
  410. name: '',
  411. code: '',
  412. desc: '',
  413. parent: '',
  414. branch: '',
  415. };
  416. if (type == 'edit') {
  417. let query = new Parse.Query('Department');
  418. let r = await query.get(this.activatedNode?.key);
  419. this.activeDepart = r;
  420. this.editObject = {
  421. name: this.activeDepart.get('name'),
  422. code: this.activeDepart.get('code'),
  423. desc: this.activeDepart.get('desc'),
  424. parent: {
  425. title: this.activeDepart.get('parent')?.get('name'),
  426. id: this.activeDepart.get('parent')?.id,
  427. },
  428. branch: this.activeDepart.get('branch'),
  429. };
  430. this.modalValue = this.activeDepart.get('parent')?.get('name');
  431. this.parentMap = await this.tbookSer.formatNode(
  432. this.activeDepart.get('parent')?.id
  433. );
  434. if (this.activatedNode?.parentNode?.origin?.parentNode?.origin.key) {
  435. this.parentList = await this.getDepart(
  436. this.activatedNode?.parentNode?.origin?.parentNode?.origin.key
  437. );
  438. }
  439. this.radio = this.activeDepart.get('parent')?.id;
  440. } else if (type == 'add' && this.activatedNode) {
  441. console.log(this.activatedNode);
  442. this.editObject.parent = {
  443. title: this.activatedNode.origin.title,
  444. id: this.activatedNode.origin.key,
  445. };
  446. this.radio = this.activatedNode.origin.key;
  447. this.modalValue = this.activatedNode.origin.title;
  448. this.editObject.branch =
  449. this.activatedNode.origin.branch || this.activatedNode.origin.title;
  450. this.parentMap = await this.tbookSer.formatNode(this.activatedNode.origin.key);
  451. if (this.activatedNode?.parentNode?.origin.key) {
  452. this.parentList = await this.getDepart(
  453. this.activatedNode.parentNode.origin.key
  454. );
  455. }
  456. }
  457. console.log(this.parentMap);
  458. this.editType = type;
  459. this.isVisible = true;
  460. this.resetChange()
  461. }
  462. async onPre(type:string, data?: any, index?: number) {
  463. console.log(data);
  464. if (!data?.key || !data.hasChildren) {
  465. // this.parentList = await this.getDepart();
  466. // this.parentMap = []
  467. return;
  468. }
  469. // if(index == this.parentMap.length-1) return
  470. this.parentMap.splice((index || 0) + 1);
  471. this.radio = '';
  472. if(type == 'profileEdit'){
  473. this.profileEdit.identity = ''
  474. }
  475. this.pushValue(type,this.parentMap[this.parentMap.length - 1])
  476. this.parentList = this.parentMap[this.parentMap.length - 1].key == this.tbookSer.profile.user.department?.objectId ? this.nodes : await this.getDepart(data?.parent);
  477. }
  478. //选择所属类别下级列表
  479. async onCheckedDepart(type: string, e: any, checked?: boolean) {
  480. this.radio = '';
  481. console.log(e);
  482. if (type == 'account' || type == 'profileEdit') {
  483. this.account.identity = '';
  484. this.profileEdit.identity = '';
  485. }
  486. this.parentMap = await this.tbookSer.formatNode(e.key);
  487. let index = this.parentMap.findIndex(
  488. (item) => this.tbookSer.profile.user.department?.objectId == item.key
  489. );
  490. if (index != -1) {
  491. this.parentMap.forEach((item, i) => {
  492. if (i >= index) {
  493. this.parentMap[i].verify = true;
  494. }
  495. });
  496. }
  497. if (checked || e.isLeaf) {
  498. this.pushValue(type,e)
  499. return;
  500. }
  501. if (e.isLeaf) {
  502. return;
  503. }
  504. this.parentList = await this.getDepart(e?.key);
  505. }
  506. modalValue:string = ''
  507. //赋值
  508. pushValue(type:string, e: any){
  509. console.log(e);
  510. this.radio = e.key;
  511. this.modalValue = e.title
  512. if (type == 'account') {
  513. this.account.department = { title: e.title, id: e.key };
  514. this.account.companyType = e.branch || e.title;
  515. if(this.tbookSer.profile.identity == '工作联系人'){
  516. this.userType = this.parents.some((item) => e.parent == item.id)
  517. ? ['评审专家', '教师','高校联系人']
  518. : e.type == '单位'
  519. ? ['评审专家', '高校联系人', '教师']
  520. : ['评审专家', '教师'];
  521. }
  522. }else if (type == 'profileEdit' && e.parent) {
  523. this.profileEdit.department = { title: e.title, id: e.key };
  524. this.profileEdit.companyType = e.branch || e.title;
  525. if(this.tbookSer.profile.identity == '工作联系人'){
  526. this.userType = this.parents.some((item) => e.parent == item.id)
  527. ? ['评审专家', '教师','高校联系人']
  528. : e.type == '单位'
  529. ? ['评审专家', '高校联系人', '教师']
  530. : ['评审专家', '教师'];
  531. }
  532. } else {
  533. this.editObject.parent = {
  534. title: e.title,
  535. id: e.key,
  536. };
  537. this.editObject.branch = e.branch || e.title;
  538. }
  539. }
  540. async handleOk(): Promise<void> {
  541. if (!this.editObject?.name || !this.editObject.parent?.id) {
  542. this.message.error('请填写完整信息');
  543. return;
  544. }
  545. if (this.activeDepart?.id && this.editType == 'edit') {
  546. this.activeDepart.set('name', this.editObject?.name);
  547. this.activeDepart.set('code', this.editObject?.code);
  548. this.activeDepart.set('desc', this.editObject.desc);
  549. this.activeDepart.set('parent', {
  550. __type: 'Pointer',
  551. className: 'Department',
  552. objectId: this.editObject.parent?.id,
  553. });
  554. this.activeDepart.set('branch', this.editObject.branch);
  555. } else {
  556. let obj = Parse.Object.extend('Department');
  557. this.activeDepart = new obj();
  558. this.activeDepart?.set('name', this.editObject?.name);
  559. this.activeDepart?.set('code', this.editObject?.code);
  560. this.activeDepart?.set('desc', this.editObject.desc);
  561. this.activeDepart?.set('parent', {
  562. __type: 'Pointer',
  563. className: 'Department',
  564. objectId: this.editObject.parent?.id,
  565. });
  566. this.activeDepart?.set('branch', this.editObject.branch);
  567. }
  568. await this.activeDepart?.save();
  569. if(this.activeDepart?.id){
  570. //判断添加的是部门还是单位
  571. let filters = ['出版单位','教育部直属高校']
  572. let leng = await this.tbookSer.formatNode(this.activeDepart.id)
  573. if(leng.length > 2){
  574. console.log(leng.length);
  575. if(filters.includes(leng[0].title)){
  576. this.activeDepart?.set('type', '部门');
  577. }else{
  578. this.activeDepart?.set('type',leng.length > 3 ? '部门' : '单位');
  579. }
  580. leng.slice()
  581. await this.activeDepart?.save();
  582. }
  583. }
  584. await this.updateChildren();
  585. this.isVisible = false;
  586. this.message.success(this.editType == 'edit' ? '保存' : '添加' + '成功');
  587. this.activeDepart = undefined;
  588. this.ngOnInit();
  589. }
  590. //更新上级children字段
  591. async updateChildren() {
  592. let query = new Parse.Query('Department');
  593. query.equalTo('objectId', this.editObject.parent?.id);
  594. query.select('hasChildren')
  595. let r = await query.first();
  596. if (r?.id && !r.get('hasChildren')) {
  597. r?.set('hasChildren', true);
  598. await r.save();
  599. }
  600. return;
  601. }
  602. //变更用户部门
  603. async showProfile(data: Parse.Object) {
  604. let query = new Parse.Query('Department');
  605. query.include('parent', 'parent.parent');
  606. let r = await query.get(data?.get('user')?.get('department')?.id);
  607. if(data?.get('user')?.get('department')?.id == this.tbookSer.profile.user.department?.objectId){
  608. this.parentList = this.nodes;
  609. }else{
  610. this.parentList = await this.getDepart(r.get('parent').id);
  611. }
  612. this.parentMap = await this.tbookSer.formatNode(
  613. data?.get('user')?.get('department')?.id
  614. );
  615. let index = this.parentMap.findIndex(
  616. (item) => this.tbookSer.profile.user.department?.objectId == item.key
  617. );
  618. if (index != -1) {
  619. this.parentMap.forEach((item, i) => {
  620. if (i >= index) {
  621. this.parentMap[i].verify = true;
  622. }
  623. });
  624. }
  625. this.radio = data?.get('user')?.get('department')?.id;
  626. this.profileAccount = data;
  627. this.profileEdit = {
  628. //变更部门用户json
  629. department: {
  630. key: r?.id,
  631. title: r?.get('title'),
  632. },
  633. companyType: data?.get('companyType'),
  634. identity: data?.get('identity'),
  635. };
  636. let parms = {
  637. title: r?.get('name'),
  638. key: r?.id,
  639. type: r?.get('type'),
  640. parent: r?.get('parent')?.id,
  641. branch: r?.get('branch'),
  642. };
  643. console.log(parms);
  644. this.pushValue('profileEdit', parms);
  645. this.modalValue = r?.get('name');
  646. this.profileVisible = true;
  647. }
  648. handleCancel(): void {
  649. console.log('关闭弹窗');
  650. this.activeDepart = undefined;
  651. this.modalValue = ''
  652. this.isVisible = false;
  653. this.activatedNode = undefined;
  654. this.parentMap = [];
  655. this.accountIsVisible = false;
  656. this.account = {
  657. name: '',
  658. phone: '',
  659. email: '',
  660. password: '',
  661. identity: '',
  662. department: {},
  663. companyType: '',
  664. };
  665. this.profileVisible = false;
  666. this.profileAccount = undefined;
  667. this.profileEdit = {
  668. //变更部门用户json
  669. department: {},
  670. companyType: '',
  671. identity: '',
  672. };
  673. }
  674. /* 组织 */
  675. showModalOrganize() {
  676. this.message.warning('权限灰度中');
  677. }
  678. goDateil(id: string) {
  679. let url = '';
  680. switch (this.tbookSer.profile.identity) {
  681. case '国家级管理员':
  682. url = '/nav-admin/manage/user/edit';
  683. break;
  684. case '工作联系人':
  685. url = '/nav-province-contact/manage/user/edit';
  686. break;
  687. case '高校联系人':
  688. url = '/nav-province-school-contact/manage/user/edit';
  689. break;
  690. }
  691. this.route.navigate([url, { id: id }]);
  692. }
  693. randomPassword() {
  694. this.account.password = this.tbookSer.randomPassword();
  695. }
  696. /* 添加账号 */
  697. isLoadingOne:boolean = false
  698. async accountComplete() {
  699. if(this.isLoadingOne) return
  700. this.isLoadingOne = true
  701. this.account.email = this.account?.email.trim();
  702. this.account.phone = this.account?.phone.trim();
  703. this.account.name = this.account?.name.trim();
  704. this.account.password = this.account?.password.trim();
  705. if(!await this.authVrifly()){
  706. this.isLoadingOne = false
  707. return
  708. }
  709. try {
  710. let obj = Parse.Object.extend('_User');
  711. let user = new obj();
  712. user?.set('username', this.account?.email || this.account?.phone);
  713. user?.set('name', this.account?.name);
  714. user?.set('phone', this.account?.phone);
  715. this.account?.email && user?.set('email', this.account?.email);
  716. user?.set('password', this.account.password);
  717. user?.set('accountState', '已认证');
  718. user?.set('department', {
  719. __type: 'Pointer',
  720. className: 'Department',
  721. objectId: this.account.department?.id,
  722. });
  723. let u = await user.save();
  724. let p = Parse.Object.extend('Profile');
  725. let profile = new p();
  726. profile?.set('user', u?.toPointer());
  727. profile?.set('companyType', this.account.companyType);
  728. profile?.set('email', this.account.email);
  729. profile?.set('identity', this.account.identity);
  730. let res = await profile?.save();
  731. this.isLoadingOne = false
  732. this.accountIsVisible = false;
  733. this.account = null;
  734. Parse.Cloud.run('aliSmsSend',{
  735. "mobileList": [this.account?.phone],"templateCode":"SMS_469060724","params":{},"signName":"普通高等教育教材网"
  736. })
  737. this.modal.success({
  738. nzTitle: '添加成功',
  739. nzContent: '',
  740. nzOnOk: () => {
  741. this.currentDepart && this.getProfile();
  742. },
  743. });
  744. } catch (err: any) {
  745. console.warn('添加用户错误', err);
  746. this.isLoadingOne = false
  747. this.message.error(err?.Error || '错误:请检查用户邮箱是否已存在');
  748. return;
  749. }
  750. }
  751. async authVrifly():Promise< boolean | undefined>{
  752. this.account.email = this.account?.email.trim();
  753. this.account.phone = this.account?.phone.trim();
  754. this.account.name = this.account?.name.trim();
  755. this.account.password = this.account?.password.trim();
  756. if(!this.account?.name|| !this.account.department?.id || !this.account.password
  757. || !this.account.phone || !this.account?.email){
  758. this.message.warning('请填写必填项');
  759. return
  760. }
  761. if(!this.account.identity){
  762. this.message.error("请选择人员类型");
  763. return;
  764. }
  765. let a = /^(?:(?:\+|00)86)?1[3-9]\d{9}$/
  766. if(this.account.phone && !String(this.account.phone).match(a)){
  767. this.message.error("请填写正确手机号");
  768. return;
  769. }
  770. let m = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
  771. if(!String(this.account.email).match(m)){
  772. this.message.error("邮箱格式有误");
  773. return;
  774. }
  775. // if(!this.account?.email && !this.account?.phone){
  776. // this.message.error("邮箱或手机号必须填写一项");
  777. // return;
  778. // }
  779. console.log(this.account.password);
  780. if(!(this.account.password.length >= 6 && this.account.password.length <= 18)){
  781. this.message.error('密码格式错误,请填写6-18位非空字符串(数字、大小写字母或英文符号)');
  782. return;
  783. }
  784. if(!await this.tbookSer.userFind(this.account.phone)){
  785. this.message.error('手机号已存在');
  786. return
  787. }
  788. return true
  789. }
  790. //移除部门
  791. // async removeBranch(data: Parse.Object) {
  792. // if (data?.get('user')?.id) {
  793. // data?.get('user')?.set('department', null);
  794. // await data?.get('user')?.save();
  795. // this.message.error('移除成功');
  796. // this.getProfile();
  797. // }
  798. // }
  799. // removeBranchAll() {
  800. // this.modal.confirm({
  801. // nzTitle: '批量移除',
  802. // nzContent: `请谨慎操作`,
  803. // nzOkText: '确认',
  804. // nzOkType: 'primary',
  805. // nzOkDanger: true,
  806. // nzOnOk: async () => {
  807. // let selectedList = this.profiles.filter((item: any) =>
  808. // this.setOfCheckedId.has(item?.id)
  809. // );
  810. // let romovePromiseList = selectedList.map((item: any) => {
  811. // return new Promise(async (resolve) => {
  812. // item?.get('user')?.set('department', null);
  813. // await item?.get('user')?.save();
  814. // resolve(true);
  815. // });
  816. // });
  817. // try {
  818. // await Promise.all(romovePromiseList);
  819. // this.message.error('移除成功');
  820. // this.getProfile();
  821. // this.resetChange();
  822. // } catch (err) {}
  823. // },
  824. // nzCancelText: '取消',
  825. // nzOnCancel: () => console.log('Cancel'),
  826. // });
  827. // }
  828. //删除用户
  829. async deleteSelected(data?:Parse.Object) {
  830. let filters = []
  831. if(data?.id){
  832. filters = [data?.id]
  833. }else{
  834. filters = Array.from(this.setOfCheckedId)
  835. }
  836. console.log(filters);
  837. let v = await this.tbookSer.getEduProcessProf(filters)
  838. this.modal.confirm({
  839. nzTitle: `确认${data?.id ? '批量删除' : '删除该用户'}吗?`,
  840. nzContent: `${v ? '该用户已经被设置为【流程名称】的工作联系人,删除后,你需要重新设置该流程的工作联系人' : '该用户已经提交至申报流程中的教材不会被删除'}`,
  841. nzOkText: '确认',
  842. nzOkType: 'primary',
  843. nzOkDanger: true,
  844. nzOnOk: async () => {
  845. let selectedList = this.profiles.filter((item: any) =>
  846. this.setOfCheckedId.has(item?.id)
  847. );
  848. let deletePromiseList = selectedList.map((item: any) => {
  849. return new Promise(async (resolve) => {
  850. await item.get('user')?.destroy()
  851. await item.destroy()
  852. resolve(true)
  853. });
  854. });
  855. try {
  856. await Promise.all(deletePromiseList);
  857. this.setOfCheckedId = new Set<string>();
  858. this.checkedAll = false
  859. this.getProfile();
  860. } catch (err) {}
  861. },
  862. nzCancelText: '取消',
  863. nzOnCancel: () => console.log('Cancel'),
  864. });
  865. }
  866. //保存更新部门
  867. async updateProfile() {
  868. if (this.isLoadingOne) return;
  869. this.isLoadingOne = true;
  870. if (
  871. !this.profileEdit?.department.id ||
  872. !this.profileEdit?.department?.title ||
  873. !this.profileEdit?.identity ||
  874. !this.profileEdit.companyType
  875. ) {
  876. this.message.warning('填写信息不完整');
  877. this.isLoadingOne = false;
  878. return;
  879. }
  880. try {
  881. this.profileAccount?.set('identity', this.profileEdit?.identity);
  882. this.profileAccount?.set('companyType', this.profileEdit?.companyType);
  883. await this.profileAccount?.save();
  884. this.profileAccount?.get('user')?.set('department', {
  885. __type: 'Pointer',
  886. className: 'Department',
  887. objectId: this.profileEdit?.department.id,
  888. });
  889. await this.profileAccount?.get('user')?.save();
  890. this.pageIndex = 1;
  891. this.getProfile();
  892. this.isLoadingOne = false;
  893. this.handleCancel()
  894. } catch (err) {
  895. console.log(err);
  896. this.message.error('修改出错,请稍后重试');
  897. this.isLoadingOne = false;
  898. }
  899. }
  900. resetChange() {
  901. this.setOfCheckedId = new Set<string>();
  902. this.checkedAll = false;
  903. }
  904. }