From 309d1f9d649daa08bb9b068af014749f6d4a5bce Mon Sep 17 00:00:00 2001 From: fengxiang <110431245@qq.com> Date: Fri, 06 Jul 2018 14:00:45 +0800 Subject: [PATCH] 设备和监控点父页面 筛选条件不予 编辑页面联动 --- src/app/routes/reports/demo/demo.component.ts | 278 +++++++++++++++++++++++++++++++++++++++---------------- 1 files changed, 197 insertions(+), 81 deletions(-) diff --git a/src/app/routes/reports/demo/demo.component.ts b/src/app/routes/reports/demo/demo.component.ts index 0b66746..c279929 100644 --- a/src/app/routes/reports/demo/demo.component.ts +++ b/src/app/routes/reports/demo/demo.component.ts @@ -4,10 +4,9 @@ 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', @@ -29,16 +28,29 @@ {value: 'bar', label: '���������'}, {value: 'line', label: '���������'} ]; - - public items = [{ + public professionOptions = []; + public dimensionOptions = [ + {value: 'monitorPoint', label: '������������'}, + {value: 'profession', label: '������'} + ]; + monitorPointShow = true; + professionShow = false; + public items: any[] = [{ id: 0, + profession: null, monitorPoint: null, device: null, - time: null, + time: new Date(), 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, @@ -48,6 +60,7 @@ ) { this.timeType = this.typeOptions[1]; this.query.reportType = this.reportOptions[1].value; + this.query.dimension = this.dimensionOptions[0].value; } ngOnInit() { @@ -55,21 +68,86 @@ 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}); } }); + + this.http.get(environment.SERVER_BASH_URL + 'mobile/profession').subscribe((res: any) => { + if (res.errno !== 0) { + this.msgSrv.error(res.message); + } else { + this.professionOptions = res.data; + } + }); + } + + dimensionChange(value) { + this.items.forEach((item, index) => { + item.profession = null; + item.monitorPoint = null; + this.getDevices(index); + }); + if (value === 'monitorPoint') { + this.professionShow = false; + this.monitorPointShow = true; + } else { + this.professionShow = true; + this.monitorPointShow = false; + } + } + + 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() { const id = (this.items.length > 0) ? this.items[this.items.length - 1].id + 1 : 0; const index = this.items.push({ id: id, + profession: null, monitorPoint: null, device: null, - time: null, + time: new Date(), monitorPointOptions: [], - deviceOptions: [], - _areas: [] + deviceOptions: [] }); } @@ -81,72 +159,106 @@ this.areacodeService.getProvinces().subscribe( (res: {label: string, value: string}[]) => { event.resolve(res); - } - ); break; + }); + break; case 0: this.areacodeService.getCities(option.value).subscribe( (res: {label: string, value: string}[]) => { event.resolve(res); - } - ); break; + }); + break; case 1: - this.areacodeService.getAreas(option.value).subscribe( + this.areacodeService.getAreas(option.value,false).subscribe( (res: {label: string, value: string}[]) => { event.resolve(res); - } - ); break; - } - } - - 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) { - let areaName = ''; - switch (this.items[i]._areas.length) { - case 1: - areaName = 'provinceCode'; break; + }); + break; case 2: - areaName = 'cityCode'; break; + this.areacodeService.getTowns(option.value).subscribe( + (res: {label: string, value: string}[]) => { + event.resolve(res); + }); + break; case 3: - areaName = 'areaCode'; break; + this.areacodeService.getVillages(option.value).subscribe( + (res: {label: string, value: string}[]) => { + event.resolve(res); + }); + 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) => { + } + + public regionChange(event: {option: CascaderOption, index: number}, i) { + + let name = ''; + let areaName = ''; + const option = event.option; + this.items[i].monitorPoint = null; + //this.items[i].profession = null; + this.items[i].cityCode = null; + this.items[i].areaCode = null; + this.items[i].townCode = null; + this.items[i].villageCode = null; + + switch (event.index) { + case 0: + name = 'provinceCode'; + this.items[i].provinceCode = option.value; + areaName = option.label; + break; + case 1: + name = 'cityCode'; + this.items[i].cityCode = option.value; + areaName = option.parent.label + '/' + option.label; + break; + case 2: + name = 'areaCode'; + this.items[i].areaCode = option.value; + areaName = option.parent.parent.label + '/' + option.parent.label + '/' + option.label; + break; + case 3: + name = 'townCode'; + this.items[i].townCode = option.value; + areaName = option.parent.parent.parent.label + '/' + option.parent.parent.label + '/' + option.parent.label + '/' + option.label; + break; + case 4: + name = 'villageCode'; + this.items[i].villageCode = option.value; + areaName = option.parent.parent.parent.parent.label + '/' + option.parent.parent.parent.label + '/' + option.parent.parent.label + '/' + option.parent.label + '/' + option.label; + break; + } + 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 { this.items[i].monitorPointOptions = res.data; } }); + this.getDevices(i); } - - monitorPointChange(value, i) { - this.items[i].deviceOptions = []; + + getDevices(i) { this.items[i].device = null; - if (value) { - this.http.get(environment.SERVER_BASH_URL + 'device/monitorPointId', {params: {monitorPointId: value.id}}).subscribe((res: any) => { - if (res.code === 0) { - this.msgSrv.error(res.message); - } else { - this.items[i].deviceOptions = res.data; - } - }); + if (!!this.items[i].profession) { + this.items[i].professionId = this.items[i].profession.id; + } else { + this.items[i].professionId = null; } + if (!!this.items[i].monitorPoint) { + this.items[i].monitorPointId = this.items[i].monitorPoint.id; + } else { + this.items[i].monitorPointId = null; + } + return this.http.get(environment.SERVER_BASH_URL + 'device/professionId', {params: this.items[i]}).subscribe((res: any) => { + if (res.code === 0) { + this.msgSrv.error(res.message); + } else { + this.items[i].deviceOptions = res.data; + } + }); } - + _disabledDate(current: Date): boolean { return current && current.getTime() > Date.now(); } @@ -156,32 +268,27 @@ let validate = true; const queryItems = []; for (let i = 0; i < this.items.length; i++) { - let item = this.items[i]; - let queryItem: any = {}; - if ((!!item.time) && (item.monitorPointOptions.length > 0)) { - for (var key in item) { + const areaName = ''; + const item = this.items[i]; + const queryItem: any = {}; + if (item.monitorPointOptions.length > 0 && item.deviceOptions.length > 0) { + for (const key in item) { if (item[key]) { 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.profession) { + queryItem.professionId = queryItem.profession.id; + queryItem.professionName = queryItem.profession.name; + delete queryItem.profession; + } if (queryItem.monitorPoint) { queryItem.monitorPointId = queryItem.monitorPoint.id; queryItem.monitorPointName = queryItem.monitorPoint.name; queryItem.monitorPointAddress = queryItem.monitorPoint.address; delete queryItem.monitorPoint; + } else { + queryItem.monitorPointName = queryItem.areaName; } delete queryItem.monitorPointOptions; if (queryItem.device) { @@ -189,7 +296,9 @@ 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; @@ -199,15 +308,22 @@ break; } } - if (validate && this.timeType && query.reportType) { - if (query.sensorKeys && query.sensorKeys.length > 0) { - query.sensors = JSON.stringify(query.sensorKeys); + if (validate) { + delete query.sensors; + if (this._sensors) { + const sensors = []; + for (const 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; - sessionStorage.setItem("queryParams", JSON.stringify(query)); + sessionStorage.setItem('queryParams', JSON.stringify(query)); } else { - this.msgSrv.error('���������������������������������������'); + this.msgSrv.error('���������������������������������������������������������������'); return false; } } -- Gitblit v1.8.0