import {formatYMD} from '@/common/filters/custom.js';

export default {
  data() {
    return {
      // dateKey: 0,
      dateDefault: [],
      pickerOptions() {
        // let pickerMinDate;
        return {
          onPick(obj) {
            // pickerMinDate = obj.minDate;
          },
          disabledDate(time) {
            let start = new Date();
            start.setFullYear(start.getFullYear() - 1);
            start.setDate(start.getDate() + 1);
            start = new Date(`${start.getFullYear()}-${start.getMonth() + 1}-${start.getDate()}`);
            let end = new Date();
            end = new Date(`${end.getFullYear()}-${end.getMonth() + 1}-${end.getDate()} 23:59:59`);
            return time.getTime() < start.getTime() || time.getTime() > end;
          }
        };
      }
    };
  },
  methods: {
    setDefalutTime(){
      let start = new Date();
      start.setFullYear(start.getFullYear() - 1);
      start.setDate(start.getDate()+1);
      start = `${start.getFullYear()}-${start.getMonth() + 1}-${start.getDate()}`;
      let end = new Date();
      end = `${end.getFullYear()}-${end.getMonth() + 1}-${end.getDate()}`;
      this.dateDefault = [formatYMD(new Date(start).getTime()), formatYMD(new Date(end).getTime())]
    },
  },
  filters: {
    formatDate(val, format) {
      if(!val) return '--';
      val = new Date(val);
      let y = val.getFullYear();
      let m = (val.getMonth() + 1).toString().padStart(2, '0');
      let d = val.getDate().toString().padStart(2, '0');
      let h = val.getHours().toString().padStart(2, '0');
      let mm = val.getMinutes().toString().padStart(2, '0');
      let s = val.getSeconds().toString().padStart(2, '0');
      if(format == 'ymd') {
        return `${y}-${m}-${d}`;
      } else if(format == 'hms') {
        return `${h}:${mm}:${s}`;
      }
      return `${y}-${m}-${d}\xa0\xa0\xa0${h}:${mm}:${s}`;
    }
  },
};