From 45d40501534b95bfd4a8f744b560651a87849fa4 Mon Sep 17 00:00:00 2001
From: fengxiang <110431245@qq.com>
Date: Fri, 05 Jan 2018 11:21:37 +0800
Subject: [PATCH] 监控点

---
 src/app/routes/devices/devices.module.ts                                                  |    8 
 src/app/routes/systems/organization/organization.service.ts                               |    3 
 src/app/routes/devices/monitor-point/monitor-point-edit/monitor-point-edit.component.html |    3 
 src/app/routes/devices/version/version.service.ts                                         |    3 
 src/app/routes/systems/organization/organization.component.ts                             |   15 ++
 src/app/core/entity/grid.ts                                                               |    2 
 src/app/routes/devices/monitor-point/monitor-point.component.ts                           |  168 +++++++++++++++++++++++++++
 src/app/routes/devices/monitor-point/monitor-point-edit/monitor-point-edit.component.ts   |   15 ++
 src/app/routes/devices/monitor-point/monitor-point.component.html                         |   69 +++++++++++
 src/app/routes/devices/monitor-point/monitor-point.service.ts                             |   35 +++++
 10 files changed, 309 insertions(+), 12 deletions(-)

diff --git a/src/app/core/entity/grid.ts b/src/app/core/entity/grid.ts
index d380735..3a1ac82 100644
--- a/src/app/core/entity/grid.ts
+++ b/src/app/core/entity/grid.ts
@@ -13,7 +13,7 @@
    sort?: string;
    isSort?: boolean;
    type?: DataType;
-   format?: Function;
+   format?: (value: any, col: Column, row: any) => string;
 }
 export interface DataType {
     name: Types;
diff --git a/src/app/routes/devices/devices.module.ts b/src/app/routes/devices/devices.module.ts
index 71b1b01..e65f3b7 100644
--- a/src/app/routes/devices/devices.module.ts
+++ b/src/app/routes/devices/devices.module.ts
@@ -1,3 +1,4 @@
+import { MonitorPointService } from 'app/routes/devices/monitor-point/monitor-point.service';
 
 import { ToolsService } from './../../core/services/tools.service';
 import { NgModule } from '@angular/core';
@@ -13,8 +14,9 @@
 import { PipeModule } from '@core/pipe/pipe.module';
 import { FormBuilder } from '@angular/forms';
 import { VersionEditComponent } from './version/version-edit/version-edit.component';
+import { MonitorPointEditComponent } from './monitor-point/monitor-point-edit/monitor-point-edit.component';
 
-const COMPONENTS_NOROUNT = [  VersionEditComponent  ];
+const COMPONENTS_NOROUNT = [  VersionEditComponent, MonitorPointEditComponent  ];
 
 const routes: Routes = [
   {
@@ -39,9 +41,9 @@
     BasicInfoComponent,
     VersionComponent,
     MonitorPointComponent,
-    ...COMPONENTS_NOROUNT     
+       ...COMPONENTS_NOROUNT     
   ],
-  providers: [ToolsService, VersionService, _HttpClient, FormBuilder],
+  providers: [ToolsService, VersionService, MonitorPointService, _HttpClient, FormBuilder],
   entryComponents: COMPONENTS_NOROUNT
 })
 export class DevicesModule { }
