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

import { Http,Response } from '@angular/http';
import { ActivityApplyPage } from '../activityApply/activityApply'
import { ActivityConfirmPage } from '../activityConfirm/activityConfirm';
import { AppService } from '../../../service/appHttpService';
import {ActivityDetailPage} from "../activityDetail/activityDetail";
@IonicPage()
@Component({
  selector: 'page-activityList',
  templateUrl: 'activityList.html',
})
export class ActivityListPage {

  items = [];


  activityType:Array<String> = ['未知','体检','疗休养','培训','工会活动'];
  activityFbObject:Array<String> = ['未知','全体人员','用户组','处事部门'];
  constructor(public navCtrl: NavController,
    public navParams: NavParams,
    public alertCtrl: AlertController,
    public http: Http,
    public appService: AppService) {
      
  } 


  //初始化显示活动列表
  ionViewDidEnter(): void {
    this.getActivityList();
    this.addRecodings();
  }

  getActivityList(){   
   

    this.appService.ObserverHttpPost("/wisdomgroup/modules/activity/findAllActivityForAppWithUsergroup",null)

    .subscribe((res: Response) => {
      let data = res.json();
      console.log("activityListData------->",data);    
        this.items =data;
      }, error => {        
          this.appService.alert('网络异常！');    
      }   
    );
  }

  //查看详情
  goDetail(item){
    console.log(item);
    let id = item.id;
    this.navCtrl.push("ActivityDetailPage",{id:id});
  }


  goApplyDetails(item){
    console.log(item);
      // if(item.activityState==2 && item.orderList.length>0){
          this.goDetail(item);
      // }else{
      //     this.goApply(item);
      // }
  }

  doRefresh(refresher) {
    console.log('Begin async operation', refresher);
    setTimeout(() => {
      this.getActivityList();
      console.log('Async operation has ended');
      refresher.complete();
    }, 2000);
  }

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

  //增加阅读记录
  addRecodings(){
    this.appService.ObserverHttpGet("/wisdomgroup/modules/activity/addRecodings", null)
    .subscribe((res: Response) => {
     
    }, error => {
      this.appService.alert('网络异常！');
    }
    );
  }

}
