From 780f76a3e8dd68abe6b007006f85a76991ea2c54 Mon Sep 17 00:00:00 2001
From: fengxiang <110431245@qq.com>
Date: Mon, 16 Apr 2018 13:40:28 +0800
Subject: [PATCH] Merge branch 'develop' of http://blit.7drlb.com:8888/r/screen-frontend into develop

---
 src/app/routes/reports/demo/demo.component.ts |  164 ++++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 139 insertions(+), 25 deletions(-)

diff --git a/src/app/routes/reports/demo/demo.component.ts b/src/app/routes/reports/demo/demo.component.ts
index 37cf5ed..305c4b6 100644
--- a/src/app/routes/reports/demo/demo.component.ts
+++ b/src/app/routes/reports/demo/demo.component.ts
@@ -3,7 +3,10 @@
 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 {AreacodeService} from '@business/services/http/areacode.service';
+import {NzTreeComponent} from 'ng-tree-antd';
+import {Subject} from 'rxjs/Subject';
 
 @Component({
   selector: 'app-demo',
@@ -25,19 +28,27 @@
     {value: 'bar', label: '���������'},
     {value: 'line', label: '���������'}
   ];
-  public monitorPointOptions = [];
-  public items = [{
+
+  public items: any[] = [{
     id: 0,
     monitorPoint: null,
     device: null,
     time: null,
+    monitorPointOptions: [],
     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,
     public dateSrv: DateService,
-    public router: Router,
+    private areacodeService: AreacodeService,
     public msgSrv: NzMessageService
   ) {
     this.timeType = this.typeOptions[1];
@@ -49,9 +60,52 @@
       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() {
@@ -61,23 +115,70 @@
       monitorPoint: null,
       device: null,
       time: null,
+      monitorPointOptions: [],
       deviceOptions: []
     });
   }
 
-  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 regionChange(event: {option: CascaderOption, index: number}, i) {
+    let name = '';
+    let areaName = '';
+    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:
+        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;
+    }
+    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;
+      }
+    });
   }
 
   monitorPointChange(value, i) {
@@ -103,24 +204,30 @@
     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.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;
+        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;
+        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;
@@ -131,14 +238,21 @@
       }
     }
     if (validate && this.timeType && query.reportType) {
-      if (query.sensorKey && query.sensorKey.length > 0) {
-        query.sensors = JSON.stringify(query.sensorKey);
+      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;
-      this.router.navigate(['report'], {queryParams: query});
+      sessionStorage.setItem("queryParams", JSON.stringify(query));
     } else {
       this.msgSrv.error('���������������������������������������');
+      return false;
     }
   }
 }

--
Gitblit v1.8.0