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 { ActivityStatisticService } from '../../service/activityStatisticService';

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

  items:object[];

  users:object[];

  isNoSignFlag:boolean = false;

  acitivityid:string;
  //待出行
  waitgoOrder:number;
  //待确认
  waitSureOrder:number;
  //未出行
  notgoOrder:number;
  //已出行
  hasgoOrder:number;
  //未报名
  notSign:number;

  constructor(public navCtrl: NavController,
    public navParams: NavParams,
    public alertCtrl: AlertController,
    public http: Http,
    public appService: AppService, 
    public toast: ToastController,
    public activityStatisticService: ActivityStatisticService) {
      
  }
  ionViewDidLoad(){
    /** 订单状态   （1.待出行(已报名)、2.待确认（已报名未确认）、3.报名未出行、4.已完成  （3，4均为确认状态））*/
    this.acitivityid = this.navParams.get("id"); //活动id
    //初始化加载未报备
    this.items = [];
    //this.role = this.navParams.get("role");
   
      this.activityStatisticService.activityOrderCount(this.acitivityid,(data) => {
        this.waitgoOrder = data["waitgoOrder"];
        this.waitSureOrder = data["waitSureOrder"];
        this.notgoOrder = data["notgoOrder"];
        this.hasgoOrder = data["hasgoOrder"];
      });
  
      this.appService.ObserverHttpPost("/wisdomgroup/modules/activity/notSignActivityList",{activityid:this.acitivityid})
      .subscribe((res: Response) => {
          let resultback = res.json(); 
          this.items = resultback; 
          this.notSign = this.items.length;
        }, error => {        
            this.appService.alert('网络异常！');    
        }   
      ); 

  }


  conmon(state_value){
    
    this.isNoSignFlag = true;
    this.items = [];
      this.appService.ObserverHttpPost("/wisdomgroup/modules/order/orderWaitGoWithActivityid",{id:this.acitivityid,state:state_value})
      .subscribe((res: Response) => {
          let resultback = res.json(); 
          this.items = resultback; 
        }, error => {        
            this.appService.alert('网络异常！');    
        }   
      );
   
  }

  //报名待出行
  hasSign(){ 
    
    this.conmon(1);
  }

  //待确认
  waitSure(){
   
    this.conmon(2);
  }

   //已确认未出行
  notgo(){
   
    this.conmon(3);
  }

  //已确认出行
  hasgo(){ 
    
    this.conmon(4);
  }

  //未报名
  noSign(){
    this.items = [];
    this.isNoSignFlag = false;
    this.appService.ObserverHttpPost("/wisdomgroup/modules/activity/notSignActivityList",{activityid:this.acitivityid})
    .subscribe((res: Response) => {
        let resultback = res.json(); 
        this.items = resultback; 
      }, error => {        
          this.appService.alert('网络异常！');    
      }   
    ); 
  }




}
