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/excel/excel.component.ts |  133 +++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 117 insertions(+), 16 deletions(-)

diff --git a/src/app/routes/reports/excel/excel.component.ts b/src/app/routes/reports/excel/excel.component.ts
index a6fce42..5d882ba 100644
--- a/src/app/routes/reports/excel/excel.component.ts
+++ b/src/app/routes/reports/excel/excel.component.ts
@@ -4,6 +4,10 @@
 import {Component, OnInit, Inject} from '@angular/core';
 import {HttpClient} from '@angular/common/http';
 import {ITokenService, DA_SERVICE_TOKEN} from '@delon/auth';
+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-excel',
@@ -23,10 +27,18 @@
     {value: 'hour', label: '���', format: 'YYYY-MM-DD HH'}
   ];
 
+  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 msgSrv: NzMessageService,
+    private areacodeService: AreacodeService,
     @Inject(DA_SERVICE_TOKEN) public tokenService: ITokenService
   ) {
     this.timeType = this.typeOptions[1];
@@ -39,24 +51,106 @@
       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});
       }
     });
   }
 
-  searchChange(searchText) {
-    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 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);
+  }
+
+  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}) {
+    let name = '';
+    const option = event.option;
+    this.query.areaCode = null;
+    this.query.monitorPointId = null;
+    this.query.mac = null;
+    switch (event.index) {
+      case 0:
+        name = 'provinceCode';
+        this.query.provinceCode = option.value;
+        this.query.cityCode = null;
+        break;
+      case 1:
+        name = 'cityCode';
+        this.query.cityCode = option.value;
+        break;
+      case 2:
+        name = 'areaCode';
+        this.query.areaCode = option.value;
+        break;
+    }
+    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.monitorPointOptions = res.data;
+      }
+    });
   }
 
   monitorPointChange(value) {
@@ -75,15 +169,22 @@
 
   reportQuery() {
     const query = this.query;
-    if (this.timeType && query.monitorPointId && query.time) {
+    if (this.monitorPointOptions.length > 0 && query.time) {
       query.time = this.dateSrv.date_format(query.time, this.timeType.format);
       if (query.timeb) {
         query.timeb = this.dateSrv.date_format(query.timeb, this.timeType.format);
       }
-      if (query.sensorKey && query.sensorKey.length > 0) {
-        query.sensors = JSON.stringify(query.sensorKey);
-      }
       query.type = this.timeType.value;
+      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);
+        }
+      }
+
       let url = environment.SERVER_BASH_URL + 'report/excel?';
       for (const a in query) {
         if (query[a]) {
@@ -92,7 +193,7 @@
       }
       window.location.href = url + '_token=' + this.tokenService.get().token;
     } else {
-      this.msgSrv.error('������������������');
+      this.msgSrv.error('������������������������������������������������������������');
     }
   }
 }

--
Gitblit v1.8.0