import {Component, ViewChild} from '@angular/core';
import {IonicPage, NavController, NavParams, Slides} from 'ionic-angular';

import {Response} from '@angular/http';

import {AppService} from '../../../service/appHttpService';
import {OutGoingReportEditPage} from '../../report/outGoingReportEdit/outGoingReportEdit';

import {ActivityStatisticService} from '../../../service/activityStatisticService';

import {OutGoingReportViewPage} from '../../report/outGoingReportView/outGoingReportView';

import {Storage} from '@ionic/storage';
import {MinePage} from "../../tabs/mine/mine";

declare var Swiper;

@IonicPage()
@Component({
    selector: 'page-myReport',
    templateUrl: 'myReport.html',
})


export class MyReportPage {

    swiperIndex = 0;
    swiper: any;
    allReport = [];
    processingReport: Array<any> = [];
    endReport: Array<any> = [];

    //ViewChild传入一个字符串contentSlides，变量contentSlides接收。其它不变
    @ViewChild('contentSlides') contentSlides: Slides;
    menus: Array<string> = ['全部报备', '报备中', '已结束'];

    constructor(public navCtrl: NavController,
                public appService: AppService,
                public activityStatisticService: ActivityStatisticService,
                public storage: Storage) {

        console.log(this.navCtrl);
    }

    //初始化加载我的报备
    ngOnInit(): void {
        this.getAllMyReport();
    }

    //当页面加载的时候触发，只触发一次，当有缓存的的时候，打开页面时不在加载
    ionViewDidLoad() {

    }

    //选择菜单
    selectPageMenu(index) {
        this.swiperIndex = index;
        //切换页面
        // this.contentSlides.slideTo(index);
    }

    //获取所有我的报备
    getAllMyReport() {
        this.appService.ObserverHttpPost("/wisdomgroup/modules/premanager/getPremanagerByUser", null)
            .subscribe((res: Response) => {
                    let data = res.json();
                    this.allReport = data;

                    this.allReport.forEach(element => {
                        if (!element["isOverTimeFlag"]) { //报备中
                            this.processingReport.push(element);
                        } else {
                            this.endReport.push(element);  //已结束
                        }
                    });
                }, error => {
                }
            );
    }

    //跳转到报备页面
    goReport(report) {
        if (report.isOverTimeFlag) {
            return false;
        }
        this.storage.set("premanager", report);
        this.navCtrl.push("OutGoingReportEditPage");
    }

    //跳转到报备查看详情页面
    goDetail(report) {
        this.navCtrl.push("OutGoingReportViewPage", {premanager: report});
    }

    goBack() {
        this.navCtrl.popToRoot();
    }

}
