page-role.component.ts 27 KB

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