<template>
    <el-dialog v-model="showDialog" title="设置间隔时间" width="20%" :before-close="handleClose">
        <el-form :model="formData" ref="formRef" :rules="rules">
            <el-form-item label="间隔时间" prop="cronExpression">
                <el-input v-model="formData.cronExpression" placeholder="请输入间隔时间" />
            </el-form-item>
        </el-form>
        <template #footer>
            <el-button @click="handleClose">取消</el-button>
            <el-button type="primary" @click="onConfirm">确定</el-button>
        </template>
    </el-dialog>
</template>

<script setup lang='ts'>
import { ref } from 'vue'

const showDialog = ref(false)
const formRef = ref()
const formData = ref({
    cronExpression: '',
    code: ''
})
const rules = ref({
    cronExpression: [{ required: true, message: "间隔时间不为空", trigger: "blur" }]
})

const emits = defineEmits(['cornData'])

const onConfirm = () => {
    formRef.value?.validate((valid: boolean) => {
        if (valid) {
            emits('cornData', formData.value)
            showDialog.value = false
        } else {
            console.log('检验失败');
        }
    })

}
const handleClose = () => {
    showDialog.value = false
}

defineExpose({
    showDialog,
    formData
})
</script>
 
<style lang = "scss" scoped>
</style>