import { Component, OnInit, ViewChild } from '@angular/core'; import { ActivatedRoute, RouterOutlet, Router } from '@angular/router'; // import { CompTableListComponent } from '../../../../app/comp-table/comp-table-list/comp-table-list.component'; import _Role from '../../../../schemas/_Role'; // import { TranslateService } from '@ngx-translate/core'; import * as Parse from 'parse'; import { CommonModule } from '@angular/common'; import { Department } from '../../../../schemas/Department'; import { NzSpaceModule } from 'ng-zorro-antd/space'; import { NzPageHeaderModule } from 'ng-zorro-antd/page-header'; import { NzBreadCrumbModule } from 'ng-zorro-antd/breadcrumb'; import { CommonCompModule } from '../../../../services/common.modules'; import { NzModalModule } from 'ng-zorro-antd/modal'; import { NzFormatEmitEvent, NzTreeModule, NzTreeNode, } from 'ng-zorro-antd/tree'; import { NzContextMenuService, NzDropdownMenuComponent, } from 'ng-zorro-antd/dropdown'; import { NzCheckboxModule } from 'ng-zorro-antd/checkbox'; import { NzEmptyModule } from 'ng-zorro-antd/empty'; import { NzRadioModule } from 'ng-zorro-antd/radio'; import { NzMessageService } from 'ng-zorro-antd/message'; import { NzModalService } from 'ng-zorro-antd/modal'; import { NzPopoverModule } from 'ng-zorro-antd/popover'; import { setHours } from 'date-fns'; import { NzDatePickerModule } from 'ng-zorro-antd/date-picker'; import { textbookServer } from '../../../../services/textbook'; interface nodes { title: string; key: string; isLeaf?: boolean; isParent?: boolean; children?: Array; } interface depart { name: string; id?: string; code?: string; desc?: string; parent?: object | any; branch: string; } @Component({ selector: 'app-process-list', templateUrl: './process-list.component.html', styleUrls: ['./process-list.component.scss'], imports: [ CommonModule, CommonCompModule, RouterOutlet, // CompTableListComponent, NzSpaceModule, NzPageHeaderModule, NzBreadCrumbModule, NzTreeModule, NzCheckboxModule, NzEmptyModule, NzModalModule, NzRadioModule, NzPopoverModule, NzDatePickerModule ], standalone: true, }) export class ProcessListComponent implements OnInit { // @ViewChild(CompTableListComponent) list: CompTableListComponent | undefined; timeDefaultValue = setHours(new Date(), 0); // _Role = _Role Department = Department; user: Parse.User | undefined; className: string | undefined; queryParams: any | undefined; fieldsArray: Array | undefined; searchValue: string = ''; //搜索内容 searchValuePro: string = ''; //搜索流程内容 nodes: Array = []; currentDepart: nodes | any = null; eduProcessList: Array = []; statusMap: any = {}; eduProcessLength: number = 0; pageSize: number = 10; pageIndex: number = 1; checkedShowFilter: boolean = false; checkedAll: boolean = false; //全选 indeterminate = false; loading = false; isVisible: boolean = false; activatedNode: NzTreeNode | any; //当前选择节点 editType: string = 'add'; //弹窗类型 activeDepart?: Parse.Object; //当前编辑部门 editObject: depart = { name: '', code: '', desc: '', parent: {}, branch: '', }; parentMap: Array = []; parentList: Array = []; setOfCheckedId = new Set(); formatStatus = (e: any) => { if (e.get('status') == '100') { return { title: '已暂停', color: 'lime', strat: true, stop: true, end: false, del: false, }; } if ( e?.get('deadline') && new Date() > new Date(e?.get('deadline')) && e?.get('status') == '400' ) { return { title: '已结束', color: 'gold', strat: false, stop: false, end: false, del: true, collect:true }; } if(e?.get('collectStartData') && new Date() < new Date(e?.get('collectStartData'))){ return { title: '待收集', color: 'default', strat: false, stop: false, end: false, del: false, collect:true }; } if(e?.get('collectStartData') && new Date() > new Date(e?.get('collectStartData')) && new Date() < e?.get('collectEndData')){ return { title: '收集中', color: 'orange', strat: false, stop: false, end: false, del: false, collect:true }; } if (e?.get('status') == '400') { return { title: '已完成', color: 'green', strat: false, stop: false, end: true, del: false, collect:true }; } if (!e?.get('startDate') || new Date() < new Date(e.get('startDate'))) { return { title: '未开始', color: 'grey', strat: true, stop: false, end: false, del: true, }; } if (e?.get('deadline') && new Date() > new Date(e?.get('deadline'))) { return { title: '已逾期', color: 'red', strat: true, stop: false, end: false, del: true, }; } if ( e.get('status') == '200' && e?.get('startDate') && new Date() >= new Date(e?.get('startDate')) ) { return { title: '遴选中', color: 'blue', strat: false, stop: true, end: true, del: false, }; } if (e.get('status') == '300') { return { title: '已公示', color: 'red', strat: false, stop: true, end: true, del: false, }; } if (e.get('status') == '201') { return { title: '评审中', color: 'cyan', strat: false, stop: true, end: true, del: false, }; } return; }; /* 新建组织 */ branchObj: any = { name: '', code: '', desc: '', }; showModal:boolean = false eduProcess?:Parse.Object //当前编辑流程 textBookList:Array = [] //流程教材列表(推荐) collectStartData:any collectEndData:any constructor( public tbookSer: textbookServer, private route: Router, private activeRoute: ActivatedRoute, private nzContextMenuService: NzContextMenuService, private message: NzMessageService, private modal: NzModalService ) { this.user = Parse.User.current(); this.className = this.Department.className; this.fieldsArray = this.Department.fieldsArray; this.queryParams = { where: { isDeleted: { $ne: true }, }, }; } ngOnInit(): void { this.activeRoute.paramMap.subscribe(async (params) => { this.nodes = await this.getDepart(); }); } async getDepart( parent?: string, searchValue?: string ): Promise> { let nodes: any = []; let query = new Parse.Query('Department'); query.equalTo('parent', parent ? parent : undefined); searchValue && query.contains('name', searchValue); query.notEqualTo('isDeleted', true); query.select('code', 'name', 'branch', 'parent', 'type'); query.descending('createdAt'); query.limit(2000); let res = await query.find(); res.forEach((item) => { nodes.push({ title: item.get('name'), key: item.id, children: [], // isParent: item.get('type') =='单位' ? true : false, //是否是最下级 isLeaf: true, }); }); return nodes; } async onSearch(e: string) { this.nodes = await this.getDepart('', e); } onSearchPro(e: string) { this.pageIndex = 1; this.getEduProcess(); } changeDepart(e: any) { this.currentDepart = e; this.setOfCheckedId = new Set(); this.checkedAll = false; this.pageIndex = 1; this.getEduProcess(); } async getEduProcess() { this.eduProcessList = []; this.loading = true; let query1 = Parse.Query.fromJSON('EduProcess', { where: { $or: [ { name: { $regex: `.*${this.searchValuePro}.*` }, }, ], }, }); let query2 = Parse.Query.fromJSON('EduProcess', { where: { $or: [ { code: { $regex: `.*${this.searchValuePro}.*` }, }, ], }, }); let query = Parse.Query.or(query1, query2); query.include('profileSubmitted', 'profileSubmitted.user'); query.notEqualTo('isDeleted', true); this.currentDepart?.key && query.equalTo('branch', this.currentDepart.key); this.eduProcessLength = await query.count(); query.skip(this.pageSize * (this.pageIndex - 1)); query.limit(this.pageSize); query.descending('createdAt'); let r = await query.find(); // let list: any[] = []; r.forEach((item) => { // let _item = item.toJSON(); // _item['checked'] = false; // _item['state'] = this.formatStatus(_item); this.statusMap[item.id] = this.formatStatus(item); }); this.eduProcessList = r; this.loading = false; } //分页切换 pageIndexChange(e: any) { console.log(e); this.pageIndex = e; this.getEduProcess(); } onAllChecked(checked: boolean): void { console.log(checked); this.eduProcessList.forEach((item) => { if (checked) { this.setOfCheckedId.add(item.id); } else { this.setOfCheckedId.delete(item.id); } }); if (!checked) { this.setOfCheckedId = new Set(); } this.checkedAll = checked; } onItemChecked(id: string, e: boolean) { if (e) { this.setOfCheckedId.add(id); } else { this.setOfCheckedId.delete(id); } this.checkedAll = this.eduProcessList.every((item) => this.setOfCheckedId.has(item.id) ); } //新建打开弹窗 async showModalDepart(type: string) { this.parentList = this.nodes; if (type == 'edit') { let query = new Parse.Query('Department'); let r = await query.get(this.activatedNode?.key); this.activeDepart = r; this.parentMap = this.formatNode(this.activatedNode); if (this.activatedNode?.parentNode?.origin.key) { this.parentList = await this.getDepart( this.activatedNode.parentNode.origin.key ); } } this.editType = type; this.isVisible = true; } //格式化链 formatNode(node: NzTreeNode): Array { let arr = []; if (node.parentNode?.origin.title) { arr.push({ title: node.parentNode?.origin.title, key: node.parentNode?.origin.key, }); arr.unshift(...this.formatNode(node.parentNode)); } return arr; } async onPre(data?: any, index?: number) { if (!data) { this.parentList = await this.getDepart(); this.parentMap = []; return; } if (index == this.parentMap.length - 1) return; this.parentMap.splice(index || 0 + 1); this.parentList = await this.getDepart(data?.key); } //选择所属类别下级列表 async onCheckedDepart(e: any, checked?: boolean) { console.log(e); if (checked) { this.editObject = { name: e.title, code: '', desc: '', parent: e, branch: '', }; return; } this.parentMap.push({ title: e.title, key: e.key, }); this.parentList = await this.getDepart(e?.key); } /* 组织 */ showModalOrganize() { // this.message.warning('权限灰度中'); this.branchObj = { name: '', code: '', desc: '', }; this.isVisible = true; } async handleOk(): Promise { if (!this.branchObj?.name) { this.message.warning('组织名称不能为空'); } let obj = Parse.Object.extend('Department'); let depart = new obj(); depart.set('name', this.branchObj?.name); depart.set('desc', this.branchObj?.desc); depart.set('code', this.branchObj?.code); await depart.save(); this.isVisible = false; this.message.success('新建成功'); this.nodes = await this.getDepart(); } handleCancel(): void { console.log('Button cancel clicked!'); this.isVisible = false; this.activatedNode = undefined; this.parentMap = []; this.showModal = false this.collectStartData = undefined this.collectEndData = undefined this.eduProcess = undefined this.textBookList = [] } statusSelected(type: string) { let map: any = { strat: '开始', stop: '暂停', end: '结束', del: '删除', }; this.modal.confirm({ nzTitle: `批量${map[type]}`, nzContent: type == 'del' ? `删除后数据不可恢复,请谨慎操作` : `确认批量${map[type]}吗`, nzOkText: '确认', nzOkType: 'primary', nzOkDanger: map[type] ? true : false, nzOnOk: async () => { let selectedList = this.eduProcessList.filter((item: any) => this.setOfCheckedId.has(item?.id) ); let deletePromiseList = selectedList.map((item: any) => { return new Promise((resolve) => { resolve(this.onStatusChange(item, type)); }); }); try { await Promise.all(deletePromiseList); this.getEduProcess(); } catch (err) {} }, nzCancelText: '取消', nzOnCancel: () => console.log('Cancel'), }); } toUrl(url: string, params?: object) { if (params) { this.route.navigate([url, params]); } else { this.route.navigate([url]); } } //暂停流程 async onStatusChange( data: Parse.Object, type: string, end?: boolean, ): Promise { console.log(data, type); switch (type) { case 'strat': if (data?.get('status') == '100') { data?.set('status', '200'); } if (!data?.get('startDate') || data?.get('startDate') > new Date()) { data?.set('startDate', new Date()); } if (!data?.get('deadline') || data?.get('deadline') < new Date()) { data?.set( 'deadline', new Date(new Date().getTime() + 60 * 1000 * 60 * 24 * 7) ); console.warn('结束时间延长一周之后'); } break; case 'stop': data?.set('status', '100'); break; case 'end': data?.set('status', '400'); data?.set('deadline', new Date()); break; case 'del': data?.set('isDeleted', true); break; } await data.save(); if (end) { this.getEduProcess(); } } //打开编辑收集文件弹窗 async openEditCollect(data:Parse.Object){ this.eduProcess = data this.collectStartData = this.eduProcess?.get('collectStartData') this.collectEndData = this.eduProcess?.get('collectEndData') let query = new Parse.Query('EduTextbook') query.equalTo('eduProcess',this.eduProcess?.id) query.notEqualTo('isDeleted',true) query.equalTo('status','400') query.equalTo('recommend', true); query.notEqualTo('discard', true); query.select('title') let r = await query.find() this.textBookList = r this.showModal = true } //保存收集文件设置 async editCollect(){ if(!this.collectStartData || !this.collectEndData || this.collectStartData > this.collectEndData){ this.message.warning('请设置正确的开始和截止时间') return } this.eduProcess?.set('collectStartData',this.collectStartData) this.eduProcess?.set('collectEndData',this.collectEndData) await this.eduProcess?.save() this.message.success('设置成功') this.getEduProcess() this.showModal = false } /* 短信通知 */ sendNoticeMSG(){ this.modal.confirm({ nzTitle: '短信通知', nzContent: '发送短信提醒所有已提交教材的教师及对应出版单位', nzOkText: '发送', nzOkType: 'primary', nzOkDanger: true, nzOnOk: () => { this.tbookSer.sendNoticeMSG() this.message.success('已发送') }, nzCancelText: '取消', nzOnCancel: () => console.log('Cancel') }); } }