import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import {AppService} from "../../../service/appHttpService";
import {ChangeApplySurePage} from "../change-apply-sure/change-apply-sure";
import {CalendarComponentOptions, DayConfig} from "ion2-calendar";
import {monthCh, weekDay} from "../../../app/main";
import { DatePipe } from "@angular/common";

@IonicPage()
@Component({
  selector: 'page-select-change-person',
  templateUrl: 'select-change-person.html',
})
export class SelectChangePersonPage {

    //日历
    optionsMulti: CalendarComponentOptions;
    newArr: DayConfig[] = [];

    nowId;
    date;  //换班日期
    list = [];
    changeType = 0;
  constructor(public navCtrl: NavController, public navParams: NavParams,
              public appService: AppService,public datePipe: DatePipe) {
  }

  ionViewDidLoad() {
    this.nowId = this.navParams.get('nowId');
    const year = this.datePipe.transform( this.navParams.get('date'),'yyyy' );
    const month = this.datePipe.transform( this.navParams.get('date'),'MM' );
    this.getMonth(year,month);
  }

  //选择月份
    //月份改变
    monChange(e) {
        this.getMonth(e.newMonth.years, e.newMonth.months);
    }

  getMonth(year,month){
    const data = {
        date:year + '/' + month + '/01',
        type:this.changeType
    };
      this.appService.ObserverHttpGetOption('/wisdomgroup/schedule/getScheduleByMonthAndType',data)
          .subscribe((res)=>{
            let response = res.json();
            response.forEach(event=>{
                this.newArr.push({
                    date:new Date(event.dutyDate),
                    subTitle:event.name,
                })
            });
              this.optionsMulti = {
                  pickMode: 'multi',
                  monthFormat: 'YYYY 年 MM 月 ',
                  weekdays: weekDay,
                  monthPickerFormat: monthCh,
                  weekStart: 0,
                  disableWeeks: [0, 1, 2, 3, 4, 5, 6],
                  daysConfig: this.newArr
              };
      })
  }

  //换班
  select(item){
    this.navCtrl.push('ChangeApplySurePage',{
      'changeId':item.id,
        'nowId':this.nowId
    })
  }

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

}