diff --git a/src/app/routes/devices/monitor-point/monitor-point-edit/monitor-point-edit.component.html b/src/app/routes/devices/monitor-point/monitor-point-edit/monitor-point-edit.component.html
new file mode 100644
index 0000000..ad9f119
--- /dev/null
+++ b/src/app/routes/devices/monitor-point/monitor-point-edit/monitor-point-edit.component.html
@@ -0,0 +1,3 @@
+<p>
+  monitor-point-edit works!
+</p>
diff --git a/src/app/routes/devices/monitor-point/monitor-point-edit/monitor-point-edit.component.ts b/src/app/routes/devices/monitor-point/monitor-point-edit/monitor-point-edit.component.ts
new file mode 100644
index 0000000..a99f4d1
--- /dev/null
+++ b/src/app/routes/devices/monitor-point/monitor-point-edit/monitor-point-edit.component.ts
@@ -0,0 +1,15 @@
+import { Component, OnInit } from '@angular/core';
+
+@Component({
+  selector: 'app-monitor-point-edit',
+  templateUrl: './monitor-point-edit.component.html',
+  styles: []
+})
+export class MonitorPointEditComponent implements OnInit {
+
+  constructor() { }
+
+  ngOnInit() {
+  }
+
+}
diff --git a/src/app/routes/devices/monitor-point/monitor-point.component.html b/src/app/routes/devices/monitor-point/monitor-point.component.html
index 7fd487b..b580411 100644
--- a/src/app/routes/devices/monitor-point/monitor-point.component.html
+++ b/src/app/routes/devices/monitor-point/monitor-point.component.html
@@ -1,3 +1,66 @@
-<p>
-  monitor-point works!
-</p>
+<pro-header [title]="grid.title"></pro-header>
+<nz-card [nzBordered]="false">
+    	<div class="mb-md">
+                <button nz-button (click)="addOrModify()" [nzType]="'primary'" [nzSize]="'large'">
+                    <i class="anticon anticon-plus"></i><span>������</span>
+                </button>
+                <ng-container *ngIf="grid.selectedIndexs.length > 0"> &nbsp;
+                <button nz-button [nzSize]="'large'" (click)="deleteSelected()">������������</button>
+                </ng-container>
+                <nz-input [ngStyle]="{'width': '280px','float':'right'}" [(ngModel)]="queryMap.value" name=""  [nzPlaceHolder]="queryMap.text"
+                (keyup)="queryTextChanged($event)" (change)="queryTextChanged($event)" ></nz-input>
+        </div>
+    	<div class="mb-md">
+                <nz-alert *ngIf="grid.selectedIndexs.length > 0" [nzType]="'info'" [nzShowIcon]="true"> 
+                    <span alert-body>
+                         ���������<strong class="text-primary">{{grid.selectedIndexs.length}}</strong>���
+                    </span> 
+                </nz-alert>
+    </div>
+    <nz-table #nzTable
+              [nzAjaxData]="grid.data"              
+              [nzTotal]="grid.total"
+              [(nzPageIndex)]="grid.pageIndex"
+              [(nzPageSize)]="grid.pageSize"
+              [nzLoading]="grid.loading"
+              [nzShowTotal]="true"
+              (nzPageIndexChange)="load()">
+              <thead nz-thead>
+                  <tr>
+                    <th nz-th [nzCheckbox]="true">
+                        <label nz-checkbox [(ngModel)]="grid.allChecked" [nzIndeterminate]="grid.indeterminate" (ngModelChange)="grid.checkAll($event)"></label>
+                    </th>
+                    <th nz-th *ngFor="let col of grid.columns"
+                     [ngStyle]="{'width':col.width,'text-align':col['align'] === undefined?'left':col.align}" >
+                           <span>{{ col.text }}</span>
+                           <nz-table-sort *ngIf="col.isSort"   [(nzValue)]="col.sort" (nzValueChange)="sort(col.name,$event)"></nz-table-sort>
+                    </th>
+                    <th nz-th><span>������</span></th>
+                  </tr>
+              </thead>
+              <tbody nz-tbody>
+                <tr nz-tbody-tr *ngFor="let row of nzTable.data">
+                    <td nz-td [nzCheckbox]="true">
+                       <label nz-checkbox [(ngModel)]="row.checked" (ngModelChange)="grid.refreshStatus($event)"></label>
+                    </td>
+                    <td nz-td *ngFor="let col of grid.columns"
+                    [ngStyle]="{'width':col.width,'text-align':col['align'] === undefined?'left':col.align}">
+                        <span [ngSwitch]="col.type">
+                             <!-- ������������������������������������ -->
+                            <span *ngSwitchDefault> {{ row[col.name]|tyepHandle:col:row }} </span>
+                             <!-- ������������������������������������ -->        
+                        </span>
+                    </td>
+                    <td nz-td>
+                            <a (click)="addOrModify(row)">������</a>
+                            <span nz-table-divider></span>
+                              <nz-popconfirm [nzTitle]="'���������������������������?'" [nzOkText]="'Yes'" [nzCancelText]="'No'" (nzOnConfirm)="delete(row.id)" >
+                                <a nz-popconfirm>������</a>
+                              </nz-popconfirm>
+                     </td>
+                </tr>
+              </tbody>
+              </nz-table>
+  </nz-card>
+  
+
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 9ada8ef..e1a6b84 100644
--- a/src/app/routes/devices/monitor-point/monitor-point.component.ts
+++ b/src/app/routes/devices/monitor-point/monitor-point.component.ts
@@ -1,5 +1,33 @@
+import { DataType, AreaNames } from './../../../core/entity/grid';
+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 { 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';
 
+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',
@@ -7,9 +35,147 @@
 })
 export class MonitorPointComponent implements OnInit {
 
-  constructor() { }
+
+  private organization: MonitorPoint;
+  grid: Grid<MonitorPoint> = new Grid(null);
+  queryMap = { text: '���������������', value: ''};
+  queryTextStream: Subject<string> = new Subject<string>();
+    private initPage() {
+    this.organization =  {
+      name: {
+        text: '������',
+        width: '120px'  
+      }
+    };
+    this.grid.title = '������������';
+    this.grid.setColumns(this.organization);
+    this.grid.pageSize = 10;
+  }
+  constructor(
+    private monitorPointService: MonitorPointService,
+    
+    private confirmServ: NzModalService,
+    public msgSrv: NzMessageService,
+    private modalHelper: ModalHelper,
+  ) {}
 
   ngOnInit() {
+    this.initPage();
+    this.queryTextStream
+    .debounceTime(500)
+    .distinctUntilChanged()
+    .subscribe(queryText => {
+        this.load();
+    });
+  }
+  queryTextChanged($event) {
+      this.queryTextStream.next(this.queryMap.value);
+  }
+  load(reload: boolean = false) {   
+    if (reload) {
+      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);
+            }
+       }
+    );
+  }
+
+// rowData���null���������������
+  addOrModify(d) {
+    const data = {};
+    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(
+            (key: string) => {
+                return ret.data[key] !== origData[key];    
+            } 
+          );
+          // ������������
+          if (!isModified) { 
+            ret.close();
+            this.msgSrv.success('���������������������������');
+            return;
+          }
+      }
+      this.monitorPointService.save(ret.data).subscribe(
+         ( res: any) => {
+            if (res.code === 1) {
+              this.load();
+              ret.close();
+              this.msgSrv.success('���������������������');
+            }
+         }
+      );
+    });
+  }
+
+  delete(...id: number[]) {
+    this.monitorPointService.delete( ...id ).subscribe(
+      ( res: any) => {
+         if (res.code === 1) {
+           this.load();
+           this.msgSrv.success('���������������������������');
+         }
+      }
+   );
+  }
+
+   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 );
+       }
+    });
+  }
+  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();
+  }
+
+  reset(ls: any[]) {
+    for (const item of ls) item.value = false;
+    this.load(true);
   }
 
 }
