From efe936a73370a55d4c3336fb9973a92fcf87efff Mon Sep 17 00:00:00 2001
From: fengxiang <110431245@qq.com>
Date: Thu, 08 Mar 2018 09:22:09 +0800
Subject: [PATCH] ts语法修正,报表部分功能实现

---
 src/app/routes/devices/basic-info/adjust-config/adjust-config.component.ts |   57 +++++++++++++++++++++++++++++++++------------------------
 1 files changed, 33 insertions(+), 24 deletions(-)

diff --git a/src/app/routes/devices/basic-info/adjust-config/adjust-config.component.ts b/src/app/routes/devices/basic-info/adjust-config/adjust-config.component.ts
index 2ae7c10..a29198b 100644
--- a/src/app/routes/devices/basic-info/adjust-config/adjust-config.component.ts
+++ b/src/app/routes/devices/basic-info/adjust-config/adjust-config.component.ts
@@ -5,6 +5,8 @@
 import { Component, OnInit } from '@angular/core';
 import { DeviceAdjustValue, Sensor, Device } from '@business/entity/data';
 import { Grid, PageBean, ResultBean } from '@business/entity/grid';
+import { ContentChild } from '@angular/core/src/metadata/di';
+import swal, { SweetAlertType } from 'sweetalert2';
 
 @Component({
   selector: 'app-adjust-config',
@@ -12,9 +14,9 @@
   styles: []
 })
 export class AdjustConfigComponent implements OnInit {
-  record:Device;
-  _dataValue:{[s:string]:number} = {};
-  data:DeviceAdjustValue;
+  record: Device;
+  _dataValue: {[s: string]: number} = {};
+  data: DeviceAdjustValue;
   deviceVersionId: number;
   isSaving = false;
   grid: Grid<Sensor> = new Grid(null);
@@ -51,11 +53,15 @@
   constructor(
     private subject: NzModalSubject,
     private sensorsService: SensorsService,
-    private adjustValueService:DeviceAdjustValueService,
+    private adjustValueService: DeviceAdjustValueService,
     public msgSrv: NzMessageService,
   ) { }
 
   ngOnInit() {
+    if (this.record.deviceVersionId == null) {
+      swal(`������������������������`, '������������������������������������������������������������', 'info');
+      this.subject.destroy();    
+    }
     this.initPage();
     this.load();
   }
@@ -66,22 +72,23 @@
     }, 1);
     zip(
       this.adjustValueService.getByDid(this.record.id),
-      this.sensorsService.getPagingList(this.grid, null)
+      this.sensorsService.getPageByVersionId(this.record.deviceVersionId)
     ).subscribe(
-        ([adjustRes,sensorsRes]) => {
-            if(adjustRes!=null && adjustRes.code==1 && sensorsRes != null && sensorsRes.data != null){
-               this.data = adjustRes.data;
-               if(this.data == null||this.data.deviceId== null){
-                  this.data = {};
-                  this.data.value = {};
-                  this.data['deviceId'] = this.record.id;
-               }
-              // ���������������������
-              Object.assign(this._dataValue,this.data.value);
+        ([adjustRes, sensorsRes]) => {
+            if (adjustRes != null && adjustRes.code === 1 && sensorsRes != null && sensorsRes.data != null) {
+                this.data = {
+                  deviceId: this.record.id,
+                  value: {}
+                };
+                if (adjustRes.data != null) {
+                  // ���������������������
+                  Object.assign(this._dataValue, adjustRes.data.value);
+                  this.data['id'] = adjustRes.data.id;
+                }                
                this.grid.initData(sensorsRes);
                sensorsRes.data.forEach(
-                (item:Sensor) => {
-                  this.data.value[item.sensorKey] = this.data.value[item.sensorKey] == null?0:this.data.value[item.sensorKey];                
+                (item: Sensor) => {
+                  this.data.value[item.sensorKey] = this._dataValue[item.sensorKey] == null ? 0 : this._dataValue[item.sensorKey];                
                   }
               );
               this.grid.refreshStatus();
@@ -97,22 +104,24 @@
   }
   save($event) {
     // $event.preventDefault();
-    let isModify = Object.keys(this.data.value).some(
+    let isModify = Object.keys(this._dataValue).length !== Object.keys(this.data.value).length;
+    if (!isModify) {
+      isModify = Object.keys(this.data.value).some(
         key => {
             return this.data.value[key] !== this._dataValue[key];
         }
-    );
-    debugger;
-    if(isModify){
+      );
+    }
+    if (isModify) {
       this.adjustValueService.save(this.data).subscribe(
-        (res:ResultBean<any>) =>{
-               if(res!=null&&res.code==1){
+        (res: ResultBean<any>) => {
+               if (res != null && res.code === 1) {
                    this.subject.destroy();                   
                    this.msgSrv.success('���������������������');
                }
         }
     );
-    }else{
+    } else {
         this.subject.destroy();
         this.msgSrv.success('������������������������');
     }

--
Gitblit v1.8.0