<template>
  <Dialog v-model="visible" title="设置节假日" width="400px">
    <el-form v-loading="formLoading"  :model="form" label-width="120px">
      <el-form-item label="日期">
        <el-date-picker
          v-model="form.theDay"
          type="date"
          value-format="YYYY-MM-DD"
          placeholder="选择日期"
        />
      </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 { updateHoliday } from '@/api/calendar/index'
import { ElMessage } from 'element-plus'
import {DICT_TYPE, getStrDictOptions} from '@/utils/dict'

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

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

defineExpose({ open })

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