diff --git a/src/app/routes/devices/monitor-point/monitor-point.service.ts b/src/app/routes/devices/monitor-point/monitor-point.service.ts
new file mode 100644
index 0000000..89045e4
--- /dev/null
+++ b/src/app/routes/devices/monitor-point/monitor-point.service.ts
@@ -0,0 +1,35 @@
+import { ExampleService } from './../../../core/services/example.service';
+import { _HttpClient } from '@delon/theme';
+import { environment } from './../../../../environments/environment.prod';
+import { RouteConfigLoadStart } from '@angular/router';
+import { Injectable } from '@angular/core';
+import { equal } from 'assert';
+import { Observable } from 'rxjs/Observable';
+import {  PageBean } from '@core/entity/grid';
+
+@Injectable()
+export class MonitorPointService {
+
+  private urls = {
+    edit: environment.SERVER_BASH_URL + '/monitor-point/page-list',
+    save: environment.SERVER_BASH_URL + '/monitor-point/add-or-modify',
+    delete: environment.SERVER_BASH_URL + '/monitor-point/delete-by-ids'
+};
+constructor(private http: _HttpClient) { }
+ public getPagingList(page: PageBean, queryText: string): Observable<PageBean> {
+  const example = new ExampleService();
+  if (queryText != null && queryText !== '') {
+    example.or().andLike({name: 'name', value: '%' + queryText + '%'});
+  }
+  const param: PageBean = {pageSize: page.pageSize, pageIndex: page.pageIndex, 
+      queryParams: example.getSqlParam(), orderByClause: page.getOrderByClause()};
+      return this.http.get(this.urls.edit, param);
+}
+public save(data: any): Observable<any> {
+      return this.http.post(this.urls.save, data);
+}
+public delete(...ids: number[]): Observable<any> {             
+      return this.http.post(this.urls.delete, ids);
+}
+
+}
diff --git a/src/app/routes/devices/version/version.service.ts b/src/app/routes/devices/version/version.service.ts
index c18123a..b94059e 100644
--- a/src/app/routes/devices/version/version.service.ts
+++ b/src/app/routes/devices/version/version.service.ts
@@ -1,6 +1,6 @@
 import { ExampleService } from './../../../core/services/example.service';
 import { _HttpClient } from '@delon/theme';
