import { Component, OnInit, ViewContainerRef } from '@angular/core'; import { NzMessageService } from 'ng-zorro-antd/message'; import { NzModalService } from 'ng-zorro-antd/modal'; import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import { PlanAdjustmentComponent } from './plan-adjustment/plan-adjustment.component' import { HttpClient } from '@angular/common/http'; import { CheckagainComponent } from './checkagain/checkagain.component'; @Component({ selector: 'app-da-oneself-plan', templateUrl: './da-oneself-plan.component.html', styleUrls: ['./da-oneself-plan.component.scss'] }) export class DaOneselfPlanComponent implements OnInit { constructor(private http: HttpClient, private modal: NzModalService, private message: NzMessageService, private viewContainerRef: ViewContainerRef) { } validateForm!: FormGroup; OrganizationId ngOnInit(): void { this.OrganizationId = JSON.parse(sessionStorage.getItem('userData')).organizationId this.selectedMonth = new Date().getMonth() + 1 this.getTasks() this.getAllStation() this.getTuesdayThursdayNum() } selectedMonth selectedYear = 2024 selectedTime selectMonth(item) { this.selectedMonth = item.id this.getTuesdayThursdayNum() this.getTasks() this.getAllStation() } selectYear(e) { this.selectedYear = e console.log('年', e) this.getTuesdayThursdayNum() this.getTasks() this.getAllStation() } //当月有几个周二周四 TuesdayThursdayNum = 0 getTuesdayThursdayNum() { let selectedTime = this.selectedYear + '-' + this.selectedMonth + '-' + '01' this.http.get(`/api/TaskTargets/GetTargetCount/${selectedTime}`).subscribe((data: any) => { console.log('最大日期', data) this.TuesdayThursdayNum = data }) } months = [ { id: 1, name: '1月', isable: true }, { id: 2, name: '2月', isable: true }, { id: 3, name: '3月', isable: true }, { id: 4, name: '4月', isable: true }, { id: 5, name: '5月', isable: true }, { id: 6, name: '6月', isable: true }, { id: 7, name: '7月', isable: true }, { id: 8, name: '8月', isable: true }, { id: 9, name: '9月', isable: true }, { id: 10, name: '10月', isable: true }, { id: 11, name: '11月', isable: true }, { id: 12, name: '12月', isable: true } ] isExpand = false expand() { this.isExpand = !this.isExpand } formatOne = (percent: number): string => `${percent}%\n完成率`; //上部卡片 cardData = [ { name: '双随机', isDetails: false, isLoading: false, background: '#1D9DFF', icon: 'suiji.png', passed: 0, inspected: 0, percentage: 0, data: [] }, { name: '行政许可', isDetails: false, isLoading: false, background: '#42B983', icon: 'xuke.png', passed: 0, inspected: 0, percentage: 0, data: [] }, { name: '熟悉演练', isDetails: false, isLoading: false, background: '#9D80FF', icon: 'yanlian.png', passed: 0, inspected: 0, percentage: 0, data: [] }, { name: '联络指导', isDetails: false, isLoading: false, background: '#5483EA', icon: 'zhidao.png', passed: 0, inspected: 0, percentage: 0, data: [] }, { name: '消防宣传', isDetails: false, isLoading: false, background: '#FF5D2A', icon: 'xuanchuan.png', passed: 0, inspected: 0, percentage: 0, data: [] }, { name: '投诉举报', isDetails: false, isLoading: false, background: '#5087FF', icon: 'tousu.png', passed: 0, inspected: 0, percentage: 0, data: [] }, { name: '火灾调查', isDetails: false, isLoading: false, background: '#FF404D', icon: 'huozai.png', passed: 0, inspected: 0, percentage: 0, data: [] } ] openDetails(data, type) { data.isDetails = type } async getTasks() { this.cardData.forEach((item, key) => { item.data = [] item.passed = 0 item.inspected = 0 item.percentage = 0 }); let selectedTime = this.selectedYear + '-' + this.selectedMonth + '-' + '01' let params = { Month: selectedTime, OrganizationId: this.OrganizationId, PageNumber: 1, PageSize: 9999, approvalStatuses: ['待处理', '通过', '驳回', '待检查', '已检查'] } return await new Promise((resolve, reject) => { this.http.get('/api/PlanTasks', { params: params }).subscribe((data: any) => { // console.log('任务申请列表', data.items); data.items.forEach(element => { this.cardData.forEach((item, key) => { element.taskType == item.name ? this.cardData[key].data.push(element) : null }); }); this.cardData.forEach(element => { element.data.forEach(item => { item.approvalStatus == '待检查' ? element.passed += 1 : null item.approvalStatus == '已检查 ' ? element.inspected += 1 : null }) }) this.cardData.forEach(element => { element.percentage = Math.round((element.inspected / element.data.length) * 100) || 0 }) resolve(data) console.log('并入卡片数据', this.cardData) }) }) } //获得辖区下所有救援站 stationData = [] getAllStation() { let params = { ContainsChildren: "true", PageNumber: 1, PageSize: 9999 } this.http.get('/api/Organizations', { params: params }).subscribe((data: any) => { data.items = data.items.filter(element => { return element.level == 'squadron' }); data.items.forEach(element => { element.isExpand = false element.isLoading = false }); this.stationData = data.items this.stationData[0].isExpand = true this.stationData.forEach(item => { this.getTaskListOfStation(item) }) }) } expandcarditem(item) { item.isExpand = !item.isExpand } //获得消防站下的所有任务 PageNumber = 1 PageSize = 9999 getTaskListOfStation(item) { let selectedTime = this.selectedYear + '-' + this.selectedMonth + '-' + '01' let params = { Month: selectedTime, CompanyOrganizationId: item.id, PageNumber: this.PageNumber, approvalStatuses: ['通过', '待检查', '已检查'], PageSize: this.PageSize } item.isLoading = true this.http.get('/api/PlanTasks', { params: params }).subscribe({ next: (data: any) => { item.isLoading = false let listData = [ { name: '双随机', background: '#1D9DFF', icon: 'suiji.png', scale: '0/0', data: [], inspected: 0, finished: 0 }, { name: '行政许可', background: '#42B983', icon: 'xuke.png', scale: '0/0', data: [], inspected: 0, finished: 0 }, { name: '熟悉演练', background: '#9D80FF', icon: 'yanlian.png', scale: '0/0', data: [], inspected: 0, finished: 0 }, { name: '联络指导', background: '#5483EA', icon: 'zhidao.png', scale: '0/0', data: [], inspected: 0, finished: 0 }, { name: '消防宣传', background: '#FF5D2A', icon: 'xuanchuan.png', scale: '0/0', data: [], inspected: 0, finished: 0 }, { name: '投诉举报', background: '#5087FF', icon: 'tousu.png', scale: '0/0', data: [], inspected: 0, finished: 0 }, { name: '火灾调查', background: '#FF404D', icon: 'huozai.png', scale: '0/0', data: [], inspected: 0, finished: 0 } ] data.items.forEach(element => { listData.forEach((item, key) => { element.taskType == item.name ? listData[key].data.push(element) : null }); }); for (let index = 0; index < listData.length; index++) { const element = listData[index]; if (element.data.length == 0) { listData.splice(index, 1) index-- } } item.data = listData console.log('当前登录用户所有通过的任务', item); item.allUnitsNum = 0 item.awaitInspect = 0 item.inspected = 0 item.finished = 0 item.data.forEach(element => { item.allUnitsNum += element.data.length element.data.forEach(i => { i.approvalStatus == '待检查' ? item.awaitInspect += 1 : null i.approvalStatus == '已检查' ? item.inspected += 1 : null i.approvalStatus == '待检查' ? element.inspected += 1 : null i.approvalStatus == '已检查' ? element.finished += 1 : null }); }); item.percentage = Math.round((item.inspected / item.allUnitsNum) * 100) }, error: (err) => { this.message.create('warning', '获取数据失败'); item.isLoading = false } }) } adjustment(item) { let selectedTime = this.selectedYear + '-' + this.selectedMonth + '-' + '01' const modal = this.modal.create({ nzTitle: "任务调整", nzContent: PlanAdjustmentComponent, nzViewContainerRef: this.viewContainerRef, nzWidth: 900, nzFooter: null, nzComponentParams: { data: JSON.parse(JSON.stringify(item)), time: selectedTime, level: '大队' } }); const instance = modal.getContentComponent(); modal.afterClose.subscribe(result => { this.getTasks() this.getTaskListOfStation(item) }); } checkagain(i) { if (i.recheckStatus == '需要复查') { this.message.create('warning', '暂未去该单位复查不合格项'); return } let arr = JSON.parse(i.resultDataHistory) let obj = JSON.parse(arr[arr.length - 1]) console.log(obj) const modal = this.modal.create({ nzTitle: '复查记录(' + i.recheckStatus + ')', nzContent: CheckagainComponent, nzViewContainerRef: this.viewContainerRef, nzWidth: 1200, nzFooter: null, nzComponentParams: { data: obj } }); const instance = modal.getContentComponent(); modal.afterClose.subscribe(result => { // this.getTasks() // this.getTaskListOfStation(item) }); } }