From 309d1f9d649daa08bb9b068af014749f6d4a5bce Mon Sep 17 00:00:00 2001
From: fengxiang <110431245@qq.com>
Date: Fri, 06 Jul 2018 14:00:45 +0800
Subject: [PATCH] 设备和监控点父页面 筛选条件不予 编辑页面联动

---
 src/app/routes/devices/monitor-point/monitor-point.component.ts |  266 +++++++++++++++++++++++++++++++++--------------------
 1 files changed, 165 insertions(+), 101 deletions(-)

diff --git a/src/app/routes/devices/monitor-point/monitor-point.component.ts b/src/app/routes/devices/monitor-point/monitor-point.component.ts
index e1a6b84..b24c84c 100644
--- a/src/app/routes/devices/monitor-point/monitor-point.component.ts
+++ b/src/app/routes/devices/monitor-point/monitor-point.component.ts
@@ -1,33 +1,23 @@
-import { DataType, AreaNames } from './../../../core/entity/grid';
+import { CoorPickerService } from 'app/routes/map/coordinates-picker/coordinates-picker.service';
+import { AreaNames, MonitorPoint } from '@business/entity/data';
 import { Version, ValueTransformer } from '@angular/compiler/src/util';
 import { Subject } from 'rxjs/Subject';
-import { ToolsService } from '@core/services/tools.service';
 import { Component, OnInit } from '@angular/core';
 import { NzMessageService, NzModalService } from 'ng-zorro-antd';
 import { ModalHelper } from '@delon/theme';
 import { HttpClient } from '@angular/common/http';
-import { environment } from '../../../../environments/environment';
-import { DateService } from '@core/services/date.service';
-import { VersionService } from 'app/routes/devices/version/version.service';
-import { Types } from '@core/enum/types.enum';
-import { Column, Grid, PageBean } from '@core/entity/grid';
+import { environment } from 'environments/environment';
+import { VersionService } from '@business/services/http/version.service';
+import { Types } from '@business/enum/types.enum';
+import { Column, Grid, PageBean, DataType } from '@business/entity/grid';
 import { filter } from 'rxjs/operators/filter';
 import { MonitorPointEditComponent } from 'app/routes/devices/monitor-point/monitor-point-edit/monitor-point-edit.component';
-import { MonitorPointService } from 'app/routes/devices/monitor-point/monitor-point.service';
+import { MonitorPointService } from '@business/services/http/monitor-point.service';
+import { CoordinatesPickerComponent } from 'app/routes/map/coordinates-picker/coordinates-picker.component';
+import { OrganizationService } from '@business/services/http/organization.service';
+import { ExampleService } from '@business/services/util/example.service';
 
