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

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

import { AppService } from '../../../service/appHttpService';
import { JoinDetailPage } from '../../activity-track/joinDetail/joinDetail';
import {BatchDetailPage} from "../batch-detail/batch-detail";

@IonicPage()
@Component({
  selector: 'page-activityDetail',
  templateUrl: 'activityDetail.html',
})
export class ActivityDetailPage {

  batches: object[];
  activity = {
      batchList:[]
  };
    batchList = [];
  //页面报名保存展示
  isCover: boolean = false;
  //活动详情显示
  introduce: string;



  constructor(public navCtrl: NavController,
    public navParams: NavParams,
    public alertCtrl: AlertController,
    public http: Http,
    public appService: AppService, public toast: ToastController) {
    let id = this.navParams.get('id');
    this.findMyOrderByOrderId(id);
  }

    findMyOrderByOrderId(id){

        let now = new Date().getTime();
        this.appService.ObserverHttpGet("/wisdomgroup/modules/activity/findAllActivityForAppWithXQ", {"id":id})
            .subscribe((res :Response) => {
                    this.activity = res.json();
                    this.batchList = this.activity.batchList;
                    for( let i = 0;i<this.batchList.length;i++ ){
                        let endDate = this.batchList[i].batchEndDate + " 24:00:00";
                        endDate = new Date(endDate).getTime() +'';     //判断是否过截止日期
                        if( now > Number(endDate) ){      //已截止
                            this.batchList[i].signUp = false;
                        }else{    //
                            this.batchList[i].signUp = true;
                        }
                        console.log(this.batchList);
                    }
                }, error => {
                    this.appService.alert('网络异常！');
                }
            );
    }


    goJoinDetail(){
        this.navCtrl.push("JoinDetailPage");
    }

    //批次详情
    goBatchDetail(item){
      console.log(this.activity);
      this.navCtrl.push('BatchDetailPage',{batch:item,activity:this.activity});
    }

    //活动介绍限定65个字符串，多余以省略号代替
    subIntroduce(str: string) {
      if (!str) this.introduce = '';
      if (str.length <= 65) this.introduce = str;
      if (str.length > 65) this.introduce = str.substr(0, 65) + "...";
    }
  
    //具体介绍
    hidden() {
      this.isCover = false;
    }
    show() {
      this.isCover = true;
    }

}
