import {Component} from '@angular/core';
import {IonicPage, LoadingController, NavController, NavParams} from 'ionic-angular';
import {AppService} from "../../../../service/appHttpService";
import {Storage} from "@ionic/storage";
import {Response} from "@angular/http";

@IonicPage()
@Component({
    selector: 'page-survery',
    templateUrl: 'survery.html',
})
export class SurveryPage {

    userId;
    list = [];
    loading;

    constructor(public navCtrl: NavController, public navParams: NavParams,
                public appService: AppService, public storage: Storage,
                public loadingCtrl: LoadingController) {
    }

    ionViewDidLoad() {
        this.loading = this.loadingCtrl.create({
            content: '请稍等...',
            // dismissOnPageChange: true,
            enableBackdropDismiss: true
        });
        this.loading.present();
        this.getList();
        this.addRecodings();
    }

    ionViewDidEnter() {
        this.getList();
    }


    //增加阅读记录
    addRecodings() {
        this.appService.ObserverHttpGet("/wisdomgroup/modules/question/addRecodings", null)
            .subscribe((res: Response) => {

                }, error => {
                }
            );
    }

    getList() {
        this.storage.get("user").then((res) => {
            this.appService.ObserverHttpGetAdd('/wisdomgroup/modules/question/findQuesByUserId/', res.id)
                .subscribe((res) => {
                    if (this.loading) {
                        this.loading.dismiss();
                    }
                    this.list = res.json().datalist;
                })
        });
    }


    //填写问卷
    geToWrite(item) {
        this.navCtrl.push('SurveyWritePage', {item: item});
    }

    //查看问卷结果
    goToResult(item) {
        this.navCtrl.push('SurveyPreviewPage', {item: item});
    }

}
