<template>
    <div>
        <slot></slot>
        <div class="option" :class="[value.length && value[0].type, { length: value.length }]">
            <div class="item-box" v-for="(n, i) in value" :key="i">
                <div class="option-item">
                    <img :src="getFileUrl(n.img)" @click.stop="$refs.previewer.show(i)">
                    <div class="name">{{ n.value }}</div>
                </div>
            </div>
        </div>
        <div v-transfer-dom>
            <previewer :list="previewerList" ref="previewer"></previewer>
        </div>
    </div>
</template>

<script>
import { TransferDom, Previewer } from 'vux'
import { getFileUrl } from '@/assets/utils/host.js'
export default {
    directives: { TransferDom },
    components: { Previewer },
    props: {
        value: { type: Array, default: () => [] }
    },
    data () {
        return {
            getFileUrl,
            previewerList: this.value.map(item => ({ src: getFileUrl(item.img) }))
        }
    }
}
</script>

<style lang="less" scoped>
.option {
    display: flex;
    flex-wrap: wrap;
    word-break: break-all;
    line-height: 16px;
    &.column {
        flex-direction: column;
    }
}
.option-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;
    }
}
.row {
    &.length {
        margin: 0 -5px -5px;
    }
    .item-box {
        width: 50%;
        padding: 5px;
    }
    .option-item {
        flex-direction: column;
        position: relative;
        padding: 80px 5px 0;
    }
    img {
        width: 100%;
        height: 80px;
        position: absolute;
        top: 0;
        left: 0;
    }
    .name {
        padding: 5px;
    }
}
.column {
    .item-box {
        margin-top: 5px;
    }
    .option-item {
        padding: 5px 10px;
        align-items: center;
    }
    .name {
        margin-left: 10px;
    }
    img {
        width: 32px;
        height: 32px;
    }
    .name {
        display: flex;
        flex-direction: column;
        justify-content: center;
    }
}
</style>
