
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 '../../contact/contactList/contactList';
import {AddBlockPage} from "../../contact/add-block/add-block";

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

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

  }

  //ionViewWillEnter
  ionViewDidEnter():void{
    //加载组织列表：initOrganizeList
    this.initOrganizeList();
    this.initOwnerList();
  }
  initOrganizeList():void{
      //this.appService.ObserverHttpGet("/wisdomgroup/app/getAllOrganization",null)
      //隐藏显示
      this.appService.ObserverHttpGetData("/wisdomgroup/sysmanagement/org/getAllOrganization",{order:0})
      .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('网络异常！');  
        }   
      );
  }

    initOwnerList(){
      const data = {
          pageSize:'10',
          pageNumber:'1'
      };
        this.appService.ObserverHttpGetData("/wisdomgroup/modules/telpBook",data)
            .subscribe((res: Response) => {
                    let data = res.json();
                    this.ownerList = data.data.list;
                    console.log(this.ownerList);
                }, error => {
                    this.appService.alert('网络异常！');
                }
            );
    }

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

    //跳转至部门下联系人列表页面
    usualContactBlockPersons(organization){
        this.navCtrl.push("ContactListPage",{"orgid":organization.id,"orgName":organization.usergroupName});
    }
  //跳转至常用联系人列表
  usualContactPersons(){
    this.navCtrl.push("ContactListPage");
  }

  //添加分组
  usualContactAdd(){
      this.navCtrl.push('AddBlockPage');
  }

    deleteItem(item){

    }

}
