From 0fedf4949561e5eece7dc55c2dfc4963a5cbb6b2 Mon Sep 17 00:00:00 2001
From: fengxiang <110431245@qq.com>
Date: Tue, 15 May 2018 10:45:15 +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 |  249 +++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 209 insertions(+), 40 deletions(-)

diff --git a/src/app/routes/reports/demo/demo.component.ts b/src/app/routes/reports/demo/demo.component.ts
index c64baca..ee873aa 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',
@@ -16,32 +19,48 @@
   public query: any = {};
   public sensorOptions = [];
   public typeOptions = [
-    {value: 'year', label: '���', format: 'yyyy', typeFormat: '%Y-%m', timeLength: 12},
-    {value: 'month', label: '���', format: 'yyyy-MM', typeFormat: '%Y-%m-%d', timeLength: 28},
-    {value: 'day', label: '���', format: 'yyyy-MM-dd', typeFormat: '%Y-%m-%d %H', timeLength: 24},
-    {value: 'hour', label: '���', format: 'yyyy-MM-dd HH', typeFormat: '%Y-%m-%d %H:%i', timeLength: 60}
+    {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 monitorPointOptions = [];
-  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: []
   }];
+
+  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];
     this.query.reportType = this.reportOptions[1].value;
+    this.query.dimension = this.dimensionOptions[0].value;
   }
 
   ngOnInit() {
@@ -49,35 +68,149 @@
       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;
+      item.device = null;
+    });
+    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: []
     });
   }
 
-  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].profession = 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) {
@@ -94,6 +227,26 @@
     }
   }
 
+  professionChange(value, i) {
+    this.items[i].deviceOptions = [];
+    this.items[i].device = null;
+    if (value) {
+      if (!!this.items[i].areaName) {
+        this.items[i].professionId = value.id;
+        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;
+          }
+        });
+      } else {
+        this.msgSrv.error('������������ ������������');
+      }
+    }
+
+  }
+
   _disabledDate(current: Date): boolean {
     return current && current.getTime() > Date.now();
   }
@@ -103,26 +256,39 @@
     let validate = true;
     const queryItems = [];
     for (let i = 0; i < this.items.length; i++) {
-      let item = this.items[i];
-      let queryItem: any = {};
-      if (item.monitorPoint && item.time) {
-        for (var key in item) {
+      const areaName = '';
+      const item = this.items[i];
+      const queryItem: any = {};
+      if (item.monitorPointOptions.length > 0) {
+        for (const 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.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) {
           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.toUpperCase());
+        queryItem.formatTime = this.dateSrv.date_format(queryItem.time, this.timeType.format);
         delete queryItem.time;
         queryItems.push(queryItem);
       } else {
@@ -131,19 +297,22 @@
       }
     }
     if (validate && this.timeType && query.reportType) {
-      query.sensors = null;
-      if (query.sensorKey && query.sensorKey.length > 0) {
+      delete query.sensors;
+      if (this._sensors) {
         const sensors = [];
-        query.sensorKey.forEach(sensor => {
-          sensors.push(sensor.sensorKey + '-' + sensor.name + '-' + sensor.unit);
-        });
-        query.sensors = JSON.stringify(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.timeType = JSON.stringify(this.timeType);
-      this.router.navigate(['report'], {queryParams: query});
+      query.type = this.timeType.value;
+      sessionStorage.setItem('queryParams', JSON.stringify(query));
     } else {
       this.msgSrv.error('���������������������������������������');
+      return false;
     }
   }
 }

--
Gitblit v1.8.0