
import { Component } from '@angular/core';
import {  NavController, NavParams, ToastController } from 'ionic-angular';
import { Response } from '@angular/http';
import { Storage } from '@ionic/storage';
import { AppService } from '../../../service/appHttpService';

import { SearchPage } from '../../search/search';
import { ContactListPage } from '../../contactList/contactList';

@Component({
  selector: 'page-contact',
  templateUrl: 'contact.html'
})
export class ContactPage {
  
  //组织部门列表
  organizations: Array<string> = [];

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

  }

  //ionViewWillEnter
  ngOnInit():void{
    //加载组织列表：initOrganizeList
    this.initOrganizeList();
  }
  initOrganizeList():void{
      //this.appService.ObserverHttpGet("/wisdomgroup/app/getAllOrganization",null)
      //隐藏显示
      this.appService.ObserverHttpGet("/wisdomgroup/sysmanagement/org/getAllOrganization",null)
      .subscribe((res: Response) => {
          let data = res.json();
          console.log("data:"+data);
          this.organizations = data;

          //移除父节点
          for (let index = 0; index < this.organizations.length; index++) {
            const element = this.organizations[index];
            if(element["organizationLevel"] == '1' ) {
              var flag = index;
            }                
          }
          this.organizations.splice(flag,1);  
        }, error => {        
          this.appService.alert('网络异常！');  
        }   
      );
  }

  search(){
    this.navCtrl.push("SearchPage");
  }
  //跳转至部门下联系人列表页面
  usualContactOrgPersons(organization){
    console.log("organization:"+JSON.stringify(organization));
    this.navCtrl.push("ContactListPage",{"orgid":organization.id,"orgName":organization.name});
  }
  //跳转至常用联系人列表
  usualContactPersons(){
    this.navCtrl.push("ContactListPage");
  }


}