-import { environment } from './../../../../environments/environment.prod';
+import { environment } from './../../../../environments/environment';
 import { RouteConfigLoadStart } from '@angular/router';
 import { Injectable } from '@angular/core';
 import { equal } from 'assert';
@@ -20,6 +20,7 @@
     const example = new ExampleService();
     if (queryText != null && queryText !== '') {
       example.or().andLike({name: 'name', value: '%' + queryText + '%'});
+      example.or().andEqualTo({name: 'version', value: queryText});
     }
     const param: PageBean = {pageSize: page.pageSize, pageIndex: page.pageIndex, 
       queryParams: example.getSqlParam(), orderByClause: page.getOrderByClause()};
diff --git a/src/app/routes/systems/organization/organization.component.ts b/src/app/routes/systems/organization/organization.component.ts
index ef58ac4..5aa3a9a 100644
--- a/src/app/routes/systems/organization/organization.component.ts
+++ b/src/app/routes/systems/organization/organization.component.ts
@@ -51,7 +51,20 @@
       },
       rank: {
         text: '������',
-        width: '60px'
+        width: '80px',
+        format: (value: any, col: Column, row: any) => {
+          const item = [
+            { value: 0, label: '������' },
+            { value: 1, label: '������������' },
+            { value: 2, label: '���������' },
+            { value: 3, label: '������������' },
+            { value: 4, label: '���������' },
+            { value: 5, label: '���������' }
+          ].filter( (rankItem: {value: number, label: string }) => {
+            return rankItem.value === value;
+          });
+          return item != null && item.length === 1 ? item[0].label : '';
+        }
       },
       telephone: {
         text: '������',
diff --git a/src/app/routes/systems/organization/organization.service.ts b/src/app/routes/systems/organization/organization.service.ts
index 1e75ef8..85b97ba 100644
--- a/src/app/routes/systems/organization/organization.service.ts
+++ b/src/app/routes/systems/organization/organization.service.ts
@@ -1,6 +1,6 @@
 import { ExampleService } from './../../../core/services/example.service';
 import { _HttpClient } from '@delon/theme';
-import { environment } from './../../../../environments/environment.prod';
+import { environment } from './../../../../environments/environment';
 import { RouteConfigLoadStart } from '@angular/router';
 import { Injectable } from '@angular/core';
 import { equal } from 'assert';
@@ -20,7 +20,6 @@
     const example = new ExampleService();
     if (queryText != null && queryText !== '') {
       example.or().andLike({name: 'name', value: '%' + queryText + '%'});
-      example.or().andEqualTo({name: 'version', value: queryText});
     }
     const param: PageBean = {pageSize: page.pageSize, pageIndex: page.pageIndex, 
         queryParams: example.getSqlParam(), orderByClause: page.getOrderByClause()};

--
Gitblit v1.8.0