<template>
    <el-form :model="form" :rules="rules" ref="form" label-width="100px">
        <el-form-item label="按钮名称：" prop="ModuleName">
            <el-input v-model="form.ModuleName" placeholder="请输入按钮名称"></el-input>
        </el-form-item>
        <el-form-item label="跳转链接：" prop="LinkUrl">
            <el-input v-model="form.LinkUrl" placeholder="请输入跳转链接"></el-input>
        </el-form-item>
        <el-form-item label="打开方式：" prop="LinkType">
            <el-radio-group v-model.number="form.LinkType">
                <el-radio :label="1">新窗口打开</el-radio>
                <el-radio :label="2">当前页面跳转</el-radio>
            </el-radio-group>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" :loading="confirmLoading" @click="handleConfrim">确 定</el-button>
        </el-form-item>
    </el-form>
</template>

<script>
export default {
    name: 'AppLink',
    data () {
        return {
            form: {
                ModuleType: 2,
                ModuleId: '',
                ModuleName: '',
                LinkUrl: '',
                LinkType: ''
            },
            rules: {
                ModuleName: [
                    { required: true, message: '请输入按钮名称', trigger: 'blur' }
                ],
                LinkUrl: [
                    { required: true, message: '请输入跳转链接', trigger: 'blur' }
                ],
                LinkType: [{
                    required: true, message: '请选择打开方式', trigger: 'change'
                }]
            },
            confirmLoading: false
        }
    },
    methods: {
        handleConfrim () {
            this.$refs.form.validate((valid) => {
                if (valid) {
                    this.confirmLoading = true
                    this.$api.commonApi.createPlatFormCustomModule({
                        ...this.form
                    }).then(res => {
                        this.$handleResponse(res).then(() => {
                            this.$refs.form.resetFields()
                            this.$emit('confirm')
                        })
                    }).finally(() => {
                        this.confirmLoading = false
                    })
                } else {
                    console.log('error submit!!')
                    return false
                }
            })
        }
    }
}
</script>

<style lang="stylus" scoped></style>
