import {Component} from '@angular/core';
import {IonicPage, NavController, NavParams} from 'ionic-angular';
import {DatePipe} from "@angular/common";
import {CommonService} from "../../../../provide/common.service";
import {LearnManageService} from "../learnManage.service";


@IonicPage()
@Component({
    selector: 'page-rank-list',
    templateUrl: 'rank-list.html',
})
export class RankListPage {

    testId;
    pageNumber = 1;
    pageSize = 1000;
    list = [];

    constructor(public navCtrl: NavController, public navParams: NavParams,public learnManSer:LearnManageService,
                public datePipe:DatePipe,public commonSer:CommonService) {
    }

    ionViewDidLoad() {
        this.testId = this.navParams.get('testId');
        const data = {
            testId:this.testId,
            pageNumber: this.pageNumber,
            pageSize: this.pageSize,
        };
        this.learnManSer.getRankList(data).subscribe(
            (res)=>{
                this.list = res.data.list;
            }
        )
    }

    // 下拉
    doRefresh(refresher) {
        this.commonSer.log("下拉")
        this.pageNumber = 1;
        const data = {
            testId:this.testId,
            pageNumber: this.pageNumber,
            pageSize: this.pageSize,
        };
        this.learnManSer.getRankList(data).subscribe(
            (res)=>{
                this.list = res.data.list;
                refresher.complete()
            }
        )

    }

    //上拉
    doInfinite(infiniteScroll) {
        this.commonSer.log("上拉")
        this.pageNumber++;
        const nowDate = this.datePipe.transform(new Date(), 'yyyy/MM/dd HH:hh:ss')
        const data = {
            pageNumber: this.pageNumber,
            pageSize: this.pageSize,
            selectType: '1',   //全部状态
            queryTime: nowDate,
        };
        this.learnManSer.getRankList(data).subscribe(
            (res)=>{
                this.list = res.data.list;
            }
        )
    }

}
