From f0b742d34e95811b6874bcaedbc7a06451d39da1 Mon Sep 17 00:00:00 2001 From: fengxiang <110431245@qq.com> Date: Fri, 12 Jan 2018 21:07:08 +0800 Subject: [PATCH] 组织配置 --- src/app/routes/systems/organization/organization-config/organization-config.component.ts | 151 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 144 insertions(+), 7 deletions(-) diff --git a/src/app/routes/systems/organization/organization-config/organization-config.component.ts b/src/app/routes/systems/organization/organization-config/organization-config.component.ts index f9fdffa..100d3a0 100644 --- a/src/app/routes/systems/organization/organization-config/organization-config.component.ts +++ b/src/app/routes/systems/organization/organization-config/organization-config.component.ts @@ -1,24 +1,161 @@ +import { filter } from 'rxjs/operators'; +import { HttpClient } from '@angular/common/http'; +import { FormGroup, FormBuilder, FormControl, Validators } from '@angular/forms'; +import { SensorsService } from '@business/services/http/sensors.service'; +import { Grid, PageBean } from '@business/entity/grid'; import { Organization } from '@business/entity/data'; -import { Component, OnInit } from '@angular/core'; +import { Component, OnInit, OnDestroy } from '@angular/core'; import { OrganizationService } from '@business/services/http/organization.service'; +import { _HttpClient } from '@delon/theme'; +import { AlarmConfigService } from '@business/services/http/alarm-config.service'; +import { AlarmStyle } from '@business/enum/types.enum'; @Component({ selector: 'app-organization-config', templateUrl: './organization-config.component.html', - styles: [] + styles: [], + providers: [AlarmConfigService] }) -export class OrganizationConfigComponent implements OnInit { - organization: Organization; +export class OrganizationConfigComponent implements OnInit, OnDestroy { + ngOnDestroy(): void { + this.backToList(); + } + private organization:Organization; + grid: Grid<object> = new Grid<object>(null); + validateForm: FormGroup; constructor( - private organizationService: OrganizationService - ) { - console.log(this.organizationService.data); + private organizationService: OrganizationService, + private sensorsService: SensorsService, + private alarmConfigService:AlarmConfigService, + private formBuilder: FormBuilder, + private http: _HttpClient + ) { + this.organization = this.organizationService.data; } ngOnInit() { + this.load(); } + load(reload: boolean = false) { + if (reload) { + this.grid.pageIndex = 1 ; + } + // TODO + // ������������������ExpressionChangedAfterItHasBeenCheckedError + // setTimeout(() => { + // this.grid.loading = true; + // }, 1); + let pageBean = this.organizationService.config.pageBean;// + let resultBean = this.organizationService.config.resultBean; + resultBean = resultBean == null?{} : resultBean; + if (pageBean != null && pageBean.data != null) { + this.grid.initData(pageBean); + this.grid.refreshStatus(); + setTimeout(() => { + this.grid.loading = false; + }, 1); + let validates = {}; + let data = resultBean.data == null ?{}:resultBean.data; + const value = data['value'] == null ? {} : data['value']; + let alarmLevels = value['alarmLevels']; + alarmLevels = alarmLevels==null ? {} : alarmLevels; + // ������������ + const level_num = 3; + this.grid.data.forEach( + (sensor: object) => { + const sensorLevel = alarmLevels[sensor['key']] == null ?{}:alarmLevels[sensor['key']]; + const enable_key = sensor['key'] + '_enable'; + const enable_value = sensorLevel['enable'] == null ? false : sensorLevel['enable'] == 1; + validates[enable_key] = enable_value; + const increments:number[] = sensorLevel['increment']; + const degression:number[] = sensorLevel['degression']; + for(let i=0;i<level_num;i++){ + const increment_key = sensor['key']+'_level_increment_'+(i+1); + if( increments == null || increments.length == 0 ){ + validates[increment_key] = [null,[Validators.pattern('^\\d+(\\.\\d+)?$')]]; + }else{ + const increment_value = increments.length>i ? increments[i]:null ; + validates[increment_key] = [increment_value,[Validators.pattern('^\\d+(\\.\\d+)?$')]]; + } + const degression_key = sensor['key']+'_level_degression_'+(i+1); + if( degression == null || degression.length == 0 ){ + validates[degression_key] = [null,[Validators.pattern('^\\d+(\\.\\d+)?$')]]; + }else{ + const degression_value = degression.length>i ? degression[i]:null ; + validates[degression_key] = [degression_value,[Validators.pattern('^\\d+(\\.\\d+)?$')]]; + } + } + + } + ); + validates['_allChecked'] = [this.grid.allChecked]; + //������������������ + let alarmMode = value['alarmMode']; + alarmMode = alarmMode==null ? {}: alarmMode; + this.alarmModes.push( + {label:'������',value:AlarmStyle.email, disabled: false}, + {label:'������',value:AlarmStyle.sms, disabled: false}, + {label:'������',value:AlarmStyle.voice, disabled: false}, + {label:'������',value:AlarmStyle.weixin, disabled: false} + ); + validates['mode_enable'] = [alarmMode['enable']]; + for(let i = 0; i<level_num; i++){ + const n = i+1; + validates['mode_level'+n] = [AlarmStyle[alarmMode['level'+n]]]; + } + this.validateForm = this.formBuilder.group(validates); + this.grid.loading = false; + this.enableKeys = Object.keys(this.validateForm.value).filter( + (key: string) => { + return key.endsWith('_enable'); + } + ); + this.enableKeys.forEach( + (key: string) => { + this.validateForm.controls[key].valueChanges.subscribe( + (value: any) => { + if(this._allCheckTriggers <= 0){ + this.refreshIndeterminate(); + } else { + this._allCheckTriggers--; + } + } + ); + } + ); + this.refreshIndeterminate(); + } + + } + alarmModes: {label:string,value:AlarmStyle,disabled: boolean} [] = []; + backToList() { this.organizationService.handle = 'list'; this.organizationService.title = '������������'; } + enableKeys: string []; + indeterminate: boolean; + checkAll(param){ + this._allCheckTriggers = 0; + this.enableKeys.forEach( + (key: string) => { + this._allCheckTriggers++; + this.validateForm.controls[key].setValue(param); + } + ); + this.refreshIndeterminate(); + } + private _allCheckTriggers: number = 0; + refreshIndeterminate(){ + const allChecked = this.enableKeys.every(key => this.validateForm.controls[key].value); + const allUnChecked = this.enableKeys.every(key => !this.validateForm.controls[key].value); + this.indeterminate = (!allChecked) && (!allUnChecked); + } + save($event, value, valid) { + $event.preventDefault(); + if (valid) { + + + } + } } -- Gitblit v1.8.0