<template>
    <!--    弹窗 新增   -->
    <el-dialog
            title="新增友情链接"
            :visible.sync="addDialogVisit"
            width="30%"
            @close="handleResetLinks('addForm')"
            center>
        <div class="add-dialog-content">
            <el-form :model="addForm" :rules="addRules" ref="addForm" label-width="80px" class="demo-ruleForm">
                <el-form-item label="名称:" prop="name">
                    <el-input v-model="addForm.name"></el-input>
                </el-form-item>
                <el-form-item label="链接:" prop="url">
                    <el-input v-model="addForm.url"></el-input>
                </el-form-item>
            </el-form>
        </div>
        <span slot="footer" class="dialog-footer">
                <el-button size="mini" @click="addDialogVisit = false">取 消</el-button>
                <el-button size="mini" type="primary" @click="handleAddLinks('addForm')">确 定</el-button>
            </span>
    </el-dialog>
</template>

<script>
    export default {
        name: 'addYouQingLink',
        data() {
            return {
                addForm:           {
                    name: '',
                    url:  '',
                },
                addRules:          {
                    name: [
                        { required: true, message: '友情链接名称不能为空', trigger: 'blur' },
                    ],
                    url:  [
                        { required: true, message: '友情链接不能为空', trigger: 'blur' },
                    ],
                },
                addDialogVisit: false
            }
        },
        methods: {
            handleAddLinks(formName) {
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        this.addLinksFun();
                    } else {
                        return false;
                    }
                });
            },
            handleResetLinks(formName) {
                this.$refs[formName].resetFields();
                this.addDialogVisit = false;
            },
            addLinksFun() {
                this.$emit('add-Link', this.addForm);
            }
        }
    };
</script>

<style scoped>

</style>