import {Component} from '@angular/core';
import {IonicPage, NavController, NavParams} from 'ionic-angular';
import {NewsService} from "./news.service";
import * as Mock from "mockjs";
import {DealPage} from "../deal/deal";
import {DoSupervisePage} from "../home/do-supervise/do-supervise";
import {DealDetailPage} from "../deal/deal-detail/deal-detail";

@IonicPage()
@Component({
    selector: 'page-news',
    templateUrl: 'news.html',
})
export class NewsPage {
    type = "1";
    newList = [];
    dqtxList = [];
    rgtxList = [];

    dbPage = {
        page: 1,
        limit: 10
    };
    total = 0;

    constructor(public navCtrl: NavController, public navParams: NavParams,
                private newSer: NewsService) {
    }

    ionViewDidEnter() {
        this.getList();
        const data = {
            page: 1,
            limit: 1000
        }
        this.newSer.dqtxList(this.dbPage).subscribe(
            (res) => {
                this.dqtxList = res.dqtxList;
                this.total = res.pageable.totalSize;
            }
        )
        this.newSer.rgtxList(data).subscribe(
            (res) => {
                this.rgtxList = res.dqtxList;
            }
        )
    }

    getList() {
        const data = {
            page: 1,
            limit: 1000
        };
        this.newSer.noticeSearch(data).subscribe(
            (res) => {
                res.page.list.notice.forEach(e => {
                    e.title = e.type == "1" ? "督办提醒" : "待办提醒";
                });
                this.newList = res.page.list.notice;
            }
        )
    }


    goDetail(item) {
        const data = {
            id: item.scheduleid,
            type: item.unittype == 1 ? "1" : "2",
        };
        this.navCtrl.push(DealDetailPage, {"item": data});
    }

    switchType() {

    }

    doInfinite(event) {
        if (this.total == this.dqtxList.length) {
            event.enable(false);
            return false;
        }
        this.dbPage.page++;
        this.newSer.dqtxList(this.dbPage).subscribe(
            (res) => {
                if (event) event.complete();
                this.dqtxList = this.dqtxList.concat(res.dqtxList);
                this.total = res.pageable.totalSize;
            }
        )
    }

}
