import {Component} from '@angular/core';
import {App, Events, IonicPage, NavController, NavParams, Platform} from 'ionic-angular';
import {AppService} from "../../app/app.service";
import {Storage} from "@ionic/storage";
import {MineService} from "./mine.service";
import {timer} from "rxjs/observable/timer";
import {LoginService} from "../login/login.service";
import {InAppBrowser} from "@ionic-native/in-app-browser";
import {AppVersion} from "@ionic-native/app-version";
import {LogoutService} from "../../secret/logout.service";
import {CommonService} from "../../core/common.service";
import {PersonPage} from "./person/person";
import {OperationPage} from "./operation/operation";
import {MySupervisePage} from "./my-supervise/my-supervise";
import {MyVerifyPage} from "./my-verify/my-verify";
import {SetPage} from "./set/set";
import {LoginPage} from "../login/login";

@Component({
    selector: 'page-mine',
    templateUrl: 'mine.html',
})
export class MinePage {
    mineInfo;
    userInfo;
    number;
    version;

    appVersionInfo = {
        UpdateTips: false,
        AppUrl: '',
        UpdateText: '',
    }

    constructor(public navCtrl: NavController, public navParams: NavParams, private logoutSer: LogoutService,
                private mineSer: MineService, private events: Events, private appVersion: AppVersion,
                private loginSer: LoginService, private inAppBrowser: InAppBrowser,
                private platform: Platform,
                private commonSer: CommonService,
                private appSer: AppService, private app: App, private storage: Storage) {
        //获取个人信息
        this.storage.get('mineInfo').then(value => {
            this.mineInfo = value;
        })
    }

    ionViewDidEnter() {
        this.getVersion();
    }

    //个人信息
    goToPerson() {
        this.navCtrl.push(PersonPage);
    }

    //我的审核
    goToSupervise() {
        this.navCtrl.push(MySupervisePage);
    }

    //我的督办
    goToVerify() {
        this.navCtrl.push(MyVerifyPage);
    }

    //操作记录
    goToOperation() {
        this.navCtrl.push(OperationPage);
    }

    //设置
    goToSet() {
        this.navCtrl.push(SetPage);
    }

    //检测当前版本
    getVersion() {
        //检测是否需要更新
        this.appVersion.getVersionNumber().then((version: string) => {
            this.version = version;
        }).catch(err => {
            console.log(err);
        });
    }

    //检测版本
    checkVersion() {
        let versionCode;
        let platform;
        if (this.platform.is('ios')) platform = 'IOS';
        if (this.platform.is('android')) platform = 'android';
        this.appVersion.getVersionNumber().then((version: string) => {
            versionCode = version.split('.').join('');
            const data = {
                code: platform
            }
        }).catch(err => {
            console.log(err);
        });
    }

    logout() {
        this.storage.clear();
        this.events.publish('toLogin');
    }
}
