<template>
  <div>
    <vxe-modal
      :value="isShow"
      show-footer
      title="年休假"
      show-confirm-button
      :width="defaultModalSize.width"
      :height="defaultModalSize.height"
      esc-closable
      transfer
      show-zoom
      resize
      @input="e => $emit('update:isShow',e)"
    >
      <el-form ref="elForm" :model="form" :rules="rules" label-position="top" label-width="100">
        <el-form-item label="年份" prop="year" required>
            <el-date-picker style="width: 100%;" type="year" v-model="form.year" size="small" value-format="yyyy" />
        </el-form-item>

        <el-form-item label="工作年限" prop="work_year" required>
          <el-input v-model="form.work_year" type="number"/>
        </el-form-item>
        <el-form-item label="应休假天数" prop="should_holiday_days" required>
          <el-input v-model="form.should_holiday_days" type="number"/>
        </el-form-item>
        <el-form-item label="计划安排开始时间" prop="plan_start_time" required>
          <el-date-picker style="width: 100%;" type="date" v-model="form.plan_start_time" size="small" value-format="yyyy-MM-dd" />
        </el-form-item>
        <el-form-item label="计划安排结束时间" prop="plan_end_time" required>
          <el-date-picker style="width: 100%;" type="date" v-model="form.plan_end_time" size="small" value-format="yyyy-MM-dd" />
        </el-form-item>
      </el-form>

      <template #footer>
        <el-button type="primary" :loading="loading" @click="submit">确认</el-button>
      </template>
    </vxe-modal>
  </div>
</template>

<script>
import { getToken } from '@/utils/auth'
import { save } from '@/api/yearHoliday'
import {defaultModalSize} from "@/settings";
export default {
  props: {
    departments: {
      type: Array,
      default: () => []
    },
    isShow: {
      type: Boolean,
      default: false,
      required: true
    }
  },
  data() {
    return {
      defaultModalSize,
      action: process.env.VUE_APP_UPLOAD_API,
      fileList: [],
      loading: false,
      form: {
        year: '',
        work_year: '',
        should_holiday_days: '',
        plan_start_time: '',
        plan_end_time: '',
      },
      rules: {
        year: [
          { required: true, message: '请输入年份' }
        ],
        work_year: [
          { required: true, message: '请输入工作年限' }
        ],
        should_holiday_days: [
          { required: true, message: '请输入应休假天数' }
        ],
        plan_start_time: [
          { required: true, message: '请输入计划安排开始时间' }
        ],
        plan_end_time: [
          { required: true, message: '请输入计划安排结束时间' }
        ]
      }
    }
  },
  computed: {},
  methods: {
    submit() {
      this.$refs['elForm'].validate(async valid => {
        if (valid) {
          this.loading = true
          try {
            await save(this.form)
            this.$message.success('新增成功')
            this.$emit('refresh')
            this.$emit('update:isShow', false)
            this.loading = false
            this.$refs['elForm'].resetFields()
          } catch (err) {
            this.loading = false
          }
        }
      })
    }
  }
}
</script>

<style scoped lang="scss">
::v-deep .el-form {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-gap: 10px 20px;
}
</style>
