import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import {CalendarComponentOptions} from "ion2-calendar";
import {AppService} from "../../../service/appHttpService";
import {DutyApplyPage} from "../duty-apply/duty-apply";
import {DutyDetailPage} from "../duty-detail/duty-detail";
import {DutySignUpPage} from "../duty-sign-up/duty-sign-up";

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

    menuList = [
        {name:'值班安排'},
        {name:'我的值班'},
    ]
    swiperIndex;
    optionsMulti: CalendarComponentOptions = {
        pickMode: 'multi',
        monthFormat: 'YYYY 年 MM 月 ',
        weekdays: ['天', '一', '二', '三', '四', '五', '六'],
        weekStart: 1,
    };
    changeType = 1;
    dayObj;
    nightObj;
    nowDuty;
    historyDuty;
  constructor(public navCtrl: NavController, public navParams: NavParams,
              public appService: AppService) {
  }

  ionViewDidLoad() {
      const date = new Date().toLocaleDateString();
      this.getDuty(date);
      this.myDuty();

    this.selectPageMenu(0);
    this.getSchedule()
  }

    selectPageMenu(index) {

        this.swiperIndex = index;
        //切换页面
        // this.contentSlides.slideTo(index);
    }

    getSchedule(){

    }

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

    onChange(e){
        const date = new Date(e.time).toLocaleDateString();
        this.getDuty(date);
        console.log(date);
    }

    getDuty(date){
        //0 白班  1 夜班
        const data = {
            date:date,
            type:0
        };
        this.appService.ObserverHttpGetOption('/wisdomgroup/schedule/getScheduleInfo',data)
            .subscribe((res)=>{
                this.dayObj = res;
            });

        const data1 = {
            date:date,
            type:1
        };
        this.appService.ObserverHttpGetOption('/wisdomgroup/schedule/getScheduleInfo',data1)
            .subscribe((res)=>{
                this.nightObj = res;
            });
    }


    //我的值班
    myDuty(){
        const data = {
            type:0
        };
        this.appService.ObserverHttpGetOption('/wisdomgroup/schedule/app/getMySchedule',data)
            .subscribe((res)=>{
               this.nowDuty = res.json();
                console.log(this.nowDuty);

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

    //提交申请
    dutyApply(item){
      this.navCtrl.push('DutyApplyPage',{
          date:item.dutyDate
      })
    }

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

    //值班签到
    sigUp(){
        this.navCtrl.push('DutySignUpPage');
    }

}
