page-role.component.ts 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761
  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. constructor(
  114. public tbookSer: textbookServer,
  115. private route: Router,
  116. private modal: NzModalService,
  117. private activeRoute: ActivatedRoute,
  118. private nzContextMenuService: NzContextMenuService,
  119. private message: NzMessageService
  120. ) {
  121. this.user = Parse.User.current();
  122. // this.className = this.Department.className;
  123. // this.fieldsArray = this.Department.fieldsArray;
  124. // this.queryParams = {
  125. // where: {
  126. // // user:this.user?.toPointer(),
  127. // isDeleted: { $ne: true },
  128. // },
  129. // };
  130. }
  131. ngOnInit(): void {
  132. this.activeRoute.paramMap.subscribe(async (params) => {
  133. this.refresh();
  134. });
  135. }
  136. async refresh() {
  137. if (!this.tbookSer.profile.user.department?.objectId) {
  138. this.message.warning('权限不足');
  139. history.back();
  140. return;
  141. }
  142. let query = new Parse.Query('Department');
  143. query.equalTo('objectId', this.tbookSer.profile.user.department?.objectId);
  144. query.select('code', 'name', 'branch', 'parent', 'type', 'hasChildren');
  145. let r = await query.first();
  146. let n = [
  147. {
  148. title: this.tbookSer.profile.user.department.name,
  149. key: this.tbookSer.profile.user.department?.objectId,
  150. children: [
  151. ...(await this.getDepart(this.tbookSer.profile.user.department?.objectId)),
  152. ],
  153. isParent: !r?.get('hasChildren'),
  154. isLeaf: !r?.get('hasChildren'),
  155. branch: r?.get('branch'),
  156. parent: r?.get('parent')?.id, //上级
  157. type: r?.get('branch'),
  158. },
  159. ];
  160. this.nodes = n
  161. let query2 = new Parse.Query('Department');
  162. query2.select('name');
  163. query2.equalTo('parent', null);
  164. this.parents = await query2.find();
  165. }
  166. async getDepart(
  167. parent?: string,
  168. searchValue?: string
  169. ): Promise<Array<nodes>> {
  170. console.log(searchValue);
  171. let nodes: any = [];
  172. let query = new Parse.Query('Department');
  173. query.equalTo('parent', parent ? parent : this.tbookSer.profile.user.department?.objectId);
  174. searchValue && query.contains('name', searchValue);
  175. query.notEqualTo('isDeleted', true);
  176. query.select('code', 'name', 'branch', 'parent', 'type', 'hasChildren');
  177. query.descending('createdAt');
  178. query.equalTo('branch', this.tbookSer.profile.companyType);
  179. // if (searchValue && searchValue != undefined) {
  180. // query.equalTo('parent', this.tbookSer.profile.user.department?.objectId);
  181. // }
  182. query.limit(100);
  183. if (this.activeDepart) query.notEqualTo('objectId', this.activeDepart?.id);
  184. let res = await query.find();
  185. res.forEach((item) => {
  186. nodes.push({
  187. title: item.get('name'),
  188. key: item.id,
  189. children: [],
  190. branch: item.get('branch'),
  191. parent: item.get('parent')?.id, //上级
  192. isLeaf: !item.get('hasChildren') ? true : false, //是否是最下级
  193. type: item.get('type')
  194. });
  195. });
  196. return nodes;
  197. }
  198. //搜索
  199. async onSearchNodes(e: string, modal?: boolean, id?:string) {
  200. if (modal) {
  201. this.parentList = await this.getDepart(id, e);
  202. return;
  203. }
  204. this.nodes = await this.getDepart('', e);
  205. }
  206. //搜索失去焦点
  207. onblur(type:string){
  208. console.log(type);
  209. if(type == 'account'){
  210. this.modalValue = this.account.department?.title
  211. }else if(type == 'editObject'){
  212. this.modalValue = this.editObject.parent?.title
  213. }
  214. }
  215. reset(type:string){
  216. this.modalValue = ''
  217. this.parentList = this.nodes;
  218. this.parentMap = []
  219. if(type == 'account'){
  220. this.account.department = {}
  221. this.account.identity = ''
  222. }else if(type == 'editObject'){
  223. this.editObject.parent = {}
  224. }
  225. }
  226. //添加成员
  227. addMember() {
  228. this.radio = ''
  229. this.parentList = this.nodes;
  230. this.account = {
  231. name: '',
  232. phone: '',
  233. email: '',
  234. password: '',
  235. identity: '',
  236. department: {},
  237. companyType: '',
  238. };
  239. this.accountIsVisible = true;
  240. }
  241. //展开/合并
  242. async nzEvent(event: NzFormatEmitEvent): Promise<void> {
  243. console.log(event);
  244. let node: any = event.node;
  245. if (event.eventName === 'expand') {
  246. // if (node.origin.isParent) {
  247. // node.addChildren([]);
  248. // return;
  249. // }
  250. if (node?._children.length <= 0) {
  251. let data = await this.getDepart(node.key);
  252. node.addChildren(data);
  253. }
  254. } else {
  255. // if (node.origin.isParent) {
  256. this.currentDepart = node.origin;
  257. this.getProfile();
  258. // }
  259. }
  260. }
  261. async getProfile() {
  262. this.profiles = [];
  263. this.loading = true;
  264. let childrens = [this.currentDepart.key]
  265. if(!this.checkedShowFilter){
  266. childrens = await this.tbookSer.getChild(this.currentDepart.key)
  267. }
  268. let queryParams = {
  269. where: {
  270. $or: [
  271. {
  272. user: {
  273. $inQuery: {
  274. where: {
  275. $or: [
  276. {
  277. department: { $in: [childrens] },
  278. },
  279. ],
  280. },
  281. className: '_User',
  282. },
  283. },
  284. },
  285. ],
  286. },
  287. };
  288. let query = Parse.Query.fromJSON('Profile', queryParams);
  289. query.include('user');
  290. if(this.tbookSer.profile.identity == '工作联系人'){
  291. query.containedIn('identity',['教师','高校联系人','评审专家'])
  292. }else if(this.tbookSer.profile.identity == '高校联系人'){
  293. query.containedIn('identity',['教师','评审专家'])
  294. }
  295. query.notEqualTo('identity', '国家级管理员');
  296. query.notEqualTo('isDeleted', true);
  297. this.profileLength = await query.count()
  298. query.limit(this.pageSize)
  299. query.skip((this.pageIndex - 1) * this.pageSize)
  300. let r = await query.find();
  301. // let profiles: any[] = [];
  302. // r.forEach((item) => {
  303. // let _item = item.toJSON();
  304. // _item['checked'] = false;
  305. // profiles.push(_item);
  306. // });
  307. this.profiles = r;
  308. this.loading = false;
  309. }
  310. //分页切换
  311. pageIndexChange(e: any) {
  312. console.log(e);
  313. this.pageIndex = e;
  314. this.getProfile();
  315. }
  316. onChecked(){
  317. this.pageIndex = 1;
  318. this.getProfile()
  319. }
  320. //搜索触发
  321. onSearch(event: NzFormatEmitEvent) {
  322. console.log(event);
  323. }
  324. contextMenu(
  325. $event: MouseEvent,
  326. menu: NzDropdownMenuComponent,
  327. node?: any
  328. ): void {
  329. console.log(node);
  330. this.activatedNode = node;
  331. this.nzContextMenuService.create($event, menu);
  332. }
  333. //删除部门
  334. onDelDepart() {
  335. console.log(this.activatedNode);
  336. this.modal.confirm({
  337. nzTitle: '删除',
  338. nzContent: '删除后数据不可恢复,请谨慎操作',
  339. nzOkText: '确认',
  340. nzOkType: 'primary',
  341. nzOkDanger: true,
  342. nzOnOk: async () => {
  343. new Promise(async (resolve, reject) => {
  344. if (this.activatedNode?.key) {
  345. let query = new Parse.Query('Department');
  346. let r = await query.get(this.activatedNode?.key);
  347. if (r?.id) {
  348. r.set('isDeleted', true);
  349. await r.save();
  350. }
  351. this.message.success('删除成功');
  352. this.ngOnInit();
  353. resolve(true);
  354. }
  355. }).catch(() => console.log('Oops errors!'));
  356. },
  357. nzCancelText: '取消',
  358. nzOnCancel: () => console.log('Cancel'),
  359. });
  360. }
  361. onAllChecked(checked: boolean): void {
  362. this.profiles.forEach((item) => {
  363. if (checked) {
  364. this.setOfCheckedId.add(item.id);
  365. } else {
  366. this.setOfCheckedId.delete(item.id);
  367. }
  368. });
  369. this.checkedAll = checked;
  370. }
  371. onItemChecked(id: string, e: boolean) {
  372. if (e) {
  373. this.setOfCheckedId.add(id);
  374. } else {
  375. this.setOfCheckedId.delete(id);
  376. }
  377. this.checkedAll = this.profiles.every((item) =>
  378. this.setOfCheckedId.has(item.id)
  379. );
  380. }
  381. //新建打开弹窗
  382. async showModalDepart(type: string) {
  383. this.radio = ''
  384. this.parentList = this.nodes;
  385. this.editObject = {
  386. name: '',
  387. code: '',
  388. desc: '',
  389. parent: '',
  390. branch: '',
  391. };
  392. if (type == 'edit') {
  393. let query = new Parse.Query('Department');
  394. let r = await query.get(this.activatedNode?.key);
  395. this.activeDepart = r;
  396. this.editObject = {
  397. name: this.activeDepart.get('name'),
  398. code: this.activeDepart.get('code'),
  399. desc: this.activeDepart.get('desc'),
  400. parent: {
  401. title: this.activeDepart.get('parent')?.get('name'),
  402. id: this.activeDepart.get('parent')?.id,
  403. },
  404. branch: this.activeDepart.get('branch'),
  405. };
  406. this.parentMap = await this.tbookSer.formatNode(
  407. this.activeDepart.get('parent')?.id
  408. );
  409. if (this.activatedNode?.parentNode?.origin?.parentNode?.origin.key) {
  410. this.parentList = await this.getDepart(
  411. this.activatedNode?.parentNode?.origin?.parentNode?.origin.key
  412. );
  413. }
  414. } else if (type == 'add' && this.activatedNode) {
  415. console.log(this.activatedNode);
  416. this.editObject.parent = {
  417. title: this.activatedNode.origin.title,
  418. id: this.activatedNode.origin.key,
  419. };
  420. this.editObject.branch =
  421. this.activatedNode.origin.branch || this.activatedNode.origin.title;
  422. this.parentMap = await this.tbookSer.formatNode(this.activatedNode.origin.key);
  423. if (this.activatedNode?.parentNode?.origin.key) {
  424. this.parentList = await this.getDepart(
  425. this.activatedNode.parentNode.origin.key
  426. );
  427. }
  428. }
  429. console.log(this.parentMap);
  430. this.editType = type;
  431. this.isVisible = true;
  432. this.resetChange()
  433. }
  434. async onPre(type:string, data?: any, index?: number) {
  435. console.log(data);
  436. if (!data?.key || !data.hasChildren) {
  437. // this.parentList = await this.getDepart();
  438. // this.parentMap = []
  439. return;
  440. }
  441. // if(index == this.parentMap.length-1) return
  442. this.parentMap.splice((index || 0) + 1);
  443. this.radio = '';
  444. this.pushValue(type,this.parentMap[this.parentMap.length - 1])
  445. this.parentList = this.parentMap[this.parentMap.length - 1].key == this.tbookSer.profile.user.department?.objectId ? this.nodes : await this.getDepart(data?.parent);
  446. }
  447. //选择所属类别下级列表
  448. async onCheckedDepart(type: string, e: any, checked?: boolean) {
  449. this.radio = '';
  450. console.log(e);
  451. if (type == 'account') this.account.identity = '';
  452. this.parentMap = await this.tbookSer.formatNode(e.key);
  453. let index = this.parentMap.findIndex(
  454. (item) => this.tbookSer.profile.user.department?.objectId == item.key
  455. );
  456. if (index != -1) {
  457. this.parentMap.forEach((item, i) => {
  458. if (i >= index) {
  459. this.parentMap[i].verify = true;
  460. }
  461. });
  462. }
  463. if (checked || e.isLeaf) {
  464. this.pushValue(type,e)
  465. return;
  466. }
  467. if (e.isLeaf) {
  468. return;
  469. }
  470. this.parentList = await this.getDepart(e?.key);
  471. }
  472. modalValue:string = ''
  473. //赋值
  474. pushValue(type:string, e: any){
  475. console.log(e);
  476. this.radio = e.key;
  477. this.modalValue = e.title
  478. if (type == 'account') {
  479. this.account.department = { title: e.title, id: e.key };
  480. this.account.companyType = e.branch || e.title;
  481. if(this.tbookSer.profile.identity == '工作联系人'){
  482. this.userType = this.parents.some((item) => e.parent == item.id)
  483. ? ['评审专家', '教师','高校联系人']
  484. : e.type == '单位'
  485. ? ['评审专家', '高校联系人', '教师']
  486. : ['评审专家', '教师'];
  487. }
  488. } else {
  489. this.editObject.parent = {
  490. title: e.title,
  491. id: e.key,
  492. };
  493. this.editObject.branch = e.branch || e.title;
  494. }
  495. }
  496. async handleOk(): Promise<void> {
  497. if (!this.editObject?.name || !this.editObject.parent?.id) {
  498. this.message.error('请填写完整信息');
  499. return;
  500. }
  501. if (this.activeDepart?.id && this.editType == 'edit') {
  502. this.activeDepart.set('name', this.editObject?.name);
  503. this.activeDepart.set('code', this.editObject?.code);
  504. this.activeDepart.set('desc', this.editObject.desc);
  505. this.activeDepart.set('parent', {
  506. __type: 'Pointer',
  507. className: 'Department',
  508. objectId: this.editObject.parent?.id,
  509. });
  510. this.activeDepart.set('branch', this.editObject.branch);
  511. } else {
  512. let obj = Parse.Object.extend('Department');
  513. this.activeDepart = new obj();
  514. this.activeDepart?.set('name', this.editObject?.name);
  515. this.activeDepart?.set('code', this.editObject?.code);
  516. this.activeDepart?.set('desc', this.editObject.desc);
  517. this.activeDepart?.set('parent', {
  518. __type: 'Pointer',
  519. className: 'Department',
  520. objectId: this.editObject.parent?.id,
  521. });
  522. this.activeDepart?.set('branch', this.editObject.branch);
  523. }
  524. await this.activeDepart?.save();
  525. if(this.activeDepart?.id){
  526. //判断添加的是部门还是单位
  527. let filters = ['出版单位','教育部直属高校']
  528. let leng = await this.tbookSer.formatNode(this.activeDepart.id)
  529. if(leng.length > 2){
  530. console.log(leng.length);
  531. if(filters.includes(leng[0].title)){
  532. this.activeDepart?.set('type', '部门');
  533. }else{
  534. this.activeDepart?.set('type',leng.length > 3 ? '部门' : '单位');
  535. }
  536. leng.slice()
  537. await this.activeDepart?.save();
  538. }
  539. }
  540. await this.updateChildren();
  541. this.isVisible = false;
  542. this.message.success(this.editType == 'edit' ? '保存' : '添加' + '成功');
  543. this.activeDepart = undefined;
  544. this.ngOnInit();
  545. }
  546. //更新上级children字段
  547. async updateChildren() {
  548. let query = new Parse.Query('Department');
  549. query.equalTo('objectId', this.editObject.parent?.id);
  550. query.select('hasChildren')
  551. let r = await query.first();
  552. if (r?.id && !r.get('hasChildren')) {
  553. r?.set('hasChildren', true);
  554. await r.save();
  555. }
  556. return;
  557. }
  558. handleCancel(): void {
  559. console.log('Button cancel clicked!');
  560. this.modalValue = ''
  561. this.isVisible = false;
  562. this.activatedNode = undefined;
  563. this.parentMap = [];
  564. this.accountIsVisible = false;
  565. this.account = null;
  566. }
  567. /* 组织 */
  568. showModalOrganize() {
  569. this.message.warning('权限灰度中');
  570. }
  571. goDateil(id: string) {
  572. this.route.navigate(['/nav-admin/manage/user/edit', { id: id }]);
  573. }
  574. randomPassword() {
  575. this.account.password = this.tbookSer.randomPassword();
  576. }
  577. /* 添加账号 */
  578. isLoadingOne:boolean = false
  579. async accountComplete() {
  580. if(this.isLoadingOne) return
  581. this.isLoadingOne = true
  582. this.account.email = this.account?.email.trim();
  583. this.account.phone = this.account?.phone.trim();
  584. this.account.name = this.account?.name.trim();
  585. this.account.password = this.account?.password.trim();
  586. if(!await this.authVrifly()){
  587. this.isLoadingOne = false
  588. return
  589. }
  590. try {
  591. let obj = Parse.Object.extend('_User');
  592. let user = new obj();
  593. user?.set('username', this.account?.email || this.account?.phone);
  594. user?.set('name', this.account?.name);
  595. user?.set('phone', this.account?.phone);
  596. this.account?.email && user?.set('email', this.account?.email);
  597. user?.set('password', this.account.password);
  598. user?.set('accountState', '已认证');
  599. user?.set('department', {
  600. __type: 'Pointer',
  601. className: 'Department',
  602. objectId: this.account.department?.id,
  603. });
  604. let u = await user.save();
  605. let p = Parse.Object.extend('Profile');
  606. let profile = new p();
  607. profile?.set('user', u?.toPointer());
  608. profile?.set('companyType', this.account.companyType);
  609. profile?.set('email', this.account.email);
  610. profile?.set('identity', this.account.identity);
  611. let res = await profile?.save();
  612. this.isLoadingOne = false
  613. this.accountIsVisible = false;
  614. this.account = null;
  615. Parse.Cloud.run('aliSmsSend',{
  616. "mobileList": [this.account?.phone],"templateCode":"SMS_469060724","params":{},"signName":"普通高等教育教材网"
  617. })
  618. this.modal.success({
  619. nzTitle: '添加成功',
  620. nzContent: '',
  621. nzOnOk: () => {
  622. this.currentDepart && this.getProfile();
  623. },
  624. });
  625. } catch (err: any) {
  626. console.warn('添加用户错误', err);
  627. this.isLoadingOne = false
  628. this.message.error(err?.Error || '错误:请检查用户邮箱是否已存在');
  629. return;
  630. }
  631. }
  632. async authVrifly():Promise< boolean | undefined>{
  633. this.account.email = this.account?.email.trim();
  634. this.account.phone = this.account?.phone.trim();
  635. this.account.name = this.account?.name.trim();
  636. this.account.password = this.account?.password.trim();
  637. if(!this.account?.name|| !this.account.department?.id || !this.account.password
  638. || !this.account.phone || !this.account?.email){
  639. this.message.warning('请填写必填项');
  640. return
  641. }
  642. if(!this.account.identity){
  643. this.message.error("请选择人员类型");
  644. return;
  645. }
  646. let a = /^(?:(?:\+|00)86)?1[3-9]\d{9}$/
  647. if(this.account.phone && !String(this.account.phone).match(a)){
  648. this.message.error("请填写正确手机号");
  649. return;
  650. }
  651. 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,}))$/
  652. if(!String(this.account.email).match(m)){
  653. this.message.error("邮箱格式有误");
  654. return;
  655. }
  656. // if(!this.account?.email && !this.account?.phone){
  657. // this.message.error("邮箱或手机号必须填写一项");
  658. // return;
  659. // }
  660. console.log(this.account.password);
  661. if(!(this.account.password.length >= 6 && this.account.password.length <= 18)){
  662. this.message.error('密码格式错误,请填写6-18位非空字符串(数字、大小写字母或英文符号)');
  663. return;
  664. }
  665. if(!await this.tbookSer.userFind(this.account.phone)){
  666. this.message.error('手机号已存在');
  667. return
  668. }
  669. return true
  670. }
  671. //移除部门
  672. async removeBranch(data: Parse.Object) {
  673. if (data?.get('user')?.id) {
  674. data?.get('user')?.set('department', null);
  675. await data?.get('user')?.save();
  676. this.message.error('移除成功');
  677. this.getProfile();
  678. }
  679. }
  680. removeBranchAll() {
  681. this.modal.confirm({
  682. nzTitle: '批量移除',
  683. nzContent: `请谨慎操作`,
  684. nzOkText: '确认',
  685. nzOkType: 'primary',
  686. nzOkDanger: true,
  687. nzOnOk: async () => {
  688. let selectedList = this.profiles.filter((item: any) =>
  689. this.setOfCheckedId.has(item?.id)
  690. );
  691. let romovePromiseList = selectedList.map((item: any) => {
  692. return new Promise(async (resolve) => {
  693. item?.get('user')?.set('department', null);
  694. await item?.get('user')?.save();
  695. resolve(true);
  696. });
  697. });
  698. try {
  699. await Promise.all(romovePromiseList);
  700. this.message.error('移除成功');
  701. this.getProfile();
  702. this.resetChange();
  703. } catch (err) {}
  704. },
  705. nzCancelText: '取消',
  706. nzOnCancel: () => console.log('Cancel'),
  707. });
  708. }
  709. //删除用户
  710. deleteSelected(data?:Parse.Object) {
  711. let filters = []
  712. if(data?.id){
  713. filters = [data?.id]
  714. }else{
  715. filters = Array.from(this.setOfCheckedId)
  716. }
  717. this.modal.confirm({
  718. nzTitle: '批量删除',
  719. nzContent: `删除后数据不可恢复,请谨慎操作`,
  720. nzOkText: '确认',
  721. nzOkType: 'primary',
  722. nzOkDanger: true,
  723. nzOnOk: async () => {
  724. let selectedList = this.profiles.filter((item: any) =>
  725. this.setOfCheckedId.has(item?.id)
  726. );
  727. let deletePromiseList = selectedList.map((item: any) => {
  728. return new Promise(async (resolve) => {
  729. await item.get('user')?.destroy()
  730. await item.destroy()
  731. resolve(true)
  732. });
  733. });
  734. try {
  735. await Promise.all(deletePromiseList);
  736. this.setOfCheckedId = new Set<string>();
  737. this.checkedAll = false
  738. this.getProfile();
  739. } catch (err) {}
  740. },
  741. nzCancelText: '取消',
  742. nzOnCancel: () => console.log('Cancel'),
  743. });
  744. }
  745. resetChange() {
  746. this.setOfCheckedId = new Set<string>();
  747. this.checkedAll = false;
  748. }
  749. }