import {Component} from '@angular/core';
import {NavController, NavParams, ViewController} from 'ionic-angular';
import {AppService} from "../../../../service/appHttpService";

@Component({
    selector: 'page-block-modal',
    templateUrl: 'block-modal.html',
})
export class BlockModalPage {

    blockList = [];
    block;
    applyCount;

    constructor(public navCtrl: NavController, public navParams: NavParams,
                public viewCtrl: ViewController,public appService:AppService) {
    }

    ionViewDidLoad() {
        this.blockList = this.navParams.get('blockList');
        this.applyCount = this.navParams.get('applyCount');
        this.blockList.forEach(res=>{
            res.check = false;
        })
    }

    dismiss() {

        let selectBatch = [];
        this.blockList.forEach(res=>{
            if(res.check == true){
               selectBatch.push(res);
            }
        });
        if(this.applyCount > 0){
            if(selectBatch.length > this.applyCount){
                this.appService.popToastView('超过报名批次','middle',1500);
                return false;
            }
        }
        this.viewCtrl.dismiss(selectBatch);
    }

    cancel(){
        this.viewCtrl.dismiss();
    }

}
