import { Component, OnInit } from '@angular/core';
import {ApiService} from '../../service/api.service';
import {TransferService} from '../../service/transfer.service';

@Component({
    selector: 'app-page-four',
    templateUrl: './page-four.component.html',
    styleUrls: ['./page-four.component.scss'],
})
export class PageFourComponent implements OnInit {

    user: any = {};

    constructor(private api: ApiService, private tf: TransferService) {
    }

    ngOnInit() {
        this.getSelfInfo();
    }

    getSelfInfo() {
        this.api.user.getSelfInfo(['', (data) => {
            if (data) {
                this.user = data;
            } else {
                this.api.presentMsgToast(data && data.message ? data.message : '登录失败');
            }
        }]);
    }

    loginOut() {
        this.api.login.logout(['', (data) => {
            if (data) {
                window.localStorage.removeItem('token');
                this.tf.transfer({
                    to: 'app-extra',
                    from: 'app-home',
                    url: '/extra',
                    hash: '',
                    query: ''
                });
            } else {
                this.api.presentMsgToast(data && data.message ? data.message : '登录失败');
            }
        }]);
    }
}
