<template>
    <!-- 往来单位 新增、编辑 表单组件 -->
    <div>
        <el-form
            label-width="100px"
            size="medium"
            ref="contactUnitsParamsRef"
            :model="contactUnitsParams"
            :rules="contactUnitsParamsRules"
        >
            <el-form-item label="单位名称" prop="scrapNum">
                <el-input v-model="contactUnitsParams.scrapNum" />
            </el-form-item>
            <el-form-item label="单位类型" prop="pro_type_of">
                <el-select v-model="contactUnitsParams.pro_type_of"></el-select>
            </el-form-item>
            <el-form-item label="所属分公司" prop="pro_unit">
                <el-select v-model="contactUnitsParams.pro_unit"></el-select>
            </el-form-item>
            <el-form-item label="联系人" prop="pro_user">
                <el-input v-model="contactUnitsParams.pro_user" />
            </el-form-item>
            <el-form-item label="联系电话" prop="pro_phone">
                <el-input v-model="contactUnitsParams.pro_phone" />
            </el-form-item>
            <el-form-item label="启用状态" prop="pro_type">
                <el-switch
                    active-text="启用"
                    inactive-text="禁用"
                    v-model="contactUnitsParams.pro_type"
                ></el-switch>
            </el-form-item>
            <el-form-item>
                <el-button @click="onSubmit">确定</el-button>
                <el-button
                    @click="
                        () => {
                            this.$emit('closeDialog')
                        }
                    "
                    >取消</el-button
                >
            </el-form-item>
        </el-form>
    </div>
</template>

<script>
export default {
    name: 'FormContactUnits',
    props: {
        editParams: {
            type: Object,
            default: () => null,
        },
    },
    mounted() {
        if (this.editParams) {
            Object.assign(this.contactUnitsParams, this.editParams)
        }
    },
    data() {
        return {
            contactUnitsParams: {
                scrapNum: '',
                pro_code: '',
                pro_unit: '',
                pro_type_of: '',
                pro_type: '',
                pro_nature: '',
                pro_user: '',
                pro_phone: '',
            },
            // 校验规则
            contactUnitsParamsRules: {
                pro_name: [
                    {
                        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',
                    },
                ],
                pro_nature: [
                    {
                        required: true,
                        message: '请选择工程性质',
                        trigger: 'blur',
                    },
                ],
            },
        }
    },
    methods: {
        /** 确认按钮 */
        onSubmit() {
            this.$refs.contactUnitsParamsRef.validate((valid) => {
                if (valid) {
                    console.log('校验通过')
                    // 1. 表单校验通过后调后台 Api
                    // 2. 成功之后通知父组件关闭弹框
                    this.$emit('closeDialog')
                }
            })
        },
    },
}
</script>

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