import { zip } from 'rxjs/observable/zip';
|
import { DeviceAdjustValueService } from '@business/services/http/device-adjust-value.service';
|
import { NzModalSubject, NzMessageService } from 'ng-zorro-antd';
|
import { SensorsService } from '@business/services/http/sensors.service';
|
import { Component, OnInit } from '@angular/core';
|
import { DeviceAdjustValue, Sensor, Device } from '@business/entity/data';
|
import { Grid, PageBean, ResultBean } from '@business/entity/grid';
|
|
@Component({
|
selector: 'app-adjust-config',
|
templateUrl: './adjust-config.component.html',
|
styles: []
|
})
|
export class AdjustConfigComponent implements OnInit {
|
record:Device;
|
_dataValue:{[s:string]:number} = {};
|
data:DeviceAdjustValue;
|
deviceVersionId: number;
|
isSaving = false;
|
grid: Grid<Sensor> = new Grid(null);
|
private initPage() {
|
const sensor: Sensor = {
|
name: {
|
text: '名称',
|
width: '200px'
|
},
|
sensorKey: {
|
text: '键值',
|
width: '60px'
|
},
|
lower: {
|
text: '下限值',
|
width: '90px'
|
},
|
upper: {
|
text: '上限值',
|
width: '90px'
|
},
|
unit: {
|
text: '单位',
|
width: '100px'
|
},
|
description: {
|
text: '描述'
|
}
|
};
|
this.grid.title = '传感器';
|
this.grid.setColumns(sensor);
|
this.grid.pageSize = 0;
|
}
|
constructor(
|
private subject: NzModalSubject,
|
private sensorsService: SensorsService,
|
private adjustValueService:DeviceAdjustValueService,
|
public msgSrv: NzMessageService,
|
) { }
|
|
ngOnInit() {
|
this.initPage();
|
this.load();
|
}
|
load() {
|
// 延时加载避免ExpressionChangedAfterItHasBeenCheckedError
|
setTimeout(() => {
|
this.grid.loading = true;
|
}, 1);
|
zip(
|
this.adjustValueService.getByDid(this.record.id),
|
this.sensorsService.getPagingList(this.grid, null)
|
).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);
|
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];
|
}
|
);
|
this.grid.refreshStatus();
|
setTimeout(() => {
|
this.grid.loading = false;
|
}, 1);
|
}
|
}
|
);
|
}
|
close() {
|
this.subject.destroy();
|
}
|
save($event) {
|
// $event.preventDefault();
|
let isModify = Object.keys(this.data.value).some(
|
key => {
|
return this.data.value[key] !== this._dataValue[key];
|
}
|
);
|
debugger;
|
if(isModify){
|
this.adjustValueService.save(this.data).subscribe(
|
(res:ResultBean<any>) =>{
|
if(res!=null&&res.code==1){
|
this.subject.destroy();
|
this.msgSrv.success('校准值配置成功');
|
}
|
}
|
);
|
}else{
|
this.subject.destroy();
|
this.msgSrv.success('校准值配置未改变');
|
}
|
}
|
}
|