<template>
  <el-form ref="form" :model="model" :rules="rules" label-width="80px" label-position="right">
    <el-form-item prop="dateRange" label="时间">
      <mx-date-range-picker v-model="model.dateRange" emit-all-changes></mx-date-range-picker>
    </el-form-item>
    <div class="fx-row fx-wrap">
      <el-form-item prop="onlyRecommand" class="form-item-readonly">
        <el-checkbox v-model="model.onlyRecommand">仅允许学生选择推荐组合</el-checkbox>
      </el-form-item>
      <el-form-item prop="onlyAgree" class="form-item-readonly">
        <el-checkbox v-model="model.onlyAgree">只允许学生选择同意</el-checkbox>
      </el-form-item>
    </div>
    <div class="fx-row fx-wrap">
      <el-form-item prop="useRecommandWhileDisagree" class="form-item-readonly">
        <el-checkbox v-model="model.useRecommandWhileDisagree">如果拒绝，按推荐报名处理</el-checkbox>
      </el-form-item>
      <el-form-item prop="useRecommandWhileNonaction" class="form-item-readonly">
        <el-checkbox v-model="model.useRecommandWhileNonaction">如果不报名，按推荐报名处理</el-checkbox>
      </el-form-item>
    </div>
  </el-form>
</template>

<script>
import { getDefaultSelectRange } from '@/utils'

export default {
  name: 'elective-generation-push-setting',
  data() {
    return {
      model: {
        dateRange: getDefaultSelectRange(7),
        onlyRecommand: false, // 仅允许学生选择推荐组合, 否则允许学生填报有空缺的组合
        onlyAgree: false, // 调剂阶段，只允许学生选择同意, 否则允许学生拒绝
        useRecommandWhileDisagree: false, // 如果拒绝，按推荐报名处理
        useRecommandWhileNonaction: false // 如果不报名，按推荐报名处理
      },
      rules: {
        dateRange: [{
          message: '时间必填',
          validator: function(r, v, cb) {
            if (v.length === 2 && v.first() && v.last()) {
              cb()
              return
            }
            cb(r.message)
          }
        }]
      }
    }
  },
  methods: {
    async validate() {
      const res = await this.$refs.form.validate()
      // to standard model
      const commit = { ...this.model }
      commit.begin = commit.dateRange.first()
      commit.end = commit.dateRange.last()
      delete commit.dateRange
      return Promise.resolve(commit)
    }
  }
}
</script>

<style scoped>

</style>
