From c83b053ccb952e95fad848c914126cbfadce5d26 Mon Sep 17 00:00:00 2001
From: xufenglei <xufenglei>
Date: Tue, 12 Jun 2018 08:50:04 +0800
Subject: [PATCH] 报表查询 增加镇村选项

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

diff --git a/src/app/routes/reports/demo/demo.component.ts b/src/app/routes/reports/demo/demo.component.ts
index 305c4b6..6622aef 100644
--- a/src/app/routes/reports/demo/demo.component.ts
+++ b/src/app/routes/reports/demo/demo.component.ts
@@ -28,12 +28,19 @@
     {value: 'bar', label: '���������'},
     {value: 'line', label: '���������'}
   ];
-
+  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: []
   }];
@@ -44,7 +51,39 @@
   get sensorNames(): string {
     return this._sensorNames;
   }
-
+  options = [{
+  value: 'zhejiang',
+  label: 'Zhejiang',
+  children: [{
+    value: 'hangzhou',
+    label: 'Hangzhou',
+    children: [{
+      value: 'xihu',
+      label: 'West Lake',
+      isLeaf: true
+    }]
+  }, {
+    value: 'ningbo',
+    label: 'Ningbo',
+    isLeaf: true
+  }]
+}, {
+  value: 'jiangsu',
+  label: 'Jiangsu',
+  children: [{
+    value: 'nanjing',
+    label: 'Nanjing',
+    children: [{
+      value: 'zhonghuamen',
+      label: 'Zhong Hua Men',
+      children: [{
+      value: 'zhonghuamen12',
+      label: 'Zhong Hua Men12',
+      isLeaf: true
+    }]
+    }]
+  }]
+}];
   constructor(
     public http: HttpClient,
     public dateSrv: DateService,
@@ -53,6 +92,7 @@
   ) {
     this.timeType = this.typeOptions[1];
     this.query.reportType = this.reportOptions[1].value;
+    this.query.dimension = this.dimensionOptions[0].value;
   }
 
   ngOnInit() {
@@ -64,6 +104,28 @@
       }
     });
 
+    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;
+      this.getDevices(index);
+    });
+    if (value === 'monitorPoint') {
+      this.professionShow = false;
+      this.monitorPointShow = true;
+    } else {
+      this.professionShow = true;
+      this.monitorPointShow = false;
+    }
   }
 
   public onTreeClickSelect(event): void {
@@ -112,9 +174,10 @@
     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: []
     });
@@ -128,36 +191,52 @@
         this.areacodeService.getProvinces().subscribe(
           (res: {label: string, value: string}[]) => {
             event.resolve(res);
-          }
-        ); break;
+          }); 
+        break;
       case 0:
         this.areacodeService.getCities(option.value).subscribe(
           (res: {label: string, value: string}[]) => {
             event.resolve(res);
-          }
-        ); break;
+          });
+         break;
       case 1:
         this.areacodeService.getAreas(option.value).subscribe(
           (res: {label: string, value: string}[]) => {
             event.resolve(res);
-          }
-        ); break;
+          }); 
+        break;
+      case 2:
+        this.areacodeService.getTowns(option.value).subscribe(
+          (res: {label: string, value: string}[]) => {
+            event.resolve(res);
+          }); 
+        break;
+      case 3:
+        this.areacodeService.getVillages(option.value).subscribe(
+          (res: {label: string, value: string}[]) => {
+            event.resolve(res);
+          }); 
+        break;
     }
   }
 
   public regionChange(event: {option: CascaderOption, index: number}, i) {
+        console.info(event);
+
     let name = '';
     let areaName = '';
     const option = event.option;
     this.items[i].monitorPoint = null;
+    //this.items[i].profession = null;
+    this.items[i].cityCode = null;
     this.items[i].areaCode = null;
-    this.items[i].device = null;
+    this.items[i].townCode = null;
+    this.items[i].villageCode = 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:
@@ -170,8 +249,18 @@
         this.items[i].areaCode = option.value;
         areaName = option.parent.parent.label + '/' + option.parent.label + '/' + option.label;
         break;
+      case 3:
+        name = 'townCode';
+        this.items[i].townCode = option.value;
+        areaName = option.parent.parent.parent.label + '/' + option.parent.parent.label + '/' + option.parent.label + '/' + option.label;
+        break;
+      case 4:
+        name = 'villageCode';
+        this.items[i].villageCode = option.value;
+        areaName = option.parent.parent.parent.parent.label + '/' + option.parent.parent.parent.label + '/' + option.parent.parent.label + '/' + option.parent.label + '/' + option.label;
+        break;
     }
-    this.items[i].areaName = areaName;
+    //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);
@@ -179,22 +268,30 @@
         this.items[i].monitorPointOptions = res.data;
       }
     });
+    this.getDevices(i);
   }
-
-  monitorPointChange(value, i) {
-    this.items[i].deviceOptions = [];
+  
+  getDevices(i) {
     this.items[i].device = null;
-    if (value) {
-      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.items[i].deviceOptions = res.data;
-        }
-      });
+    if (!!this.items[i].profession) {
+      this.items[i].professionId = this.items[i].profession.id;
+    } else {
+      this.items[i].professionId = null;
     }
+    if (!!this.items[i].monitorPoint) {
+      this.items[i].monitorPointId = this.items[i].monitorPoint.id;
+    } else {
+      this.items[i].monitorPointId = null;
+    }
+    return 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;
+      }
+    });
   }
-
+  
   _disabledDate(current: Date): boolean {
     return current && current.getTime() > Date.now();
   }
@@ -204,20 +301,27 @@
     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.time) && (item.monitorPointOptions.length > 0)) {
-        for (var key in item) {
+      const areaName = '';
+      const item = this.items[i];
+      const queryItem: any = {};
+      if (item.monitorPointOptions.length > 0 && item.deviceOptions.length > 0) {
+        for (const key in item) {
           if (item[key]) {
             queryItem[key] = item[key];
           }
+        }
+        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) {
@@ -237,10 +341,11 @@
         break;
       }
     }
-    if (validate && this.timeType && query.reportType) {
+    if (validate) {
+      delete query.sensors;
       if (this._sensors) {
         const sensors = [];
-        for (var key in this._sensors) {
+        for (const key in this._sensors) {
           sensors.push(this._sensors[key]);
         }
         if (sensors.length > 0) {
@@ -249,9 +354,9 @@
       }
       query.items = JSON.stringify(queryItems);
       query.type = this.timeType.value;
-      sessionStorage.setItem("queryParams", JSON.stringify(query));
+      sessionStorage.setItem('queryParams', JSON.stringify(query));
     } else {
-      this.msgSrv.error('���������������������������������������');
+      this.msgSrv.error('���������������������������������������������������������������');
       return false;
     }
   }

--
Gitblit v1.8.0