Skip to content
myReport.ts 4.73 KiB
Newer Older
wangqinghua's avatar
wangqinghua committed
import { Component, ViewChild } from '@angular/core';
import { IonicPage, NavController, NavParams, Slides } from 'ionic-angular';

wangqinghua's avatar
wangqinghua committed
import {  Response } from '@angular/http';
wangqinghua's avatar
wangqinghua committed

wangqinghua's avatar
wangqinghua committed
import { AppService } from '../../service/appHttpService';
wangqinghua's avatar
wangqinghua committed
import { OutGoingReportEditPage } from '../report/outGoingReportEdit/outGoingReportEdit';
wangqinghua's avatar
wangqinghua committed

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

wangqinghua's avatar
wangqinghua committed
import { OutGoingReportViewPage } from '../report/outGoingReportView/outGoingReportView';
wangqinghua's avatar
wangqinghua committed

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

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


export class MyReportPage {

wangqinghua's avatar
wangqinghua committed
    swiperIndex = 0;
wangqinghua's avatar
wangqinghua committed
  swiper: any;
  allReport: Array<any> = [];
  processingReport: Array<any> = [];
  endReport: Array<any> = [];

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

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

wangqinghua's avatar
wangqinghua committed
     console.log(this.navCtrl);
wangqinghua's avatar
wangqinghua committed
  }

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

  //当页面加载的时候触发,只触发一次,当有缓存的的时候,打开页面时不在加载  
  ionViewDidLoad() {
wangqinghua's avatar
wangqinghua committed

wangqinghua's avatar
wangqinghua committed
  }
  //初始化swiper  
  initSwiper() {
    this.swiper = new Swiper('.pageMenuSlides .swiper-container', {
      //设置slider容器能够同时显示的slides数量(  
      slidesPreView: 3,
      //slide之间的距离(单位px)  
      spaceBetween: 0,
      //断点设定:根据屏幕宽度设置某参数为不同的值  
      breakpoints: {
        1024: {
          slidesPerView: 3,
          spaceBetween: 0
        },
        768: {
          slidesPerView: 3,
          spaceBetween: 0
        },
        640: {
          slidesPerView: 3,
          spaceBetween: 0
        },
        320: {
          slidesPerView: 3,
          spaceBetween: 0
        }
      }
    });
  }
  //选择菜单  
  selectPageMenu(index) {
wangqinghua's avatar
wangqinghua committed
      this.swiperIndex = index;
wangqinghua's avatar
wangqinghua committed
    //切换页面  
wangqinghua's avatar
wangqinghua committed
    // this.contentSlides.slideTo(index);
wangqinghua's avatar
wangqinghua committed
  }
  //选择菜单之后设置菜单样式  
  setStyle(index) {
    //得到菜单的个数  
    var slides = document.getElementsByClassName('pageMenuSlides')[0].getElementsByClassName('swiper-slide');
    //给所有的菜单都设置上swiper-slide样式  
    if (index < slides.length) {
      for (var i = 0; i < slides.length; i++) {
        var s = slides[i];
        s.className = "swiper-slide";
      }
      //给当前菜单设置成这个样式  
      slides[index].className = "swiper-slide bottomLine";
    }
  }

  slideChanged() {
    //getActiveIndex()获得当前页面的index  
    let index = this.contentSlides.getActiveIndex();
    this.setStyle(index);
    //s切换菜单  
    this.swiper.slideTo(index, 300);

  }

  //获取所有我已结束的报备
  // getAllMyEndReport() {
  //   this.appService.ObserverHttpPost("/wisdomgroup/modules/premanager/getEndPremanagerByUser", null)
  //     .subscribe((res: Response) => {
  //       let data = res.json();
  //       this.endReport = data;
  //     }, error => {
  //       this.appService.alert('网络异常!');
  //     }
  //     );
  // }

  //获取所有我进行中的报备
  // getAllMyProcessingReport() {
  //   this.appService.ObserverHttpPost("/wisdomgroup/modules/premanager/getProcessingPremanagerByUser", null)
  //     .subscribe((res: Response) => {
  //       let data = res.json();
  //       this.processingReport = data;
  //     }, error => {
  //       this.appService.alert('网络异常!');
  //     }
  //     );
  // }

  //获取所有我的报备
  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 => {
            this.appService.alert('网络异常!');
        }
    );
  }

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

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

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

}