| | |
| | | import {Component, OnInit} from '@angular/core'; |
| | | import {HttpClient} from '@angular/common/http'; |
| | | import {CascaderOption} from 'ng-zorro-antd/src/cascader/nz-cascader.component'; |
| | | import {Organization} from '@business/entity/data'; |
| | | import {ResultCode} from '@business/enum/types.enum'; |
| | | import {ResultBean} from '@business/entity/grid'; |
| | | import {AreacodeService} from '@business/services/http/areacode.service'; |
| | | import {NzTreeComponent} from 'ng-tree-antd'; |
| | | import {Subject} from 'rxjs/Subject'; |
| | | |
| | | @Component({ |
| | | selector: 'app-demo', |
| | |
| | | {value: 'line', label: '折线图'} |
| | | ]; |
| | | |
| | | public items = [{ |
| | | public items: any[] = [{ |
| | | id: 0, |
| | | monitorPoint: null, |
| | | device: null, |
| | | time: null, |
| | | monitorPointOptions: [], |
| | | deviceOptions: [], |
| | | _areas: [] |
| | | deviceOptions: [] |
| | | }]; |
| | | |
| | | private treeClickStream: Subject<any> = new Subject<any>(); |
| | | private _sensors: {[key: string]: string} = {}; |
| | | private _sensorNames: string; |
| | | get sensorNames(): string { |
| | | return this._sensorNames; |
| | | } |
| | | |
| | | constructor( |
| | | public http: HttpClient, |
| | |
| | | if (res.code === 0) { |
| | | this.msgSrv.error(res.message); |
| | | } else { |
| | | this.sensorOptions = res.data; |
| | | this.sensorOptions.push({id: -1, name: '全部', isExpanded: true, children: res.data}); |
| | | } |
| | | }); |
| | | |
| | | } |
| | | |
| | | public onTreeClickSelect(event): void { |
| | | this.treeClickStream.next(event); |
| | | } |
| | | |
| | | public onSensorSelect(event): void { |
| | | const data = event.node.data; |
| | | if (data.id === -1 && data.halfChecked === false) { |
| | | if (!!data.checked) { |
| | | this.sensorOptions[0].children.forEach( |
| | | sensor => { |
| | | this._sensors[sensor.id] = sensor.sensorKey + '-' + sensor.name + '-' + sensor.unit; |
| | | } |
| | | ); |
| | | } else { |
| | | this._sensors = {}; |
| | | } |
| | | } else { |
| | | if (!!data.checked) { |
| | | this._sensors[data.id] = data.sensorKey + '-' + data.name + '-' + data.unit; |
| | | } else { |
| | | delete this._sensors[data.id]; |
| | | } |
| | | } |
| | | this.reloadSensorNames(); |
| | | |
| | | } |
| | | private reloadSensorNames(): void { |
| | | // 异步提升展现速度 |
| | | setTimeout(() => { |
| | | this._sensorNames = ''; |
| | | const sensorNameList = Object.keys(this._sensors).map( |
| | | id => { |
| | | const sensor = this.sensorOptions[0].children.find(item => { |
| | | return Number(id) === Number(item.id); |
| | | }); |
| | | return sensor.name; |
| | | } |
| | | ); |
| | | this._sensorNames = sensorNameList.join(', '); |
| | | }, 1); |
| | | } |
| | | |
| | | addItem() { |
| | |
| | | device: null, |
| | | time: null, |
| | | monitorPointOptions: [], |
| | | deviceOptions: [], |
| | | _areas: [] |
| | | deviceOptions: [] |
| | | }); |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | public setAreasData(areas: {label: string, value: string}[], i) { |
| | | let isChanged = false; |
| | | const _areas = this.items[i]._areas |
| | | isChanged = areas.some((item, index: number) => { |
| | | // this._areas[index] 为null 改变 监控点选项 |
| | | return _areas.length < areas.length |
| | | || !_areas[index] |
| | | || _areas[index].value !== item.value; |
| | | }); |
| | | if (isChanged) { |
| | | this.items[i]._areas = areas; |
| | | this.items[i].monitorPoint = null; |
| | | this.regionChange(i); |
| | | } |
| | | } |
| | | |
| | | regionChange(i) { |
| | | public regionChange(event: {option: CascaderOption, index: number}, i) { |
| | | let name = ''; |
| | | let areaName = ''; |
| | | switch (this.items[i]._areas.length) { |
| | | const option = event.option; |
| | | this.items[i].monitorPoint = null; |
| | | this.items[i].areaCode = null; |
| | | this.items[i].device = null; |
| | | |
| | | switch (event.index) { |
| | | case 0: |
| | | name = 'provinceCode'; |
| | | this.items[i].provinceCode = option.value; |
| | | this.items[i].cityCode = null; |
| | | areaName = option.label; |
| | | break; |
| | | case 1: |
| | | areaName = 'provinceCode'; break; |
| | | name = 'cityCode'; |
| | | this.items[i].cityCode = option.value; |
| | | areaName = option.parent.label + '/' + option.label; |
| | | break; |
| | | case 2: |
| | | areaName = 'cityCode'; break; |
| | | case 3: |
| | | areaName = 'areaCode'; break; |
| | | name = 'areaCode'; |
| | | this.items[i].areaCode = option.value; |
| | | areaName = option.parent.parent.label + '/' + option.parent.label + '/' + option.label; |
| | | break; |
| | | } |
| | | this.http.get(environment.SERVER_BASH_URL + 'monitor-point/list/region', {params: {name: areaName, value: this.items[i]._areas.slice(-1).pop().value}}).subscribe((res: any) => { |
| | | this.items[i].areaName = areaName; |
| | | this.http.get(environment.SERVER_BASH_URL + 'monitor-point/list/region', {params: {name: name, value: option.value}}).subscribe((res: any) => { |
| | | if (res.code === 0) { |
| | | this.msgSrv.error(res.message); |
| | | } else { |
| | |
| | | let validate = true; |
| | | const queryItems = []; |
| | | for (let i = 0; i < this.items.length; i++) { |
| | | let areaName = ''; |
| | | let item = this.items[i]; |
| | | let queryItem: any = {}; |
| | | if ((!!item.time) && (item.monitorPointOptions.length > 0)) { |
| | |
| | | queryItem[key] = item[key]; |
| | | } |
| | | } |
| | | for (let i = 0; i < queryItem._areas.length; i++) { |
| | | let region = queryItem._areas[i]; |
| | | if (i == 0) { |
| | | queryItem.provinceCode = region.value; |
| | | } |
| | | if (i == 1) { |
| | | queryItem.cityCode = region.value; |
| | | } |
| | | if (i == 2) { |
| | | queryItem.areaCode = region.value; |
| | | } |
| | | } |
| | | delete queryItem._areas; |
| | | if (queryItem.monitorPoint) { |
| | | queryItem.monitorPointId = queryItem.monitorPoint.id; |
| | | queryItem.monitorPointName = queryItem.monitorPoint.name; |
| | |
| | | queryItem.deviceName = queryItem.device.name; |
| | | delete queryItem.device; |
| | | } |
| | | queryItem.deviceCount = queryItem.deviceOptions.length; |
| | | if (queryItem.deviceOptions && queryItem.deviceOptions.length > 0) { |
| | | queryItem.deviceCount = queryItem.deviceOptions.length; |
| | | } |
| | | delete queryItem.deviceOptions; |
| | | queryItem.formatTime = this.dateSrv.date_format(queryItem.time, this.timeType.format); |
| | | delete queryItem.time; |
| | |
| | | } |
| | | } |
| | | if (validate && this.timeType && query.reportType) { |
| | | if (query.sensorKeys && query.sensorKeys.length > 0) { |
| | | query.sensors = JSON.stringify(query.sensorKeys); |
| | | if (this._sensors) { |
| | | const sensors = []; |
| | | for (var key in this._sensors) { |
| | | sensors.push(this._sensors[key]); |
| | | } |
| | | if (sensors.length > 0) { |
| | | query.sensors = JSON.stringify(sensors); |
| | | } |
| | | } |
| | | query.items = JSON.stringify(queryItems); |
| | | query.type = this.timeType.value; |