Skip to content
my-collection.ts 2.69 KiB
Newer Older
import {Component, ViewChild} from '@angular/core';
import {InfiniteScrollContent, IonicPage, NavController, NavParams} from 'ionic-angular';
import {MineService} from "../mine.service";
import {AppGlobal} from "../../../service/http.service";
wangqinghua's avatar
wangqinghua committed
import {StuffDetailPage} from "../../home-pages/stuff-detail/stuff-detail";
import {CommonService} from "../../../provide/common.service";

@IonicPage()
@Component({
wangqinghua's avatar
wangqinghua committed
    selector: 'page-my-collection',
    templateUrl: 'my-collection.html',
})
export class MyCollectionPage {
@ViewChild(InfiniteScrollContent) infiniteScrollContent:InfiniteScrollContent;
wangqinghua's avatar
wangqinghua committed
    pageNum = 1;
wangqinghua's avatar
wangqinghua committed
    collectionList = [];
    picture: string = AppGlobal.domain + '/wisdomgroup';
    isLoad = true;

    loadMore = true;
    totalNum;  //总条数
wangqinghua's avatar
wangqinghua committed
    constructor(public navCtrl: NavController, public navParams: NavParams,
                public mineSer: MineService,public commonSer:CommonService) {
wangqinghua's avatar
wangqinghua committed
    }
wangqinghua's avatar
wangqinghua committed
    ionViewDidEnter() {
        this.getList();
    }
wangqinghua's avatar
wangqinghua committed
    getList() {
        const data = {
            pageNum: this.pageNum,
            pageCount: this.pageCount
        };
        this.mineSer.myCollection(data).subscribe(
            (res) => {
                this.collectionList = res.data.list;
                this.isLoad = false;
                this.totalNum = res.data.total;
            }
        )
    }

    //下拉刷新
    doRefresh(e){
        this.loadMore = true;
        this.infiniteScrollContent.inf.enable(true);
        const data = {
            pageNum: 1,
            pageCount: this.pageCount
        };
        this.mineSer.myCollection(data).subscribe(
            (res) => {
                this.collectionList = res.data.list;
                this.totalNum = res.data.total;
                setTimeout(()=>{
wangqinghua's avatar
wangqinghua committed
                    this.commonSer.toast('刷新成功');
                    e.complete()
                },800);
            }
        )
    }

    //加载更多
    doInfinite(e){
        if(this.totalNum == this.collectionList.length ){
            this.loadMore = false;
            e.enable(false);
            return false;
        }
        this.pageNum ++;
        const data = {
            pageNum: this.pageNum,
            pageCount: this.pageCount
        };
        this.mineSer.myCollection(data).subscribe(
            (res) => {
                this.totalNum = res.data.total;
                res.data.list.forEach(e=>{
                    this.collectionList.push(e);
                });
                setTimeout(()=>{
                    e.complete()
                },800);
wangqinghua's avatar
wangqinghua committed
            }
        )
    }

    //查看文章详情
    goToDetail(item) {
        this.navCtrl.push(StuffDetailPage, {
            id: item.id
        })
    }