import { Component } from '@angular/core';
import {IonicPage, NavController, NavParams, ToastController} from 'ionic-angular';
import {Response} from "@angular/http";
import {AppService} from "../../../service/appHttpService";
import {message} from "../../../app/main";


@IonicPage()
@Component({
  selector: 'page-my-block',
  templateUrl: 'my-block.html',
})
export class MyBlockPage {
    ownerList;
    contactPersonInfo;
  constructor(public navCtrl: NavController, public navParams: NavParams,
              public appService:AppService,public toastCtrl: ToastController) {
  }

  ionViewDidLoad() {
      this.contactPersonInfo = this.navParams.get('item');
      console.log(this.contactPersonInfo);
    this.initOwnerList();
  }

    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;
                }, error => {
                    this.appService.alert('网络异常！');
                }
            );
    }

    addBlock(item){
      const toast = this.toastCtrl.create(message);
      const data = {
          // 'groupName':item.usergroupName,
          'telpBookPersonList':[{
              'telpbookId':item.id,
              'linkUserid':this.contactPersonInfo.id,
              'linkUsername':this.contactPersonInfo.name
          }]
      };
      this.appService.ObserverHttpPostData('/wisdomgroup/modules/telpBook',data)
          .subscribe((res)=>{
              console.log(res.json());
              if( res.json().apiResult.errcode == '0' ){
                  toast.setMessage('添加成功');
                  toast.present();
                  this.navCtrl.pop();
              }else{
                  toast.setMessage(res.json().apiResult.data);
                  toast.present();
              }
          })
    }
}
