<template>
    <el-dialog
        v-model="dialogFormVisible"
        title="申请联调"
        width="30%"
        :append-to-body="true"
        :before-close="close"
        :close-on-click-modal="false"
        :lazy="true"
        draggable
    >
        <!--监测点信息录入 基础信息+监测点信息  监测点信息要有工程名称、用户状态 -->
        <el-form
            :model="form"
            :validate-on-rule-change="false"
            :scroll-to-error="true"
            :rules="rules"
            ref="ruleFormRef"
            label-width="80px"
            label-position="right"
        >
            <el-form-item label="原因：" prop="reason">
                <el-input v-model="form.reason" autocomplete="off" placeholder="请输入原因" />
            </el-form-item>
        </el-form>
        <template #footer>
            <div class="dialog-footer">
                <el-button @click="close()">取消</el-button>
                <el-button type="primary" @click="confirmForm()">确定</el-button>
            </div>
        </template>
    </el-dialog>
</template>
<script lang="ts" setup>
import { ref, onMounted, reactive, defineExpose, defineProps, defineEmits, watch, onUnmounted } from 'vue'
import { useDictData } from '@/stores/dictData'
import { useAdminInfo } from '@/stores/adminInfo'
import { addMointorPointTempLinedebug } from '@/api/supervision-boot/jointDebugList/index'
const emits = defineEmits(['onSubmit'])
const props=defineProps({
    debugId:{
        type:String,
        default:''
    }
})
const dictData = useDictData()
const dialogFormVisible = ref(false)
const form: any = ref({})
const ruleFormRef = ref(null)
//定义切换form类型
const selectFormType = ref('')
selectFormType.value = '0'
const resetForm = () => {
    form.value = {
        reason: '', //填报人
    }
}
//初始化数据
resetForm()
//定义校验规则
const rules = ref({
    //基础信息
    reason: [
        {
            required: true,
            message: '请输入原因',
            trigger: 'blur'
        }
    ]
})
watch(
    () => form.value,
    (val, oldVal) => {},
    {
        deep: true,
        immediate: true
    }
)
const open = () => {
    dialogFormVisible.value = true
}
const close = () => {
    //重置表单内容
    //取消表单校验状态
    ruleFormRef.value && ruleFormRef.value.resetFields()
    dialogFormVisible.value = false
    emits('onSubmit')
    resetForm()
}
onMounted(() => {
    console.log()
})

//设置工程投产日期时间选择范围不能<今天
const disabledDate = time => {
    return time.getTime() < Date.now() - 8.64e7 // 8.64e7 毫秒数代表一天
}
//提交
const confirmForm = () => {
    // 提交监测点信息
    ruleFormRef.value.validate(valid => {
        if (valid) {
            //提交监测点联调信息
            form.value={
                ...form.value,
                id:props.debugId
            }
            addMointorPointTempLinedebug(form.value).then(res => {
                ruleFormRef.value.resetFields()
                resetForm()
                close()
            })
        } else {
            console.log('表单验证失败')
            return false
        }
    })
}
defineExpose({ open })
</script>

