import {Component, ViewChild} from '@angular/core';
import {IonicPage, LoadingController, NavController, NavParams} from 'ionic-angular';
import {LearnService} from "./learn.service";
import {HomeService} from "../home/home.service";
import {Storage} from "@ionic/storage";
import {ScrollTabsComponent} from "../../components/scroll-tabs/scroll-tabs";
import {timer} from "rxjs/observable/timer";


@IonicPage()
@Component({
    selector: 'page-learning',
    templateUrl: 'learning.html',
})
export class LearningPage {
    @ViewChild('scrollTabs') scrollTabs: ScrollTabsComponent;

    code = "Subject";
    tabsList = [];
    productList = [];
    headList = [];
    headType;
    page = {
        SubjectID: '',
        page: 1,
        pageSize: "10",
        TotalCount: 0,
        isLoading:false,
    };
    loading;

    constructor(public navCtrl: NavController, public navParams: NavParams, private loadCtrl: LoadingController,
                private learnSer: LearnService, private homeSer: HomeService, private storage: Storage) {
    }

    ionViewDidLoad() {
        this.storage.get('course').then((value => {
            if (value) {   //其他路径转入
                this.page.SubjectID = value.item.ID;
                this.headType = value.headType;
            } else {  //tab栏进入
                this.headType = 'all';
            }
        }))
    }

    doRefresh(e) {
        this.page.page = 1;
        timer(1000).subscribe((res) => {
            e.complete();
        });
    }

    ionViewWillLeave() {
        // this.productList = [];
        this.storage.set('course', null);
    }

}
