|  |  |  | 
|---|
|  |  |  | import { environment } from "../../../../environments/environment"; | 
|---|
|  |  |  | import { environment } from '../../../../environments/environment'; | 
|---|
|  |  |  | import { zip } from 'rxjs/observable/zip'; | 
|---|
|  |  |  | import { Component, OnInit, OnDestroy } from '@angular/core'; | 
|---|
|  |  |  | import { NzMessageService } from 'ng-zorro-antd'; | 
|---|
|  |  |  | 
|---|
|  |  |  | activities: any[] = []; | 
|---|
|  |  |  | radarData: any[] = []; | 
|---|
|  |  |  | loading = true; | 
|---|
|  |  |  | public alarmData:any = {}; | 
|---|
|  |  |  | public alarmData: any = {}; | 
|---|
|  |  |  | public alertData = [[], [], [], []]; | 
|---|
|  |  |  | salesType = '0'; | 
|---|
|  |  |  | salesTotal = 0; | 
|---|
|  |  |  | salesPieData: any; | 
|---|
|  |  |  | members = [ | 
|---|
|  |  |  | { | 
|---|
|  |  |  | id: 'members-1', | 
|---|
|  |  |  | 
|---|
|  |  |  | end: null | 
|---|
|  |  |  | }; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | rankingListData: any[] = [ | 
|---|
|  |  |  | { title: `PM 2.5`, total: 230 }, | 
|---|
|  |  |  | { title: `PM 10`, total: 175 }, | 
|---|
|  |  |  | { title: `二氧化硫`, total: 123 }, | 
|---|
|  |  |  | { title: `二氧化氮`, total: 92 }, | 
|---|
|  |  |  | { title: `甲醛`, total: 39 }, | 
|---|
|  |  |  | { title: `氯气`, total: 24 }, | 
|---|
|  |  |  | { title: `一氧化碳`, total: 8 } | 
|---|
|  |  |  | ]; | 
|---|
|  |  |  | rankingListData: any[] = []; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | constructor( | 
|---|
|  |  |  | private deviceService: DeviceService, | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | selectedIndexChange(index) { | 
|---|
|  |  |  | if (!this.alarmData['_' + index]) { | 
|---|
|  |  |  | this.http2.get(environment.SERVER_BASH_URL + 'report/alarm-year', {params: {state: index > 0 ? index : null}}).subscribe((res: any) => { | 
|---|
|  |  |  | let data = []; | 
|---|
|  |  |  | for (let i = 0; i < res.data.length; i += 1) { | 
|---|
|  |  |  | let y = 0; | 
|---|
|  |  |  | if (!!res.data[i]) { | 
|---|
|  |  |  | y = res.data[i]; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | data.push({x: `${i + 1}月`, y: y}); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | this.alarmData['_' + index] = data; | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | this.rankingListData = []; | 
|---|
|  |  |  | if (!this.alarmData['_' + index]) { | 
|---|
|  |  |  | this.http2.get(environment.SERVER_BASH_URL + 'report/alarm-year', { params: { state: index > 0 ? index : null } }).subscribe((res: any) => { | 
|---|
|  |  |  | const data = []; | 
|---|
|  |  |  | for (let i = 0; i < res.data.length; i += 1) { | 
|---|
|  |  |  | data.push({ x: `${i + 1}月`, y: !!res.data[i] ? res.data[i] : 0 }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | this.alarmData['_' + index] = data; | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (this.alertData[index].length > 0) { | 
|---|
|  |  |  | this.alertData[index].forEach(item => { | 
|---|
|  |  |  | this.rankingListData.push( | 
|---|
|  |  |  | { | 
|---|
|  |  |  | title: item.x, | 
|---|
|  |  |  | total: item.y | 
|---|
|  |  |  | } | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | this.http2.get(environment.SERVER_BASH_URL + 'report/alarm-month', { params: { state: index > 0 ? index : null } }).subscribe((res: any) => { | 
|---|
|  |  |  | const data = []; | 
|---|
|  |  |  | for (let i = 0; i < res.data.length; i += 1) { | 
|---|
|  |  |  | for (const key in res.data[i]) { | 
|---|
|  |  |  | data.push({ x: key, y: res.data[i][key] }); | 
|---|
|  |  |  | this.rankingListData.push( | 
|---|
|  |  |  | { | 
|---|
|  |  |  | title: key, | 
|---|
|  |  |  | total: res.data[i][key] | 
|---|
|  |  |  | } | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | this.alertData[index] = data; | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | changeSaleType() { | 
|---|
|  |  |  | if (this.alertData[this.salesType].length > 0) { | 
|---|
|  |  |  | this.salesPieData = this.alertData[this.salesType]; | 
|---|
|  |  |  | this.salesTotal = this.salesPieData.reduce((pre, now) => now.y + pre, 0); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | this.http2.get(environment.SERVER_BASH_URL + 'report/alarm-month', { params: { state: this.salesType === '0' ? null : this.salesType } }).subscribe((res: any) => { | 
|---|
|  |  |  | const data = []; | 
|---|
|  |  |  | for (let i = 0; i < res.data.length; i += 1) { | 
|---|
|  |  |  | for (const key in res.data[i]) { | 
|---|
|  |  |  | data.push({ x: key, y: res.data[i][key] }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | this.salesPieData = this.alertData[this.salesType] = data; | 
|---|
|  |  |  | this.salesTotal = this.salesPieData.reduce((pre, now) => now.y + pre, 0); | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | ngOnInit() { | 
|---|
|  |  |  | this.selectedIndexChange(0); | 
|---|
|  |  |  | this.selectedIndexChange(0); | 
|---|
|  |  |  | this.changeSaleType(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // const today = new Date().getTime(); | 
|---|
|  |  |  | // const fakeDC = [60, 135, 70, 112, 80, 170, 200, 140, 52, 119, 164, 230]; | 
|---|
|  |  |  | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | // this.avgDeviceCount = (this.totalDeviceCount / 12).toFixed(0); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const alertData = []; | 
|---|
|  |  |  | const alertData_1 = []; | 
|---|
|  |  |  | const alertData_2 = []; | 
|---|
|  |  |  | const alertData_3 = []; | 
|---|
|  |  |  | for (let i = 0; i < 7; i += 1) { | 
|---|
|  |  |  | alertData.push({ x: this.rankingListData[i].title, y: Math.floor(Math.random() * 1000) + 500 }); | 
|---|
|  |  |  | alertData_1.push({ x: this.rankingListData[i].title, y: Math.floor(Math.random() * 1000) + 100 }); | 
|---|
|  |  |  | alertData_2.push({ x: this.rankingListData[i].title, y: Math.floor(Math.random() * 1000) + 200 }); | 
|---|
|  |  |  | alertData_3.push({ x: this.rankingListData[i].title, y: Math.floor(Math.random() * 1000) + 300 }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const visitData = []; | 
|---|
|  |  |  | const beginDay = new Date().getTime(); | 
|---|
|  |  |  | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | const res = { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | alertData: alertData, | 
|---|
|  |  |  | alertData_1: alertData_1, | 
|---|
|  |  |  | alertData_2: alertData_2, | 
|---|
|  |  |  | alertData_3: alertData_3, | 
|---|
|  |  |  |  | 
|---|
|  |  |  | visitData: visitData, | 
|---|
|  |  |  | visitData2: visitData2, | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | this.data = res; | 
|---|
|  |  |  | this.loading = false; | 
|---|
|  |  |  | this.changeSaleType(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | this.radarData = res.radarData; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | ]; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | salesType = '0'; | 
|---|
|  |  |  | salesPieData: any; | 
|---|
|  |  |  | salesTotal = 0; | 
|---|
|  |  |  | changeSaleType() { | 
|---|
|  |  |  | if (this.salesType == '0') { | 
|---|
|  |  |  | this.salesPieData = this.data.alertData; | 
|---|
|  |  |  | } else if (this.salesType == '1') { | 
|---|
|  |  |  | this.salesPieData = this.data.alertData_1; | 
|---|
|  |  |  | } else if (this.salesType == '2') { | 
|---|
|  |  |  | this.salesPieData = this.data.alertData_2; | 
|---|
|  |  |  | } else if (this.salesType == '3') { | 
|---|
|  |  |  | this.salesPieData = this.data.alertData_3; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (this.salesPieData) this.salesTotal = this.salesPieData.reduce((pre, now) => now.y + pre, 0); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | handlePieValueFormat(value: any) { | 
|---|