From 26332c174e8e62e7e2cd5b17fe8089b9135a8b8a Mon Sep 17 00:00:00 2001 From: xufenglei <xufenglei> Date: Fri, 30 Mar 2018 15:04:04 +0800 Subject: [PATCH] 增加 省市区 查询条件 --- src/app/routes/reports/demo/demo.component.ts | 231 ++++++++++++++++++++++++++++++++++----------------------- 1 files changed, 138 insertions(+), 93 deletions(-) diff --git a/src/app/routes/reports/demo/demo.component.ts b/src/app/routes/reports/demo/demo.component.ts index 1189314..0b66746 100644 --- a/src/app/routes/reports/demo/demo.component.ts +++ b/src/app/routes/reports/demo/demo.component.ts @@ -3,7 +3,11 @@ import {NzMessageService} from 'ng-zorro-antd'; import {Component, OnInit} from '@angular/core'; import {HttpClient} from '@angular/common/http'; -import {Router} from '@angular/router'; +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'; @Component({ selector: 'app-demo', @@ -13,35 +17,37 @@ export class DemoComponent implements OnInit { [x: string]: any; - query: any = { - }; - time: any = { - format: 'YYYY', - mode: 'month' - }; - items = [{ + public query: any = {}; + public sensorOptions = []; + public typeOptions = [ + {value: 'year', label: '���', format: 'YYYY'}, + {value: 'month', label: '���', format: 'YYYY-MM'}, + {value: 'day', label: '���', format: 'YYYY-MM-DD'}, + {value: 'hour', label: '���', format: 'YYYY-MM-DD HH'} + ]; + public reportOptions = [ + {value: 'bar', label: '���������'}, + {value: 'line', label: '���������'} + ]; + + public items = [{ id: 0, monitorPoint: null, - mac: '', + device: null, time: null, - formatTime: null, - monitorPointName: '', - deviceName: '', - monitorPointAddress: '', - deviceCount: '' - + monitorPointOptions: [], + deviceOptions: [], + _areas: [] }]; - - public sensorOptions = []; - public monitorPointOptions = []; - public deviceOptions = []; constructor( public http: HttpClient, public dateSrv: DateService, - public router: Router, + private areacodeService: AreacodeService, public msgSrv: NzMessageService ) { + this.timeType = this.typeOptions[1]; + this.query.reportType = this.reportOptions[1].value; } ngOnInit() { @@ -59,111 +65,150 @@ const index = this.items.push({ id: id, monitorPoint: null, - mac: '', + device: null, time: null, - formatTime: null, - monitorPointName: '', - deviceName: '', - monitorPointAddress: '', - deviceCount: '' + monitorPointOptions: [], + deviceOptions: [], + _areas: [] }); } - - searchChange(searchText, i) { - if (searchText) { - const query = encodeURI(searchText); - if (query) { - this.http.get(environment.SERVER_BASH_URL + '/monitor-point/list/' + query).subscribe((res: any) => { - if (res.code === 0) { - this.msgSrv.error(res.message); - } else { - this.monitorPointOptions = res.data; + public areaLazyLoad(event: {option: CascaderOption, index: number, resolve: (children: CascaderOption[]) => void, reject: () => void}) { + const index = event['index']; + const option = event.option; + switch (index) { + case -1: + this.areacodeService.getProvinces().subscribe( + (res: {label: string, value: string}[]) => { + event.resolve(res); } - }); - } + ); break; + case 0: + this.areacodeService.getCities(option.value).subscribe( + (res: {label: string, value: string}[]) => { + event.resolve(res); + } + ); break; + case 1: + this.areacodeService.getAreas(option.value).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; + case 2: + areaName = 'cityCode'; break; + case 3: + areaName = 'areaCode'; 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) => { + if (res.code === 0) { + this.msgSrv.error(res.message); + } else { + this.items[i].monitorPointOptions = res.data; + } + }); } monitorPointChange(value, i) { - this.deviceOptions = []; + this.items[i].deviceOptions = []; + this.items[i].device = null; if (value) { - this.monitorPointOptions.forEach(monitorPoint => { - if (monitorPoint.id === value) { - this.items[i].monitorPointName = monitorPoint.name; - this.items[i].monitorPointAddress = monitorPoint.address; - } - }); - this.http.get(environment.SERVER_BASH_URL + 'device/monitorPointId', {params: {monitorPointId: value}}).subscribe((res: any) => { + 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.deviceOptions = res.data; - this.items[i].deviceCount = res.data.length; + this.items[i].deviceOptions = res.data; } }); - } else { - this.items[i].monitorPoint = null; - this.items[i].mac = ''; - this.items[i].monitorPointName = ''; } } - deviceChange(value, i) { - if (value) { - this.deviceOptions.forEach(device => { - if (device.mac === value) { - this.items[i].deviceName = device.name; - } - }); - } else { - this.items[i].deviceName = ''; - } - } - - public typeOptions = [ - {value: 'year', label: '���', mode: 'month', xAxisName: '���', format: 'yyyy', typeFormat: '%Y-%m', timeLength: 12}, - {value: 'month', label: '���', mode: 'month', xAxisName: '���', format: 'yyyy-MM', typeFormat: '%Y-%m-%d', timeLength: 28}, - {value: 'day', label: '���', mode: 'day', xAxisName: '���', format: 'yyyy-MM-dd', typeFormat: '%Y-%m-%d %H', timeLength: 24}, - {value: 'hour', label: '���', mode: 'day', xAxisName: '���', format: 'yyyy-MM-dd HH', typeFormat: '%Y-%m-%d %H:%i', timeLength: 60} - ]; - - timeType = this.typeOptions[0]; - - typeChange(searchText) { - this.typeOptions.forEach(types => { - if (types.value === searchText) { - this.timeType = types; - this.time.format = types.format.toUpperCase(); - this.time.mode = types.mode; - } - }); + _disabledDate(current: Date): boolean { + return current && current.getTime() > Date.now(); } reportQuery() { const query = this.query; let validate = true; + const queryItems = []; for (let i = 0; i < this.items.length; i++) { let item = this.items[i]; - if (item.monitorPoint && item.time) { - item.formatTime = this.dateSrv.date_format(item.time, this.time.format); + let queryItem: any = {}; + if ((!!item.time) && (item.monitorPointOptions.length > 0)) { + for (var 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.monitorPoint) { + queryItem.monitorPointId = queryItem.monitorPoint.id; + queryItem.monitorPointName = queryItem.monitorPoint.name; + queryItem.monitorPointAddress = queryItem.monitorPoint.address; + delete queryItem.monitorPoint; + } + delete queryItem.monitorPointOptions; + if (queryItem.device) { + queryItem.mac = queryItem.device.mac; + queryItem.deviceName = queryItem.device.name; + delete queryItem.device; + } + queryItem.deviceCount = queryItem.deviceOptions.length; + delete queryItem.deviceOptions; + queryItem.formatTime = this.dateSrv.date_format(queryItem.time, this.timeType.format); + delete queryItem.time; + queryItems.push(queryItem); } else { validate = false; break; } } - if (validate && query.type) { - query.timeType = JSON.stringify(this.timeType); - query.items = JSON.stringify(this.items); - console.info(this.items); - this.router.navigate(['report'], {queryParams: query}); + if (validate && this.timeType && query.reportType) { + if (query.sensorKeys && query.sensorKeys.length > 0) { + query.sensors = JSON.stringify(query.sensorKeys); + } + query.items = JSON.stringify(queryItems); + query.type = this.timeType.value; + sessionStorage.setItem("queryParams", JSON.stringify(query)); } else { this.msgSrv.error('���������������������������������������'); + return false; } - - } - - _disabledDate(current: Date): boolean { - return current && current.getTime() > Date.now() ; } } -- Gitblit v1.8.0