| import { DeviceVersion } from '@business/entity/data'; | 
| import { Component, OnInit } from '@angular/core'; | 
| import { NzMessageService, NzModalSubject } from 'ng-zorro-antd'; | 
| import { FormGroup, FormBuilder, Validators } from '@angular/forms'; | 
|   | 
| @Component({ | 
|   selector: 'app-version-edit', | 
|   templateUrl: './version-edit.component.html', | 
|   styles: [] | 
| }) | 
| export class VersionEditComponent implements OnInit { | 
|   | 
|   cols: DeviceVersion; | 
|   | 
|   data: DeviceVersion; | 
|   isSaving = false; | 
|   validateForm: FormGroup; | 
|   constructor(     | 
|     private subject: NzModalSubject, | 
|     private formBuilder: FormBuilder | 
|     ) { } | 
|   | 
|   ngOnInit() { | 
|      if (this.data.createTime == null) { | 
|       this.data.createTime = new Date().getTime(); | 
|      } | 
|      const validates: DeviceVersion = { | 
|           name: [this.data.name, [Validators.required] ], | 
|           version: [this.data.version == null ? 1 : this.data.version, [Validators.required] ], | 
|           createTime: [this.data.createTime, [Validators.required] ], | 
|           description: [this.data.description] | 
|      }; | 
|      this.validateForm = this.formBuilder.group( | 
|       validates | 
|      ); | 
|   } | 
|   close() { | 
|        this.subject.destroy(); | 
|   } | 
|   save($event, value, valid) { | 
|       $event.preventDefault(); | 
|       if (valid) { | 
|         for (const i in this.validateForm.controls) { | 
|           this.validateForm.controls[ i ].disable(); | 
|         }  | 
|        const isModified =  Object.keys(value).some( | 
|           (key: string) => { | 
|               return this.data[key] !== value[key];     | 
|           }  | 
|         ); | 
|         // 未作修改 | 
|         if (!isModified) {  | 
|           this.close(); | 
|           return; | 
|         } | 
|         this.isSaving = true; | 
|         Object.keys(value).forEach( (key: string) => { | 
|               if ( value[key] != null ) { | 
|                    this.data[key] = value[key]; | 
|               } | 
|         } ); | 
|         this.subject.next( this ); | 
|       }else { | 
|         this.validate();  | 
|       } | 
|   } | 
|   validate() { | 
|      for (const i in this.validateForm.controls) { | 
|        this.validateForm.controls[ i ].markAsDirty(); | 
|      } | 
|   } | 
| } |