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

declare let cordova: any;

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

export class MinePage implements OnInit {

    user: any = {};
    videoData = {
        address: '222.73.111.148:443',
        username: 'admin',
        password: 'Landfun2012',
        department: 2,
        cameraList: [{
            name: 'G095_监控点1',
            sysCode: '22d78936f40e451881e4b2f46034f0f0'
        }],
        role: 5
    };

    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 : '登录失败');
            }
        }]);
        // cordova.plugins.HikvisionPlugin.coolMethod(this.videoData);
    }

}
