import {Component} from '@angular/core';
import {IonicPage, NavController, NavParams, ModalController, App, ToastController} from 'ionic-angular';
import {SelectBlockPage} from "../select-block/select-block";
import {Response} from "@angular/http";
import {AppService} from "../../../service/appHttpService";

@IonicPage()
@Component({
    selector: 'page-add-block',
    templateUrl: 'add-block.html',
})
export class AddBlockPage {

    groupName;

    constructor(public navCtrl: NavController, public navParams: NavParams,
                public modalCtrl: ModalController, public appService: AppService,
                public toastCtrl: ToastController) {
    }

    ionViewDidLoad() {
    }

    goSelectmodal() {
        this.navCtrl.push('SelectBlockPage');
    }

    //创建分组
    done() {
        if (!this.groupName) {
            this.appService.popToastView('请填写分组名称', 'middle', 1500);
            return;
        }
        const data = {
            groupName: this.groupName
        };
        this.appService.ObserverHttpPostData("/wisdomgroup/modules/telpBook/", data)
            .subscribe((res: Response) => {
                    let data = res.json();
                    this.appService.popToastView('创建成功!', 'middle', 1500);
                    this.navCtrl.pop();
                }, error => {
                }
            );
    }

    cancel() {
        this.navCtrl.pop();
    }
}