-interface MonitorPoint {
-  address?: any|Column;
-  areaCode?: any|Column;
-  cityCode?: any|Column;
-  description?: any|Column;
-  id?: any|Column;
-  isDelete?: any|Column;
-  latitude?: any|Column;
-  longitude?: any|Column;
-  name?: any|Column;
-  organizationId?: any|Column;
-  provinceCode?: any|Column;
-}
+
 @Component({
   selector: 'app-monitor-point',
   templateUrl: './monitor-point.component.html',
@@ -35,147 +25,221 @@
 })
 export class MonitorPointComponent implements OnInit {
 
-
-  private organization: MonitorPoint;
+  public orgOptions = [];
+  private monitorPoint: MonitorPoint;
   grid: Grid<MonitorPoint> = new Grid(null);
-  queryMap = { text: '���������������', value: ''};
+  queryMap: { mpointName?: string, organizationId?: number } = { mpointName: null, organizationId: null };
   queryTextStream: Subject<string> = new Subject<string>();
-    private initPage() {
-    this.organization =  {
+  private initPage() {
+    this.monitorPoint = {
       name: {
         text: '������',
-        width: '120px'  
+        width: '300px'
+      },
+      address: {
+        text: '������',
+        width: '300px',
+        format: (value: any, col: Column, row: any) => {
+          value = value == null ? '' : value;
+          if (row['areaNames'] != null) {
+            return row['areaNames']['provinceName'] 
+              + (!!row['areaNames']['cityName'] ? row['areaNames']['cityName'] : '')
+              + (!!row['areaNames']['areaName'] ? row['areaNames']['areaName'] : '')
+              + (!!row['areaNames']['townName'] ? row['areaNames']['townName'] : '')
+              + (!!row['areaNames']['villageName'] ? row['areaNames']['villageName'] : '')
+              + value;
+          } else {
+            return value;
+          }
+
+        }
+      },
+      description: {
+        text: '������',
+        width: '300px'
       }
     };
-    this.grid.title = '������������';
-    this.grid.setColumns(this.organization);
+    this.grid.title = '������������';
+    this.grid.setColumns(this.monitorPoint);
     this.grid.pageSize = 10;
   }
   constructor(
+    private coorPickerService: CoorPickerService,
     private monitorPointService: MonitorPointService,
-    
     private confirmServ: NzModalService,
     public msgSrv: NzMessageService,
     private modalHelper: ModalHelper,
-  ) {}
+    private organizationService: OrganizationService
+  ) { }
 
   ngOnInit() {
     this.initPage();
     this.queryTextStream
-    .debounceTime(500)
-    .distinctUntilChanged()
-    .subscribe(queryText => {
+      .debounceTime(500)
+      .distinctUntilChanged()
+      .subscribe(queryText => {
         this.load();
-    });
+      });
+    this.orgSelectChange();
+  }
+ public setOrganizationId(orgId) {
+    this.queryMap.organizationId = orgId;
+    this.load();
   }
   queryTextChanged($event) {
-      this.queryTextStream.next(this.queryMap.value);
+    this.queryTextStream.next(this.queryMap.mpointName);
   }
-  load(reload: boolean = false) {   
+  load(reload: boolean = false) {
     if (reload) {
-      this.grid.pageIndex = 1 ;
+      this.grid.pageIndex = 1;
     }
     // ������������������ExpressionChangedAfterItHasBeenCheckedError
     setTimeout(() => {
       this.grid.loading = true;
-     }, 1);
-    this.monitorPointService.getPagingList(this.grid, this.queryMap.value).subscribe(
-       (res: PageBean) => {
-            this.grid.loading = true;
-            if (res != null && res.data != null) {
-              this.grid.initData(res);
-              this.grid.refreshStatus();
-              setTimeout(() => {
-                this.grid.loading = false;
-               }, 1);
-            }
-       }
+    }, 1);
+    const example = new ExampleService();
+    const organizationId = !!this.queryMap.organizationId ? this.queryMap.organizationId : null;
+    const mpointName = !!this.queryMap.mpointName ? '%' + this.queryMap.mpointName + '%' : null;
+    example.or()
+    .andEqualTo({name: 'organizationId', value: organizationId })
+    .andLike({name: 'name', value: mpointName  });
+    this.monitorPointService.getPageByExample(this.grid, example).subscribe(
+      (res: PageBean) => {
+        this.grid.loading = true;
+        if (res != null && res.data != null) {
+          this.grid.initData(res);
+          this.grid.refreshStatus();
+          setTimeout(() => {
+            this.grid.loading = false;
+          }, 1);
+        }
+      }
     );
   }
 
-// rowData���null���������������
+  // rowData���null���������������
   addOrModify(d) {
     const data = {};
-    if ( d != null) {
+    if (d != null) {
       Object.assign(data, d);
     }
-    const cols = this.organization;
-    this.modalHelper.static(MonitorPointEditComponent, { cols , data }).subscribe( 
-      ( ret: { data: any, close: Function} ) => {
-      // ������������
-      if (ret.data['index'] != null ) {
-          const index: number = ret.data['index'] ;
-          const origData = this.grid.getData()[index];
-          const isModified =  Object.keys(origData).some(
+    let configMap = {};
+    configMap = Object.assign(configMap, this.queryMap);
+    this.modalHelper.static(MonitorPointEditComponent, { data, configMap }).subscribe(
+      (ret: { data: any, close: Function }) => {
+        // ������������
+        if (ret.data['index'] != null) {
+          const index: number = ret.data['index'];
+          const origData = this.grid.data[index];
+          const isModified = Object.keys(origData).some(
             (key: string) => {
-                return ret.data[key] !== origData[key];    
-            } 
+              return ret.data[key] !== origData[key];
+            }
           );
           // ������������
-          if (!isModified) { 
+          if (!isModified) {
             ret.close();
-            this.msgSrv.success('���������������������������');
+            this.msgSrv.success(this.grid.title + '���������������������');
             return;
           }
-      }
-      this.monitorPointService.save(ret.data).subscribe(
-         ( res: any) => {
+        }
+        this.monitorPointService.save(ret.data).subscribe(
+          (res: any) => {
             if (res.code === 1) {
               this.load();
               ret.close();
-              this.msgSrv.success('���������������������');
+              this.msgSrv.success(this.grid.title + '���������������');
             }
-         }
-      );
-    });
+          }
+        );
+      });
   }
 
   delete(...id: number[]) {
-    this.monitorPointService.delete( ...id ).subscribe(
-      ( res: any) => {
-         if (res.code === 1) {
-           this.load();
-           this.msgSrv.success('���������������������������');
-         }
+    this.monitorPointService.delete(...id).subscribe(
+      (res: any) => {
+        if (res.code === 1) {
+          this.load();
+          this.msgSrv.success(this.grid.title + '���������������');
+        }
       }
-   );
+    );
   }
 
-   deleteSelected() {
+  deleteSelected() {
     this.confirmServ.confirm({
       title: '������������',
       content: '������������������������������������������������',
       okText: '������',
       cancelText: '������'
     }).on('onOk', () => {
-       if (this.grid.selectedIndexs != null && this.grid.selectedIndexs.length > 0) {
-          const ids = this.grid.selectedIndexs.map(
-              (index: number) => {
-                  const id = this.grid.data[index].id;
-                  return Number.parseInt(id);
-              }
-          );
-          this.delete( ...ids );
-       }
+      if (this.grid.selectedIndexs != null && this.grid.selectedIndexs.length > 0) {
+        const ids = this.grid.selectedIndexs.map(
+          (index: number) => {
+            const id = this.grid.data[index].id;
+            return Number.parseInt(id);
+          }
+        );
+        this.delete(...ids);
+      }
     });
   }
   sort(field: string, value: string) {
     // ������������field
     this.grid.sorts = this.grid.sorts.filter(
-       (fn: string) => {
-          return fn !== field;
-       }
-     );
-     // ������value������null������������������������������filed
-     if ( value != null ) {
-        this.grid.sorts.push(field);
-     }
-     this.load();
+      (fn: string) => {
+        return fn !== field;
+      }
+    );
+    // ������value������null������������������������������filed
+    if (value != null) {
+      this.grid.sorts.push(field);
+    }
+    this.load();
   }
+  configCoord(record: MonitorPoint): void {
+    Object.assign(this.coorPickerService.data, record);
+    const _data = this.coorPickerService.data;
+    const areaNames = record.areaNames;
+    let adress = '';
+    if (areaNames != null) {
+      adress += !!areaNames.provinceName ? areaNames.provinceName : '';
+      adress += ' ';
+      adress += !!areaNames.cityName ? areaNames.cityName : '';
+      adress += ' ';
+      adress += !!areaNames.areaName ? areaNames.areaName : '';
+      adress += ' ';
+      adress += !!record.address ? record.address : '';
+    }
+    this.coorPickerService.data.address = adress;
+    this.coorPickerService.data['describe'] = '������������������';
+    this.modalHelper.static(CoordinatesPickerComponent).subscribe(
+      (staticComp) => {
+        const data: MonitorPoint = {
+          id: record.id,
+          longitude: _data.longitude,
+          latitude: _data.latitude,
+        };
+        this.monitorPointService.save(data).subscribe(
+          (res: any) => {
+            if (res.code === 1) {
+              this.load();
+              this.msgSrv.success('���������������������');
+            }
+          }
+        );
 
-  reset(ls: any[]) {
-    for (const item of ls) item.value = false;
-    this.load(true);
+      }
+    );
   }
-
+  orgSelectChange(text?: string) {    
+    const pageBean: PageBean = {pageIndex: 0, pageSize: 20};
+    this.organizationService.getPagingList(pageBean, text).subscribe(
+      (res: PageBean) => {
+           if (res != null && res.data != null) {               
+               this.orgOptions = res.data;
+           }
+      }
+   );
+  }
 }

--
Gitblit v1.8.0