<template>
    <div class="c_box">
        <!-- <div class="mask"></div> -->
        <!-- <div v-if="!cJson">暂未设置题目</div> -->
        <!-- <div v-if="!cJson">暂未设置题目</div> -->
        <div class="set_box" v-if="!cJson">请设置题目</div>
        <div v-else class="choice_box">
            <div class="title" style="display: flex;align-items: center;">
                <!-- + `（${option[checkJson.type].name}）` -->
                <span class="g_t_index" style="min-width: fit-content;">{{ tindex + 1 }}</span>
                <span>{{ checkJson.title }}</span>
                <!-- {{ tindex + 1 + "、" + `（${option[checkJson.type].name}）` + checkJson.title }} -->
                <span style="min-width: fit-content;" v-if="checkJson.type == 2">{{ `（${option[checkJson.type].name}）` }}</span>
                <span style="color: #efa030;min-width: fit-content;" v-if="checkJson.score">（{{ '分值：' + checkJson.score + '分' }}）</span></div>
            <div class="choices">
                <div class="choice" v-for="(item, index) in checkJson.array" :key="index">
                    <div class="choice_c" v-if="checkJson.type == 2"  @click="check(checkJson.type, index)"><el-checkbox v-model="checkJson.answer2" :label="index"
                            :disabled="checktype == 2"></el-checkbox><span
                            :class="{ right: see && cJson.answer.indexOf(index) != -1 }"
                           >{{ item.option }}</span></div>
                    <div class="choice_c" v-if="checkJson.type == 1"  @click="check(checkJson.type, index)"><el-radio v-model="checkJson.answer2[0]" :label="index"
                            :disabled="checktype == 2"></el-radio><span
                            :class="{ right: see && cJson.answer.indexOf(index) != -1 }"
                           >{{ item.option }}</span></div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
export default {
    props: {
        tindex:{
            type: Number
        },
        cJson: {
            type: Object,
        },
        checktype: {
            type: Number,
            default: 1
        },
        see: {
            type: Boolean,
            default: false
        }
    },
    data() {
        return {
            option: {
                1: { name: '单选题' },
                2: { name: '多选题' }
            },
            checkJson: undefined
        }
    },
    watch: {
        checkJson: {
            handler(newValue) {
                this.$emit('update:cJson', newValue)
            },
            deep: true
        }
    },
    methods: {
        depthCopy(s) {
            return JSON.parse(JSON.stringify(s));
        },
        check(type, index) {
            if (this.checktype == 2) {
                return;
            }
            if (type == 2) {
                if (this.checkJson.answer2.indexOf(index) == -1) {
                    this.checkJson.answer2.push(index)
                } else {
                    this.checkJson.answer2.splice(this.checkJson.answer2.indexOf(index), 1)
                }
            } else if (type == 1) {
                this.checkJson.answer2[0] = index
            }
            this.$forceUpdate()
        }
    },
    mounted() {
        this.checkJson = this.cJson ? this.depthCopy(this.cJson) : undefined
    }
}
</script>

<style scoped>
.c_box {
    width: 100%;
    position: relative;
		padding-left: 45px;
}

/* @import '../../global_styles.css'; */




.choice_box>.choices {
    margin-top: 10px;
    padding: 0 10px;
}

.choice_box>.choices>.choice {
    word-break: break-all;
}

.choice_box>.choices>.choice+.choice {
    margin-top: 5px;
}

.choice_box>.choices>.choice>.choice_c {
    display: flex;
}

.choice_box>.choices>.choice>.choice_c>span {
    /* margin-left: 10px; */
    cursor: pointer;
}

.choice_box>.choices>.choice>.choice_c>.el-checkbox {
    margin-top: 4px;
    margin-right: 10px;
}

.choice_box>.choices>.choice>.choice_c>.el-radio {
    margin-top: 4px;
    margin-right: 10px;
}

.choice_c>>>.el-checkbox__label {
    display: none;
}

.choice_c>>>.el-radio__label {
    display: none;
}

.choice_c .right {
    color: #efa030;
}

.choice_c .right::after {
    content: '（正确答案）';
}

.choice_box>.choices>.choice>>>.el-checkbox__input.is-disabled.is-checked .el-checkbox__inner::after {
    border-color: #fff !important;
}

.choice_box>.choices>.choice>>>.el-checkbox__input.is-disabled.is-checked .el-checkbox__inner {
    background-color: #409EFF !important;
    border-color: #409EFF !important;
}

.choice_box>.choices>.choice>>>.el-radio__input.is-disabled.is-checked .el-radio__inner {
    background-color: #409EFF !important;
    border-color: #409EFF !important;
}

.choice_box>.choices>.choice>>>.el-radio__input.is-disabled.is-checked .el-radio__inner::after {
    background-color: #fff !important;
}

.g_t_index{
	color: #3681FC;
	font-size: 28px;
	font-weight: bold;
	position: relative;
	margin-right: 30px;
	margin-left: -40px;
}

.g_t_index+span{
	font-weight: bold;
	font-size: 18px;
}

.g_t_index::after{
	content: "";
	width: 18px;
	height: 2px;
	position: absolute;
	right: -18px;
	top: 50%;
	transform: translateY(-50%);
	background: #3681FC;
}

.g_t_index::before{
	content: "";
	width: 6px;
	height: 6px;
	border-right: 2px solid #3681FC;
	border-top: 2px solid #3681FC;
	position: absolute;
	right: -15px;
	top: 50%;
	transform: rotate(45deg) translateY(-5px);
}

.choice_c{
	width: calc(100% - 45px);
	height: auto;
	padding: 12px 10px;
	background-color: #F3F7FD;
	border: solid 1px #3681FC;
	border-radius: 30px;
	display: flex;
	align-items: center;
	cursor: pointer;
	margin-bottom: 10px;
}
</style>