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/report/report.component.ts | 12 ++- src/app/routes/reports/demo/demo.component.ts | 114 +++++++++++++++++++++++----- src/app/routes/reports/demo/demo.component.html | 55 +++++++++---- 3 files changed, 137 insertions(+), 44 deletions(-) diff --git a/src/app/routes/report/report.component.ts b/src/app/routes/report/report.component.ts index 64d1127..9d540ff 100644 --- a/src/app/routes/report/report.component.ts +++ b/src/app/routes/report/report.component.ts @@ -2,7 +2,6 @@ import {NzMessageService, NzModalService} from 'ng-zorro-antd'; import {Component, OnInit, Injector} from '@angular/core'; import {HttpClient} from '@angular/common/http'; -import {ActivatedRoute} from '@angular/router'; import * as echarts from 'echarts'; import * as $ from 'jquery'; @@ -69,7 +68,6 @@ constructor( public injector: Injector, public http: HttpClient, - public activeRoute: ActivatedRoute, public msgSrv: NzMessageService ) { for (let index = 0; index < 30; index++) { @@ -78,7 +76,9 @@ } ngOnInit() { - this.activeRoute.queryParams.subscribe(params => { + const params = JSON.parse(sessionStorage.getItem("queryParams")); + if (!!params) { + localStorage.removeItem("queryParams"); const items = this.items = JSON.parse(params.items); const timeType = params.type; this.http.get(environment.SERVER_BASH_URL + 'report/compare', {params: params}).subscribe((res: any) => { @@ -136,6 +136,10 @@ } } }); - }); + + } else { + this.msgSrv.error("������������������������������������"); + setTimeout("window.close();",1000); + } } } diff --git a/src/app/routes/reports/demo/demo.component.html b/src/app/routes/reports/demo/demo.component.html index a11c51f..b9b6d8e 100644 --- a/src/app/routes/reports/demo/demo.component.html +++ b/src/app/routes/reports/demo/demo.component.html @@ -2,22 +2,26 @@ <nz-card [nzBordered]="false"> <form nz-form (ngSubmit)="reportQuery()" [nzLayout]="'inline'"> <div nz-row [nzGutter]="24"> - <div nz-col [nzSpan]="6" class="mb-md"> + <div nz-col [nzSpan]="5" class="mb-md"> <div nz-form-item class="d-flex"> <div nz-form-label> - <label> ��� ���</label> + <label> ��� ���</label> </div> <div nz-form-control class="flex-1"> <nz-select [nzMode]="'multiple'" [(ngModel)]="query.sensorKeys" name="sensorKeys" [nzSize]="'large'" [nzPlaceHolder]="'���������'"> <nz-option *ngFor="let option of sensorOptions" [nzLabel]="option.name" [nzValue]="option.sensorKey + '-' + option.name + '-' + option.unit"></nz-option> </nz-select> + <!-- <input nz-input /> + <div> + <ul id="sensorTree" class="ztree"></ul> + </div> --> </div> </div> </div> - <div nz-col [nzSpan]="6" class="mb-md"> + <div nz-col [nzSpan]="5" class="mb-md"> <div nz-form-item class="d-flex"> <div nz-form-label> - <label nz-form-item-required>������</label> + <label nz-form-item-required>��� ���</label> </div> <div nz-form-control class="flex-1"> <nz-select [(ngModel)]="timeType" name="timeType" [nzSize]="'large'" [nzPlaceHolder]="'���������'"> @@ -26,7 +30,7 @@ </div> </div> </div> - <div nz-col [nzSpan]="6" class="mb-md"> + <div nz-col [nzSpan]="5" class="mb-md"> <div nz-form-item class="d-flex"> <div nz-form-label> <label nz-form-item-required>������</label> @@ -38,7 +42,7 @@ </div> </div> </div> - <div nz-col [nzSpan]="6" class="mb-md" *ngIf="items.length < 2"> + <div nz-col [nzSpan]="5" class="mb-md" *ngIf="items.length < 2"> <button nz-button type="button" [nzType]="'primary'" [nzSize]="'large'" (click)="addItem()"> <!-- <i class="anticon anticon-plus"></i> --> <i class="anticon anticon-plus-circle-o"></i> @@ -49,43 +53,56 @@ </div> <div nz-row [nzGutter]="24" *ngFor="let item of items;let i = index"> - <div nz-col [nzSpan]="6" class="mb-md"> + <div nz-col [nzSpan]="5" class="mb-md"> <div nz-form-item class="d-flex"> <div nz-form-label> - <label nz-form-item-required>���������</label> + <label nz-form-item-required>���������</label> </div> <div nz-form-control class="flex-1"> - <nz-select [(ngModel)]="item.monitorPoint" name="monitorPoint{{item.id}}" nzAllowClear [nzPlaceHolder]="'���������'" [nzFilter]="false" [nzSize]="'large'" - (nzSearchChange)="searchChange($event,i)" [nzNotFoundContent]="'������������'" (ngModelChange)="monitorPointChange($event,i)" nzShowSearch> - <nz-option *ngFor="let option of monitorPointOptions" [nzLabel]="option['name']" [nzValue]="option"> </nz-option> + <nz-cascader [class.class123]="true" (nzLoad)="areaLazyLoad($event,i)" [nzPlaceHolder]="'������ ���/���/���'" (nzSelectionChange)="setAreasData($event,i)" + [nzAllowClear]="false" [nzChangeOnSelect]="true" [ngModel]="item._areas" name="areasData{{item.id}}"> + </nz-cascader> + </div> + </div> + </div> + + <div nz-col [nzSpan]="5" class="mb-md"> + <div nz-form-item class="d-flex"> + <div nz-form-label> + <label>���������</label> + </div> + <div nz-form-control class="flex-1"> + <nz-select [(ngModel)]="item.monitorPoint" name="monitorPoint{{item.id}}" nzAllowClear [nzPlaceHolder]="'������ ���������'" [nzSize]="'large'" + [nzNotFoundContent]="'������������'" (ngModelChange)="monitorPointChange($event,i)" nzShowSearch> + <nz-option *ngFor="let option of item.monitorPointOptions" [nzLabel]="option['name']" [nzValue]="option"> </nz-option> </nz-select> </div> </div> </div> - <div nz-col [nzSpan]="6" class="mb-md"> + <div nz-col [nzSpan]="5" class="mb-md"> <div nz-form-item class="d-flex"> <div nz-form-label> - <label> ������</label> + <label> ��� ���</label> </div> <div nz-form-control class="flex-1"> - <nz-select [(ngModel)]="item.device" name="mac{{item.id}}" [nzSize]="'large'" nzAllowClear [nzPlaceHolder]="'���������'"> + <nz-select [(ngModel)]="item.device" name="mac{{item.id}}" [nzSize]="'large'" [nzPlaceHolder]="'��������� ������'" [nzNotFoundContent]="'������������'" nzShowSearch nzAllowClear> <nz-option *ngFor="let option of item.deviceOptions" [nzLabel]="option.name" [nzValue]="option" ></nz-option> </nz-select> </div> </div> </div> - <div nz-col [nzSpan]="6" class="mb-md"> + <div nz-col [nzSpan]="5" class="mb-md"> <div nz-form-item class="d-flex"> <div nz-form-label> <label nz-form-item-required>������</label> </div> <div nz-form-control class="flex-1"> - <nz-datepicker style="width: 100%;" [(ngModel)]="item.time" name="time{{item.id}}" [nzPlaceHolder]="'���������'" [nzFormat]="timeType.format" [nzDisabledDate]="_disabledDate" + <nz-datepicker style="width: 100%;" [(ngModel)]="item.time" name="time{{item.id}}" [nzPlaceHolder]="'��������� ������'" [nzFormat]="timeType.format" [nzDisabledDate]="_disabledDate" [nzMode]="timeType.value=='hour'||timeType.value=='day'?'day':'month'" [nzShowTime]="timeType.value=='hour'?true:false" [nzSize]="'large'"></nz-datepicker> </div> </div> </div> - <div nz-col [nzSpan]="6" class="mb-md" *ngIf="items.length > 1"> + <div nz-col [nzSpan]="4" class="mb-md" *ngIf="items.length > 1"> <button nz-button type="button" [nzType]="'danger'" [nzSize]="'large'" (click)="items.splice(i, 1)"> <i class="anticon anticon-minus-circle-o dynamic-delete-button"></i> <span>������������������</span> @@ -95,7 +112,9 @@ <div nz-row [nzGutter]="24"> <div nz-col [nzSpan]="6" class="mb-md"> - <button nz-button type="submit" [nzType]="'primary'" [nzSize]="'large'">������</button> + <button nz-button type="submit" [nzType]="'primary'" [nzSize]="'large'"> + <a target="_blank" [routerLink]="['/report']" (click)="reportQuery()">������</a> + </button> <!-- <button nz-button type="reset" [nzSize]="'large'" class="mx-sm" (click)="load()">������</button> --> </div> </div> diff --git a/src/app/routes/reports/demo/demo.component.ts b/src/app/routes/reports/demo/demo.component.ts index 431b3a2..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', @@ -25,19 +29,21 @@ {value: 'bar', label: '���������'}, {value: 'line', label: '���������'} ]; - public monitorPointOptions = []; + public items = [{ id: 0, monitorPoint: null, device: null, time: null, - deviceOptions: [] + monitorPointOptions: [], + deviceOptions: [], + _areas: [] }]; constructor( public http: HttpClient, public dateSrv: DateService, - public router: Router, + private areacodeService: AreacodeService, public msgSrv: NzMessageService ) { this.timeType = this.typeOptions[1]; @@ -61,23 +67,70 @@ monitorPoint: null, device: null, time: null, - deviceOptions: [] + 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) { @@ -105,16 +158,32 @@ for (let i = 0; i < this.items.length; i++) { let item = this.items[i]; let queryItem: any = {}; - if (item.monitorPoint && item.time) { + if ((!!item.time) && (item.monitorPointOptions.length > 0)) { for (var key in item) { if (item[key]) { queryItem[key] = item[key]; } } - queryItem.monitorPointId = queryItem.monitorPoint.id; - queryItem.monitorPointName = queryItem.monitorPoint.name; - queryItem.monitorPointAddress = queryItem.monitorPoint.address; - delete queryItem.monitorPoint; + 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; @@ -136,9 +205,10 @@ } query.items = JSON.stringify(queryItems); query.type = this.timeType.value; - this.router.navigate(['report'], {queryParams: query}); + sessionStorage.setItem("queryParams", JSON.stringify(query)); } else { this.msgSrv.error('���������������������������������������'); + return false; } } } -- Gitblit v1.8.0