<template>
    <SysDialog class="addedit-schedulesetting" :visible="dialog.visible" v-bind="getBindValue" @onClose="onclose"
        @onConfirm="confirm">
        <template #content>
            <el-form ref="addEditScheduleSettingRef" :model="addEditScheduleSettingForm" inline
                :rules="addEditScheduleSettingFormRules" label-width="80px">
                <el-row>
                    <el-col :span="12">
                        <el-form-item prop="beanName" label="实例名称">
                            <el-input
                                v-model="addEditScheduleSettingForm.beanName"
                                placeholder="实例名称"
                                clearable
                            />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item prop="methodName" label="方法名称">
                            <el-input
                                v-model="addEditScheduleSettingForm.methodName"
                                placeholder="方法名称"
                                clearable
                            />
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="参数名称">
                            <el-input
                                v-model="addEditScheduleSettingForm.methodParams"
                                placeholder="参数名称"
                                clearable
                            />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item prop="cycleType" label="周期类型">
                            <BaseSelect v-model:modelValue="addEditScheduleSettingForm.cycleType" :filterable="false"
                                :options="cycleTypecist" placeholder="周期类型" />
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
        </template>
    </SysDialog>
</template>
<script lang="ts" setup>
import { reactive } from 'vue';
import SysDialog from "@/components/SysDialog.vue";
import useDialog from "@/hooks/useDialog";
import { useEleFormValidate } from '@/hooks/useEleFormValidate';
import { useErrorConfirm } from '@/utils/useErrorConfirm';
import { ListIitem } from '@/api/base/BaseDataModel';
import BaseSelect from '@/components/QuerySelect/BaseSelect.vue';
import { useAddEditScheduleSetting } from '@/composables/scheduleSetting/useAddEditScheduleSetting';

const { report } = useErrorConfirm()
//弹框属性
const { dialog, onClose, onShow } = useDialog();
// 弹框一些配置
const getBindValue = reactive({
    title: "设置",
    width: 575,
    height: 0
});
defineProps<{
    cycleTypecist: ListIitem[],
}>()
const emit = defineEmits(['saveScheduleSetting'])
// 校验表单
const { formValidate, resetForm } = useEleFormValidate();

const {
    addEditScheduleSettingForm,
    addEditScheduleSettingFormRules,
    dealData,
    addEditScheduleSettingRef,
    onclose,
    show
} = useAddEditScheduleSetting(onClose, onShow, resetForm, getBindValue)

// 确定
const confirm = async () => {
    const isValidate = await formValidate(addEditScheduleSettingRef.value)
    if (!isValidate) return
    try {
        // console.log(addEditScheduleSettingForm, ":<==任务");
        emit("saveScheduleSetting", addEditScheduleSettingForm, dealData.type, onclose)
    } catch (error) {
        report(error)
    }
}

//父组件调用子组件显示弹框
//暴露出去给外部使用
defineExpose({
    show
});
</script>