<template>
    <div class="option">
        <div class="header">
            <div class="title" v-if="title" :style="{ fontSize: titleSize + 'px' }">
                <span>|</span>
                <span>{{ title }}</span>
            </div>
            <slot name="optionRight">
                <div v-if="rightButton">
                    <el-button :type="rightButton?rightButton.type:''" size="mini" round :icon="rightButton.icon ? rightButton.icon : 'el-icon-arrow-left'" @click="back">{{ rightButton.title ? rightButton.title : '返回'}}</el-button>
                </div>
            </slot>
        </div>
        <slot></slot>
    </div>
</template>

<script>
export default {
    name: 'FormOption',
    props: {
        title: {
            type: String,
            require: true
        },
        titleSize: {
            type: Number,
            default: 15
        },
        rightButton: {
            type: Object,
            default: null
        }
    },
    methods: {
        back() {
            if (this.rightButton) {
                if (this.rightButton.event) {
                    this.$emit(this.rightButton.event);
                }
                else if (this.rightButton.needClose) {
                    window.close();
                }
                else {
                    this.$router.back()
                }
            }
            else {
                this.$router.back()
            }
        }
    }
}
</script>

<style lang="scss" scoped>
@import '@/styles/variables.scss';

.option {
    padding: 16px 16px 10px;
    background-color: #FFFFFF;
    border-radius: 10px;
    .header {
        display: flex;
        align-items: center;
        justify-content: space-between;
    }
    .title {
        color: #000000;
        margin-bottom: 15px;
        &>span:first-child {
            color: $blueColor;
            font-weight: bolder;
            margin-right: 8px;
        }
    }
}
</style>
