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');
    this.initOwnerList();
  }

    initOwnerList(){
        const data = {
            pageSize:'100',
            pageNumber:'1'
        };
        this.appService.ObserverHttpGetData("/wisdomgroup/modules/telpBook",data)
            .subscribe((res: Response) => {
                    let data = res.json();
                    this.ownerList = data.data.list;
                }, error => {
                }
            );
    }

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