import { PlanTaskType } from 'app/types' import { Component, Input, TemplateRef, ViewChild } from '@angular/core' import { FormControl, FormGroup } from '@angular/forms' import { AnyObject, TableOption } from 'app/shared/components/server-paginated-table' import { ApiService } from 'app/services' import { SharedModule } from 'app/shared/shared.module' import { lastValueFrom, of } from 'rxjs' import { NzModalRef, NzModalService } from 'ng-zorro-antd/modal' import { NzMessageService } from 'ng-zorro-antd/message' import { NzSafeAny } from 'ng-zorro-antd/core/types' import { ASSET_TYPE } from 'app/constants' import { AssetBasicTeamFormComponent } from 'app/components/asset-basic-team-form/asset-basic-team-form.component' import { StatusTagComponent } from 'app/components/status-tag/status-tag.component' import { PlanFormComponent } from '../plan-form/plan-form.component' @Component({ selector: 'app-task-list', standalone: true, imports: [SharedModule, StatusTagComponent], templateUrl: './task-list.component.html', styleUrl: './task-list.component.less', }) export class TaskListComponent { constructor( private api: ApiService, private modal: NzModalService, private msg: NzMessageService, ) {} @Input() type: PlanTaskType = 'inspection' queryForm = new FormGroup({ name: new FormControl(), // status: new FormControl(), }) table = new TableOption(this.fetchData.bind(this)) copyNum = 1 ASSET_TYPE = ASSET_TYPE ngOnInit(): void { this.table .setColumn([ { key: 'teamKey', title: '任务名称', visible: true }, { key: 'teamName', title: '任务状态', visible: true }, { key: 'status', title: '任务来源', visible: true }, { key: 'createUser', title: '开始时间', visible: true }, { key: 'createTime', title: '任务时长', visible: true }, { key: 'createTime', title: '完成时间', visible: true }, { key: 'createTime', title: '设备总数', visible: true }, { key: '_value', title: '待处理设备数', visible: true }, { key: 'remark', title: '已处理设备数', visible: true }, { key: 'remark', title: '执行班组', visible: true }, ]) .setRowOperate([ { title: '查看', onClick: (v) => { this.onCreate(v, true) }, }, { title: '受理', onClick: this.shouli.bind(this) }, { title: '指派', onClick: this.zhipai.bind(this) }, { title: '处置', onClick: this.chuzhi.bind(this) }, { title: '报表', onClick: this.deleteItem.bind(this) }, ]) } fetchData(p: {}, q: AnyObject) { return this.api.getTaskPage({ ...p, ...q, jobType: this.type }) } shouli(item?: NzSafeAny) { const ids = item ? [item.teamId] : Array.from(this.table.ref.selected) this.modal.confirm({ nzTitle: '是否确定受理当前设备流程?', nzContent: `受理后你将作为该任务的责任人,其他人员无法受理!`, nzOnOk: async () => { const res = await lastValueFrom(this.api.deleteUserTeam(ids)) this.msg.success(res.desc) this.table.ref.reload() }, }) } zhipai(item?: NzSafeAny) { const ids = item ? [item.teamId] : Array.from(this.table.ref.selected) this.modal.confirm({ nzTitle: '请选择设备任务处置人员', nzContent: ``, nzOnOk: async () => { const res = await lastValueFrom(this.api.deleteUserTeam(ids)) this.msg.success(res.desc) this.table.ref.reload() }, }) } chuzhi(data: NzSafeAny) {} onCreate(data?: NzSafeAny, preview?: boolean) { let nzTitle = data ? '编辑任务' : '添加任务' if (preview) { nzTitle = '预览任务' } this.modal.create({ nzTitle, nzContent: PlanFormComponent, nzWidth: '80vw', nzWrapClassName: 'modal-lg', nzData: { value: data, preview, }, nzOnOk: async (e) => { const vals = e.getValues() if (vals) { const res = await lastValueFrom( this.api.savePlan({ ...vals, planType: this.type, }), ) this.msg.success(res.desc) this.table.ref.reload() return true } return false }, }) } deleteItem(item?: NzSafeAny) { const ids = item ? [item.teamId] : Array.from(this.table.ref.selected) this.modal.confirm({ nzTitle: '警告', nzContent: `是否要删除${ids.length}个任务?`, nzOnOk: async () => { const res = await lastValueFrom(this.api.deleteUserTeam(ids)) this.msg.success(res.desc) this.table.ref.reload() }, }) } }