import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { AppService } from '../../service/appHttpService';
import { AppVersion } from '@ionic-native/app-version';
import { AppUpdateService } from '../../service/appUpdateService';

@IonicPage()
@Component({
  selector: 'page-version',
  templateUrl: 'version.html'
})

export class VersionPage {
  version: string = '';
  latestVersion: string = '';
  isLatest:boolean = true;

  constructor(
    public navCtrl: NavController, 
    public navParams: NavParams,
    public appService:AppService,
    private appUpdateService: AppUpdateService,
    private appVersion: AppVersion
  ) {
    
  }

  ionViewWillEnter() {
    this.getversion();
  }

   //获取最新版本信息
   getversion() {
    //检测是否需要更新
    this.appVersion.getVersionNumber().then((version: string) => {
      this.version = version;
      this.appUpdateService.compariVersion().subscribe(res => {
        var data = res.json();
        if (data.code == 200) {
          this.latestVersion = data.latestVersion;
          if (data.latestVersion != null && data.latestVersion != version) {
            this.isLatest = false;
          }
        }
      });
    }).catch(err => {
      console.log('getVersionNumber:' + err);
    });
  }

  //更新
  update(){
    this.appUpdateService.downloadApp("/wisdomgroup/app/download");
  }

    loginOut(){

    }

}
