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


@IonicPage()
@Component({
  selector: 'page-review-learn',
  templateUrl: 'review-learn.html',
})
export class ReviewLearnPage {
    @ViewChild(Slides) slides: Slides;

    list = [
        {title:"你最喜欢玩的游戏是什么？",quesType:'1',option:[{ans:"苹果",index:1},{ans:"香蕉",index:2},{ans:"梨",index:3},]},   //单选题
        {title:"你最喜欢吃的水果是什么",quesType:'2',option:[{ans:"苹果",index:1},{ans:"香蕉",index:2},{ans:"梨",index:3},]},  //多选题
        {title:"你最喜欢玩的地方是什么？",quesType:'3'},  //判断题
        {title:"你最喜欢什么手机？",quesType:'4'},  //填空题
        {title:"你最喜欢什么耳机？",quesType:'5'}   //问答题
    ];
    index = 1;  //当前题目的序号
    constructor(public navCtrl: NavController, public navParams: NavParams,
                public toastCtrl:ToastController,public appService:AppService) {
    }

    ionViewDidLoad() {
        console.log('ionViewDidLoad LearningDoPage');
    }

    //上一题
    prev(){
        if(this.index == 1){
            const toast = this.toastCtrl.create(message);
            toast.setMessage('已经是第一题哦');
            toast.present();
        }else{
            this.index -= 1;
            this.slides.slideTo(this.index-1)
        }
    }

    //下一题
    next(){
        if(this.index == this.list.length){
            const toast = this.toastCtrl.create(message);
            toast.setMessage('已经是最后一题了哦');
            toast.present();
        }else{
            this.index += 1;
            this.slides.slideTo(this.index-1)
        }
    }

    //只看错题
    submit(){
        this.appService.alert("确定提交问卷",()=>{
            this.navCtrl.push("LearningResultPage")
        })
    }

}
