import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import {AppService} from "../../../service/appHttpService";


@IonicPage()
@Component({
  selector: 'page-my-duty',
  templateUrl: 'my-duty.html',
})
export class MyDutyPage {

    changeType = 1;
    nowDuty = [];
    historyDuty = [];
  constructor(public navCtrl: NavController, public navParams: NavParams,
              public appService: AppService) {
  }

  ionViewDidLoad() {
    this.getDuty();
  }

    change(type){
        this.changeType = type;
    }

    getDuty(){
        const data = {
            type:0
        };
        this.appService.ObserverHttpGetOption('/wisdomgroup/schedule/app/getMySchedule',data)
            .subscribe((res)=>{
                this.nowDuty = res.json();
            });

        const data1 = {
            type:1
        };
        this.appService.ObserverHttpGetOption('/wisdomgroup/schedule/app/getMySchedule',data1)
            .subscribe((res)=>{
                this.historyDuty = res.json();
            });
    }

    //提交申请
    dutyApply(item){
      let nowTime = new Date().getTime();
      if(nowTime > item.dutyDate){
          this.appService.popToastView('该条值班已过期','middle',1500);
          return false;
      }

        this.navCtrl.push('DutyApplyPage',{
            id:item.id,
            date:item.dutyDate
        })
    }

    //申请详情
    dutyDetail(item){
        this.navCtrl.push('DutyDetailPage',{
            "id":item.applyId,
            'time':item.dutyDate
        })
    }

}
