<template>
  <Dialog v-model="visible" title="批量设置节假日" width="500px" >
    <el-form v-loading="formLoading"  :model="form" label-width="120px">
      <el-form-item label="开始日期">
        <el-date-picker
          v-model="form.startDay"
          type="date"
          value-format="YYYY-MM-DD"
          placeholder="开始日期"
        />
      </el-form-item>
      <el-form-item label="结束日期">
        <el-date-picker
          v-model="form.endDay"
          type="date"
          value-format="YYYY-MM-DD"
          placeholder="结束日期"
        />
      </el-form-item>
      <el-form-item label="单位">
        <el-select v-model="form.unit" placeholder="选择单位">
          <el-option
            v-for="dict in getIntDictOptions(DICT_TYPE.HOLIDAY_UNIT)"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="值">
        <el-input v-model="form.value" placeholder="如 周一 或 15" />
      </el-form-item>
      <el-form-item label="类型">
        <el-select v-model="form.holidayType" placeholder="选择类型">
          <el-option
            v-for="dict in getStrDictOptions(DICT_TYPE.HOLIDAY_TYPE)"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
    </el-form>
    <template #footer>
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="submit" :disabled="formLoading">确定</el-button>
    </template>
  </Dialog>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { updateHolidayList } from '@/api/calendar/index'
import { ElMessage } from 'element-plus'
import { getStrDictOptions, DICT_TYPE,getIntDictOptions } from '@/utils/dict'

// 弹框
const formLoading = ref(false) // 表单的加载中
const visible = ref(false)
const form = ref({
  startDay: '',
  endDay: '',
  unit: '',
  value: '',
  holidayType: '',
})

// 打开
const open = () => {
  visible.value = true
}

defineExpose({ open })

const emit = defineEmits(['success'])
const submit = async () => {
  // 提交请求
  formLoading.value = true
  await updateHolidayList(form.value)
  ElMessage.success('批量节假日设置成功')
  formLoading.value = false
  visible.value = false
  emit('success')
}
</script>
