<template>
    <!-- 协议管理 新增、编辑 表单组件 -->
    <div>
        <el-form
            label-width="100px"
            size="medium"
            ref="protocolParamsRef"
            :model="protocolParams"
            :rules="protocolParamsRules"
        >
            <el-row type="flex" justify="space-between" :gutter="24">
                <el-col :span="12">
                    <el-form-item label="租赁单位" prop="scrapNum">
                        <el-input v-model="protocolParams.scrapNum" />
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="授权人" prop="pro_unit">
                        <el-input v-model="protocolParams.pro_unit" />
                    </el-form-item>
                </el-col>
            </el-row>

            <el-row :gutter="24">
                <el-col :span="12">
                    <el-form-item label="租赁工程" prop="pro_type_of">
                        <el-select
                            v-model="protocolParams.pro_type_of"
                        ></el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="联系电话" prop="pro_type">
                        <el-select
                            v-model="protocolParams.pro_type"
                        ></el-select>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row :gutter="24">
                <el-col :span="12">
                    <el-form-item label="合同编号" prop="pro_type">
                        <el-select
                            v-model="protocolParams.pro_type"
                        ></el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="租赁期限" prop="pro_nature">
                        <el-select
                            v-model="protocolParams.pro_nature"
                        ></el-select>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row :gutter="24">
                <el-col :span="12">
                    <el-form-item label="开始日期" prop="pro_user">
                        <el-input v-model="protocolParams.pro_user" />
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="备注" prop="pro_phone">
                        <el-input v-model="protocolParams.pro_phone" />
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row :gutter="24">
                <el-col :span="12">
                    <el-form-item label="合同附件">
                        <el-input />
                    </el-form-item>
                </el-col>
                <el-col :span="12"> </el-col>
            </el-row>

            <el-form-item>
                <el-button type="success" @click="onSubmit">确认</el-button>
                <el-button
                    @click="
                        () => {
                            this.$emit('closeDialog')
                        }
                    "
                    >取消</el-button
                >
            </el-form-item>
        </el-form>
    </div>
</template>

<script>
export default {
    name: 'FormProtocol',
    props: {
        editParams: {
            type: Object,
            default: () => null,
        },
    },
    mounted() {
        if (this.editParams) {
            Object.assign(this.protocolParams, this.editParams)
        }
    },
    data() {
        return {
            protocolParams: {
                scrapNum: '',
                pro_code: '',
                pro_unit: '',
                pro_type_of: '',
                pro_type: '',
                pro_nature: '',
                pro_user: '',
                pro_phone: '',
            },
            // 校验规则
            protocolParamsRules: {
                scrapNum: [
                    {
                        required: true,
                        message: '请选择租赁单位',
                        trigger: 'blur',
                    },
                ],
                pro_unit: [
                    {
                        required: true,
                        message: '请输入授权人',
                        trigger: 'blur',
                    },
                ],
                pro_type_of: [
                    {
                        required: true,
                        message: '请选择租赁工程',
                        trigger: 'blur',
                    },
                ],
                pro_type: [
                    {
                        required: true,
                        message: '请输入联系电话',
                        trigger: 'blur',
                    },
                ],
            },
        }
    },
    methods: {
        /** 确认按钮 */
        onSubmit() {
            this.$refs.protocolParamsRef.validate((valid) => {
                if (valid) {
                    console.log('校验通过')
                    // 1. 表单校验通过后调后台 Api
                    // 2. 成功之后通知父组件关闭弹框
                    this.$emit('closeDialog')
                }
            })
        },
    },
}
</script>

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