<template>
    <div class="modify-form">
        <el-form label-position="right" :class="class" :label-width="width ? width + 'px' : ''" :model="param"
            ref="modifyForm" :rules="rules">
            <slot></slot>
            <el-form-item class="form-btns">
                <el-button type="primary" @click="formConfirm">确定</el-button>
                <el-button type="info" @click="emit('cancel')">取消</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>

<script lang="ts" setup>
import { onMounted, ref, watch } from "vue";
import { FormInstance } from "element-plus";

const prop = defineProps({
    width: {
        type: Number,
        default: 80,
    },
    param: {
        type: Object,
        default: {},
    },
    rules: {
        type: Object,
        default: {},
    },
    class: {
        type: String,
        default: '',
    },
});
const emit = defineEmits(["confirm", "cancel"]);
const modifyForm = ref<FormInstance>();

const formConfirm = () => {
    if (!modifyForm.value) return;
    modifyForm.value?.validate((valid, fields) => {
        if (valid) {
            emit("confirm");
            modifyForm.value?.clearValidate();
        }
    });
};

const clearValidate = () => {
    modifyForm.value?.clearValidate();
}

watch(() => prop.param, () => {
    modifyForm.value?.clearValidate();
});

onMounted(() => {
});
</script>
<style lang="scss" scoped>
//@import url(); 引入公共css类
::v-deep .el-select {
    width: 100%;
}

::v-deep .el-date-editor {
    width: 100% !important;
}

::v-deep .el-autocomplete {
    width: 100%;
}
</style>