import {Component, ElementRef, OnInit, Renderer} from '@angular/core';
import {LoginService, StateStorageService} from '..';
import {FormBuilder, Validators} from '@angular/forms';
import {Route, Router} from '@angular/router';
import {JhiEventManager} from 'ng-jhipster';
import {NgbActiveModal} from '@ng-bootstrap/ng-bootstrap';
import {EmitService} from '../event/eventEmitter';
import {NzNotificationService} from 'ng-zorro-antd';
import {LocalStorageService} from 'ngx-webstorage';
import {OverAllService} from '../../overAll/overAll.service';

@Component({
    selector: 'smart-signal',
    templateUrl: './signal.component.html',
    styles: []
})
//模拟登录
export class SignalComponent implements OnInit {

    constructor(private fb: FormBuilder,
                private eventManager: JhiEventManager,
                private loginService: LoginService,
                private stateStorageService: StateStorageService,
                private elementRef: ElementRef,
                private renderer: Renderer,
                private router: Router,
                public activeModal: NgbActiveModal,
                public emitService: EmitService,
                public notification: NzNotificationService,
                public $localStorage: LocalStorageService,
                public overAll: OverAllService) {
    }

    ngOnInit() {
        const data = {
            loginName: 'superadmin',
            password: '000000',
            rememberMe: true,
        };
        this.loginService.login(data).then((res: any) => {
            if (res) {
                this.router.navigate(['app/main/home']);
                this.notification.create('success', '登录成功', '', {nzDuration: 2000});
                this.$localStorage.store('userInfo', data);
            } else {
                this.notification.create('error', '登录失败', `${res.errMsg}`, {nzDuration: 2000});
            }
        }).catch(() => {
        });
    }

}
