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

@Component({
    selector: 'v-mine',
    templateUrl: './mine.page.html',
    styleUrls: ['./mine.page.scss'],
})
export class MinePage implements OnInit {

    user: any = {};

    constructor(private api: Api, private tf: Transfer) {
    }

    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');
                window.localStorage.removeItem('muchangUsername');
                window.localStorage.removeItem('muchangPassword');
                this.tf.transfer({url: '/login'});
            } else {
                this.api.presentMsgToast(data && data.message ? data.message : '登录失败');
            }
        }]);
    }

    onLeftClick() {
        this.tf.transfer({url: '/index'});
    }
}
