process-list.component.ts 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  1. import { Component, OnInit, ViewChild } from '@angular/core';
  2. import { ActivatedRoute, RouterOutlet, Router } 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 } 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 { NzModalService } from 'ng-zorro-antd/modal';
  28. interface nodes {
  29. title: string;
  30. key: string;
  31. isLeaf?: boolean;
  32. isParent?: boolean;
  33. children?: Array<any>;
  34. }
  35. interface depart {
  36. name: string;
  37. id?: string;
  38. code?: string;
  39. desc?: string;
  40. parent?: object | any;
  41. branch: string;
  42. }
  43. @Component({
  44. selector: 'app-process-list',
  45. templateUrl: './process-list.component.html',
  46. styleUrls: ['./process-list.component.scss'],
  47. imports: [
  48. CommonModule,
  49. CommonCompModule,
  50. RouterOutlet,
  51. CompTableListComponent,
  52. NzSpaceModule,
  53. NzPageHeaderModule,
  54. NzBreadCrumbModule,
  55. NzTreeModule,
  56. NzCheckboxModule,
  57. NzEmptyModule,
  58. NzModalModule,
  59. NzRadioModule,
  60. ],
  61. standalone: true,
  62. })
  63. export class ProcessListComponent implements OnInit {
  64. @ViewChild(CompTableListComponent) list: CompTableListComponent | undefined;
  65. // _Role = _Role
  66. Department = Department;
  67. user: Parse.User | undefined;
  68. className: string | undefined;
  69. queryParams: any | undefined;
  70. fieldsArray: Array<any> | undefined;
  71. searchValue: string = ''; //搜索内容
  72. searchValuePro: string = ''; //搜索流程内容
  73. nodes: Array<nodes | any> = [];
  74. currentDepart: nodes | any = null;
  75. eduProcessList: Array<Parse.Object> = [];
  76. statusMap: any = {};
  77. eduProcessLength: number = 0;
  78. pageSize: number = 10;
  79. pageIndex: number = 1;
  80. checkedShowFilter: boolean = false;
  81. checkedAll: boolean = false; //全选
  82. indeterminate = false;
  83. loading = false;
  84. isVisible: boolean = false;
  85. activatedNode: NzTreeNode | any; //当前选择节点
  86. editType: string = 'add'; //弹窗类型
  87. activeDepart?: Parse.Object; //当前编辑部门
  88. editObject: depart = {
  89. name: '',
  90. code: '',
  91. desc: '',
  92. parent: {},
  93. branch: '',
  94. };
  95. parentMap: Array<any> = [];
  96. parentList: Array<any> = [];
  97. setOfCheckedId = new Set<string>();
  98. formatStatus = (e: any) => {
  99. if (e.get('status') == '100') {
  100. return {
  101. title: '已暂停',
  102. color: 'lime',
  103. strat: true,
  104. stop: true,
  105. end: false,
  106. del: false,
  107. };
  108. }
  109. if (
  110. e?.get('deadline') &&
  111. new Date() > new Date(e?.get('deadline')) &&
  112. e?.get('status') == '400'
  113. ) {
  114. return {
  115. title: '已结束',
  116. color: 'gold',
  117. strat: false,
  118. stop: false,
  119. end: false,
  120. del: true,
  121. };
  122. }
  123. if (e?.get('status') == '400') {
  124. return {
  125. title: '已完成',
  126. color: 'green',
  127. strat: false,
  128. stop: false,
  129. end: true,
  130. del: false,
  131. };
  132. }
  133. if (!e?.get('startDate') || new Date() < new Date(e.get('startDate'))) {
  134. return {
  135. title: '未开始',
  136. color: 'grey',
  137. strat: true,
  138. stop: false,
  139. end: false,
  140. del: true,
  141. };
  142. }
  143. if (
  144. e.get('status') == '200' &&
  145. e?.get('startDate') &&
  146. new Date() >= new Date(e?.get('startDate'))
  147. ) {
  148. return {
  149. title: '遴选中',
  150. color: 'blue',
  151. strat: false,
  152. stop: true,
  153. end: true,
  154. del: false,
  155. };
  156. }
  157. if (e?.get('deadline') && new Date() > new Date(e?.get('deadline'))) {
  158. return {
  159. title: '已逾期',
  160. color: 'red',
  161. strat: true,
  162. stop: false,
  163. end: false,
  164. del: true,
  165. };
  166. }
  167. if (e.get('status') == '300') {
  168. return {
  169. title: '已公示',
  170. color: 'red',
  171. strat: false,
  172. stop: true,
  173. end: true,
  174. del: false,
  175. };
  176. }
  177. return;
  178. };
  179. /* 新建组织 */
  180. branchObj: any = {
  181. name: '',
  182. code: '',
  183. desc: '',
  184. };
  185. constructor(
  186. private route: Router,
  187. private activeRoute: ActivatedRoute,
  188. private nzContextMenuService: NzContextMenuService,
  189. private message: NzMessageService,
  190. private modal: NzModalService
  191. ) {
  192. this.user = Parse.User.current();
  193. this.className = this.Department.className;
  194. this.fieldsArray = this.Department.fieldsArray;
  195. this.queryParams = {
  196. where: {
  197. isDeleted: { $ne: true },
  198. },
  199. };
  200. }
  201. ngOnInit(): void {
  202. this.activeRoute.paramMap.subscribe(async (params) => {
  203. this.nodes = await this.getDepart();
  204. });
  205. }
  206. async getDepart(
  207. parent?: string,
  208. searchValue?: string
  209. ): Promise<Array<nodes>> {
  210. let nodes: any = [];
  211. let query = new Parse.Query('Department');
  212. query.equalTo('parent', parent ? parent : undefined);
  213. searchValue && query.contains('name', searchValue);
  214. query.notEqualTo('isDeleted', true);
  215. query.select('code', 'name', 'branch', 'parent', 'type');
  216. query.descending('createdAt');
  217. query.limit(2000);
  218. let res = await query.find();
  219. res.forEach((item) => {
  220. nodes.push({
  221. title: item.get('name'),
  222. key: item.id,
  223. children: [],
  224. // isParent: item.get('type') =='单位' ? true : false, //是否是最下级
  225. isLeaf: true,
  226. });
  227. });
  228. return nodes;
  229. }
  230. async onSearch(e: string) {
  231. this.nodes = await this.getDepart('', e);
  232. }
  233. onSearchPro(e: string) {
  234. this.pageIndex = 1;
  235. this.getEduProcess();
  236. }
  237. changeDepart(e: any) {
  238. this.currentDepart = e;
  239. this.setOfCheckedId = new Set<string>();
  240. this.checkedAll = false;
  241. this.pageIndex = 1;
  242. this.getEduProcess();
  243. }
  244. async getEduProcess() {
  245. this.eduProcessList = [];
  246. this.loading = true;
  247. let query1 = Parse.Query.fromJSON('EduProcess', {
  248. where: {
  249. $or: [
  250. {
  251. name: { $regex: `.*${this.searchValuePro}.*` },
  252. },
  253. ],
  254. },
  255. });
  256. let query2 = Parse.Query.fromJSON('EduProcess', {
  257. where: {
  258. $or: [
  259. {
  260. code: { $regex: `.*${this.searchValuePro}.*` },
  261. },
  262. ],
  263. },
  264. });
  265. let query = Parse.Query.or(query1, query2);
  266. query.include('profileSubmitted', 'profileSubmitted.user');
  267. query.notEqualTo('isDeleted', true);
  268. query.equalTo('branch', this.currentDepart.key);
  269. this.eduProcessLength = await query.count();
  270. query.skip(this.pageSize * (this.pageIndex - 1));
  271. query.limit(this.pageSize);
  272. query.descending('createdAt');
  273. let r = await query.find();
  274. // let list: any[] = [];
  275. r.forEach((item) => {
  276. // let _item = item.toJSON();
  277. // _item['checked'] = false;
  278. // _item['state'] = this.formatStatus(_item);
  279. this.statusMap[item.id] = this.formatStatus(item);
  280. });
  281. this.eduProcessList = r;
  282. this.loading = false;
  283. }
  284. //分页切换
  285. pageIndexChange(e: any) {
  286. console.log(e);
  287. this.pageIndex = e;
  288. this.getEduProcess();
  289. }
  290. onAllChecked(checked: boolean): void {
  291. console.log(checked);
  292. this.eduProcessList.forEach((item) => {
  293. if (checked) {
  294. this.setOfCheckedId.add(item.id);
  295. } else {
  296. this.setOfCheckedId.delete(item.id);
  297. }
  298. });
  299. if (!checked) {
  300. this.setOfCheckedId = new Set<string>();
  301. }
  302. this.checkedAll = checked;
  303. }
  304. onItemChecked(id: string, e: boolean) {
  305. if (e) {
  306. this.setOfCheckedId.add(id);
  307. } else {
  308. this.setOfCheckedId.delete(id);
  309. }
  310. this.checkedAll = this.eduProcessList.every((item) =>
  311. this.setOfCheckedId.has(item.id)
  312. );
  313. }
  314. //新建打开弹窗
  315. async showModalDepart(type: string) {
  316. this.parentList = this.nodes;
  317. if (type == 'edit') {
  318. let query = new Parse.Query('Department');
  319. let r = await query.get(this.activatedNode?.key);
  320. this.activeDepart = r;
  321. this.parentMap = this.formatNode(this.activatedNode);
  322. if (this.activatedNode?.parentNode?.origin.key) {
  323. this.parentList = await this.getDepart(
  324. this.activatedNode.parentNode.origin.key
  325. );
  326. }
  327. }
  328. this.editType = type;
  329. this.isVisible = true;
  330. }
  331. //格式化链
  332. formatNode(node: NzTreeNode): Array<any> {
  333. let arr = [];
  334. if (node.parentNode?.origin.title) {
  335. arr.push({
  336. title: node.parentNode?.origin.title,
  337. key: node.parentNode?.origin.key,
  338. });
  339. arr.unshift(...this.formatNode(node.parentNode));
  340. }
  341. return arr;
  342. }
  343. async onPre(data?: any, index?: number) {
  344. if (!data) {
  345. this.parentList = await this.getDepart();
  346. this.parentMap = [];
  347. return;
  348. }
  349. if (index == this.parentMap.length - 1) return;
  350. this.parentMap.splice(index || 0 + 1);
  351. this.parentList = await this.getDepart(data?.key);
  352. }
  353. //选择所属类别下级列表
  354. async onCheckedDepart(e: any, checked?: boolean) {
  355. console.log(e);
  356. if (checked) {
  357. this.editObject = {
  358. name: e.title,
  359. code: '',
  360. desc: '',
  361. parent: e,
  362. branch: '',
  363. };
  364. return;
  365. }
  366. this.parentMap.push({
  367. title: e.title,
  368. key: e.key,
  369. });
  370. this.parentList = await this.getDepart(e?.key);
  371. }
  372. /* 组织 */
  373. showModalOrganize() {
  374. // this.message.warning('权限灰度中');
  375. this.branchObj = {
  376. name: '',
  377. code: '',
  378. desc: '',
  379. };
  380. this.isVisible = true;
  381. }
  382. async handleOk(): Promise<void> {
  383. if (!this.branchObj?.name) {
  384. this.message.warning('组织名称不能为空');
  385. }
  386. let obj = Parse.Object.extend('Department');
  387. let depart = new obj();
  388. depart.set('name', this.branchObj?.name);
  389. depart.set('desc', this.branchObj?.desc);
  390. depart.set('code', this.branchObj?.code);
  391. await depart.save();
  392. this.isVisible = false;
  393. this.message.success('新建成功');
  394. this.nodes = await this.getDepart();
  395. }
  396. handleCancel(): void {
  397. console.log('Button cancel clicked!');
  398. this.isVisible = false;
  399. this.activatedNode = undefined;
  400. this.parentMap = [];
  401. }
  402. statusSelected(type: string) {
  403. let map: any = {
  404. strat: '开始',
  405. stop: '暂停',
  406. end: '结束',
  407. };
  408. this.modal.confirm({
  409. nzTitle: '批量删除',
  410. nzContent:
  411. type == 'del'
  412. ? `删除后数据不可恢复,请谨慎操作`
  413. : `确认批量${map[type]}吗`,
  414. nzOkText: '确认',
  415. nzOkType: 'primary',
  416. nzOkDanger: map[type] ? true : false,
  417. nzOnOk: async () => {
  418. let selectedList = this.eduProcessList.filter((item: any) =>
  419. this.setOfCheckedId.has(item?.id)
  420. );
  421. let deletePromiseList = selectedList.map((item: any) => {
  422. return new Promise((resolve) => {
  423. resolve(this.onStatusChange(item, type));
  424. });
  425. });
  426. try {
  427. await Promise.all(deletePromiseList);
  428. this.getEduProcess();
  429. } catch (err) {}
  430. },
  431. nzCancelText: '取消',
  432. nzOnCancel: () => console.log('Cancel'),
  433. });
  434. }
  435. toUrl(url: string, params?: object) {
  436. if (params) {
  437. this.route.navigate([url, params]);
  438. } else {
  439. this.route.navigate([url]);
  440. }
  441. }
  442. //暂停流程
  443. async onStatusChange(
  444. data: Parse.Object,
  445. type: string,
  446. end?: boolean
  447. ): Promise<void> {
  448. console.log(data, type);
  449. switch (type) {
  450. case 'strat':
  451. if (data?.get('status') == '100') {
  452. data?.set('status', '200');
  453. }
  454. if (!data?.get('startDate') || data?.get('startDate') > new Date()) {
  455. data?.set('startDate', new Date());
  456. }
  457. if (!data?.get('deadline') || data?.get('deadline') < new Date()) {
  458. data?.set(
  459. 'deadline',
  460. new Date(new Date().getTime() + 60 * 1000 * 60 * 24 * 7)
  461. );
  462. console.warn('结束时间延长一周之后');
  463. }
  464. break;
  465. case 'stop':
  466. data?.set('status', '100');
  467. break;
  468. case 'end':
  469. data?.set('status', '400');
  470. data?.set('deadline', new Date());
  471. break;
  472. case 'del':
  473. data?.set('isDeleted', true);
  474. break;
  475. }
  476. await data.save();
  477. if (end) {
  478. this.getEduProcess();
  479. }
  480. }
  481. }