<template>
  <div>
    <el-form :model="postponeForm" ref="postponeForm" :rules="postponeRules">
      <el-form-item label="开始日期" prop="pauseDate">
        <el-date-picker
          v-model.trim="postponeForm.pauseDate"
          type="date"
          :disabled="true"
          :picker-options="{
            firstDayOfWeek: 1,
          }"
          value-format="yyyy-MM-dd"
          placeholder="选择日期"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="顺延日期" prop="recoveryDate">
        <el-date-picker
          v-model.trim="postponeForm.recoveryDate"
          type="date"
          :picker-options="processDate()"
          value-format="yyyy-MM-dd"
          placeholder="选择日期"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="跳过节假日">
        <el-checkbox v-model.trim="postponeForm.holiday"></el-checkbox>
      </el-form-item>
      <span style="color: #f56c6c"
        >注意:课程顺延会将「开始日期」之后的全部未开始课程；<br />
        调整到「顺延日期」之后重新排课 支持将课程批量提前；</span
      >
    </el-form>

    <div class="buttonWrap">
      <el-button @click="gotoNext" type="primary">下一步</el-button>
          <el-button @click="()=>{$emit('cancaleMerge')}" >取 消</el-button>
    </div>
  </div>
</template>
<script>
export default {
  props: ["idList", "dataList"],
  data() {
    return {
      postponeForm: {
        pauseDate: "",
        recoveryDate: "",
        holiday: "",
      },
      postponeRules: {
        pauseDate: [
          { required: true, message: "请选择开始日期", trigger: "blur" },
        ],
        recoveryDate: [
          { required: true, message: "请选择顺延日期", trigger: "blur" },
        ],
      },
    };
  },
  mounted() {
    this.getFirstDate();
  },
  methods: {
    processDate() {
      //提出结束时间必须大于提出开始时间
      let that = this
      let dayjs = this.$helpers.dayjs
      return {
        firstDayOfWeek: 1,
        disabledDate(time) {
         let flag = dayjs(that.postponeForm.pauseDate).format('YYYY-MM-DD')==dayjs(time).format('YYYY-MM-DD')
          return (time.getTime() + 86400000 <= Date.now())||flag;
          //开始时间不选时，结束时间最大值小于等于当天
        },
      };
    },
    gotoNext() {
      this.$refs.postponeForm.validate((reset) => {
        if (reset) {
          let obj = {
            courseScheduleIds: this.idList,
            changeMainTeacher: false,
            changeTeachingTeacher: false,
            startDate: null,
            startTime: "",
            pauseDate:this.$helpers.dayjs(this.postponeForm.pauseDate).format('YYYY-MM-DD'),
            recoveryDate:this.postponeForm.recoveryDate,
            classGroupTeacherMapperList:null,
            teachMode: null,
            allowZeroSalary: false,
            schoolId: null,
            confirmGenerate: false,
            holiday: this.postponeForm.holiday,
          };
          this.$emit("submit", obj);
        }
      });
    },
    getFirstDate() {
      // this.postponeForm.pauseDate
      this.dataList.forEach((course, index) => {
        if (index == 0) {
          this.postponeForm.pauseDate = course.classDate;
        } else {
          let dayjs = this.$helpers.dayjs;
          dayjs(course.classDate).valueOf() -
            dayjs(this.postponeForm.pauseDate).valueOf() >
          0
            ? this.postponeForm.pauseDate
            : (this.postponeForm.pauseDate = course.classDate);
        }
      });
    },
  },
};
</script>
<style  lang="scss" scoped>
.buttonWrap {
  width: 100%;
  display: flex;
  flex-direction: row;
  justify-content: flex-end;
}
</style>
