<template>
    <form-option :title="title" :style="kvStyle" :rightButton="rightButton">
        <div class="table">
            <div class="item" v-for="(item, index) in arr" :key="index">
                <el-row>
                    <span v-for="(data, j) in item" :key="2*index+j">
                        <el-col :span="3">
                            <div class="label" :class="data.first?'margin-row':''">
                                {{ data.label }}
                            </div>
                        </el-col>
                        <el-col :span="data.row?21:9">
                            <div class="value" :class="data.first?'margin-row':''">
                                <slot name="slotValue" :row="data">
                                    {{ data.value }}
                                </slot>
                            </div>
                        </el-col>
                    </span>
                </el-row>
            </div>
            <div v-show="enforce_result" class="imgdiv">
                <img v-if="enforce_result === 'PASS'" src="../assets/pass.png">
                <img v-else src="../assets/nopass.png">
            </div>
        </div>
    </form-option>
</template>

<script>
    import FormOption from './FormOption.vue'

    export default {
        props: ['title', 'list', 'kvStyle', 'rightButton','enforce_result'],
        components: {
            FormOption
        },
        computed: {
            arr() {
                return this.changeArr()
            }
        },
        methods: {
            changeArr() {
                const res = []
                if (this.list && this.list.length > 0) {
                    this.list.map((item, index) => {
                        if(item.length){
                            res[index]=item
                        }else {
                            const num = item.row ? 1 : 2
                            const loc = Math.floor(index / num)
                            if (!res[loc]) {
                                res[loc] = []
                            }
                            res[loc].push(item)
                        }
                    })
                }
                return res
            }
        }
    }
</script>

<style lang="scss" scoped>
    .table {
        padding: 15px 20px;
    }
    .item {
        display: flex;
        align-items: center;
        margin-top: -1px;
        .label {
            background-color: #F7F8FA;
            border: 1px solid #E6E6E6;
            padding: 10px;
            text-align: right;
        }
        .label:nth-child(1) {
            margin-left: -1px;
        }
        .value {
            border: 1px solid #E6E6E6;
            padding: 10px;
            text-align: left;
            margin-left: -1px;
        }
        .margin-row {
            margin-top: 1px;
        }
    }
    .el-row {
        width: 100% !important;
    }
    .imgdiv{
        width: 130px;
        height: 130px;
        position:relative;
        left: 70%;
        bottom: 145px;
        opacity:0.5;
        border-radius:50%;
        img{
            width: 130px;
            height: 130px;
        }
    }
</style>