import {Component} from '@angular/core';
import {IonicPage, NavController, ToastController} from 'ionic-angular';

import {ModifyPasswordPage} from "../../modifyPassword/modifyPassword";
import {Storage} from '@ionic/storage';
import {AppGlobal, AppService} from "../../../service/appHttpService";
import {EditPersonInfoPage} from '../editPersonInfo/editPersonInfo';

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

export class PersonInfoPage {
    orgName = '';
    user: any;
    gender: object;
    //userInfo: object ;
    userid: '';
    picture: string = AppGlobal.picture;

    constructor(public navCtrl: NavController,
                public storage: Storage,
                public appService: AppService,
                public toast: ToastController) {

    }

    //ionViewDidLoad():void{
    ionViewWillEnter(): void {
        this.user = this.storage.get("user").then((value) => {
            this.user = value;
            console.log(this.user);
            console.log("id1:" + this.user.id);
            this.gender = this.user.userDetail.user.gender;
            console.log("gender:" + this.gender);
            this.getOrgName(this.user.id, result => {
                let data = result;
                this.orgName = data["orgName"];
            });
        });
    }

    modifyPwd() {
        this.navCtrl.push("ModifyPasswordPage")
    }

    getOrgName(id, callback?): any {
        this.appService.ObserverHttpPost("/wisdomgroup/app/getOrgName", {"userid": id})
            .toPromise()
            .then(res => {
                var data = res.json();
                callback(data == null ? "[]" : data);
            })
            .catch(error => {
            });
    }

    //不同的code代表修改不同的数据，1房间，2座机，3邮箱
    edit(code) {
        this.navCtrl.push("EditPersonInfoPage", {code: code});
    }

    goBack() {
        this.navCtrl.popToRoot();
    }

}
