<template>
    <div>
        <template v-if="item.option">
            <div class="option" :class="[item.option.type, { length: item.option.list.length }]">
                <div class="item-box" v-for="(n, i) in item.option.list" :key="i">
                    <div class="item">
                        <template v-if="item.option.type === 'row'">
                            <img :src="getFileUrl(n.img)">
                            <el-radio :value="item.option.checked" :label="n.value" v-if="radio">{{ n.name }}</el-radio>
                            <el-checkbox :value="item.option.checked" :label="n.value" v-if="checkbox">{{ n.name }}</el-checkbox>
                            <div class="describe" v-if="n.describe">{{ n.describe }}</div>
                        </template>
                        <template v-else>
                            <el-radio :value="item.option.checked" :label="n.value" v-if="radio"></el-radio>
                            <el-checkbox :value="item.option.checked" :label="n.value" v-if="checkbox"></el-checkbox>
                            <img :src="getFileUrl(n.img)">
                            <div class="text">
                                <div>{{ n.name }}</div>
                                <div class="describe" v-if="n.describe">{{ n.describe }}</div>
                            </div>
                        </template>
                    </div>
                </div>
                <div class="tips" v-if="!item.option.list.length">请在右侧上传图片添加选项</div>
            </div>
        </template>
    </div>
</template>

<script>
import { getFileUrl } from '@/assets/utils/host.js'
export default {
    props: {
        item: { type: Object, default: () => ({}) },
        radio: { type: Boolean, default: false },
        checkbox: { type: Boolean, default: false }
    },
    data () {
        return {
            getFileUrl
        }
    }
}
</script>

<style lang="less" scoped>
.option {
    display: flex;
    flex-wrap: wrap;
    word-break: break-all;
    line-height: 16px;
    &.column {
        flex-direction: column;
    }
    .tips {
        color: #909399;
        margin-top: 5px;
    }
}
.item {
    display: flex;
    background-color: #fff;
    border: 1px solid #DCDFE6;
    img {
        vertical-align: top;
        object-fit: contain;
        background-color: #f5f5f5;
    }
    .el-radio, .el-checkbox {
        margin-right: 0;
        white-space: normal;
    }
    .describe {
        font-size: 14px;
        color: #909399;
        white-space: pre-wrap;
    }
}
.row {
    &.length {
        margin: -5px;
    }
    .item-box {
        width: 25%;
        padding: 5px;
    }
    .item {
        flex-direction: column;
        position: relative;
        padding: 90px 10px 10px;
    }
    img {
        width: 100%;
        height: 80px;
        position: absolute;
        top: 0;
        left: 0;
    }
    .text {
        padding: 5px;
    }
    .describe {
        margin-top: 5px;
    }
}
.column {
    .item-box + .item-box {
        margin-top: 5px;
    }
    .item {
        padding: 5px 10px;
        align-items: center;
    }
    .el-radio, .el-checkbox {
        /deep/ .el-radio__label, /deep/  .el-checkbox__label {
            display: none;
        }
    }
    img, .text {
        margin-left: 10px;
    }
    img {
        width: 32px;
        height: 32px;
    }
    .text {
        display: flex;
        flex-direction: column;
        justify-content: center;
    }
}
</style>
