<template>
    <div class="c_box">
        <!-- <div class="mask"></div> -->
        <!-- <div v-if="!cJson">暂未设置题目</div> -->
        <div class="set_box" v-if="!cJson">填写者回答区</div>
        <div v-else class="choice_box">
            <!-- <div class="title"><div>{{ `（${option[checkJson.type].name}）` }}</div><div v-html="checkJson.title"></div></div> -->
            <div class="title">
                <div  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>
                    <span style="min-width: fit-content;color: #efa030;">{{ checkJson.score ? '（分值：'+checkJson.score+'分）' : '' }}</span>
                </div>
                <span style="color: #efa030;display: flex;margin-top: 5px;line-height: 18px;">
                    <span style="min-width: fit-content;" v-if="!checkJson.answer && see">暂无参考答案</span>
                    <span style="min-width: fit-content;display: flex;" v-else-if="see">
                        <span style="min-width: fit-content;">参考答案：</span> 
                        <span>{{ checkJson.answer }}</span>
                    </span> 
                    <!-- <span style="min-width: fit-content;margin-left: 10px;">{{ checkJson.score ? '分值：'+checkJson.score+'分' : '' }}</span> -->
                </span>
                
                <!-- <span v-if="see" style="color: #efa030; display: flex;">
                    
                    {{ checkJson.answer ? '参考答案：'+checkJson.answer : '暂无参考答案' }} <span style="min-width: fit-content;">{{ cJson.score ? '分值：'+cJson.score+'分' : '' }}</span>
                </span>
                <span style="color: #efa030;" v-if="checkJson.score && !see">（{{ '分值：'+checkJson.score+'分' }}）</span> -->
                <!-- </div><div v-html="checkJson.title"></div> -->
            </div>
            <div class="choices">
                <textarea :readonly="checktype == 2" rows="2" v-autoHeight="80" class="binfo_input binfo_textarea" cols v-model="checkJson.answer2"
                    placeholder="请输入内容"></textarea>
            </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: '问答题' },
            },
            checkJson: undefined
        }
    },
    watch: {
        checkJson: {
            handler(newValue) {
                this.$emit('update:cJson', newValue)
            },
            deep: true
        },
    },
    directives: {
        autoHeight: {
            update(el, binding) {
                const { value } = binding
                if (value && typeof value === 'number') {
                    el.style.height = `${value}px`
                } else {
                    el.style.height = 'auto'
                }
            },
            componentUpdated(el) {
                el.style.height = `${el.scrollHeight + 5}px`
            },
        },
    },
    methods: {
        depthCopy(s) {
            return JSON.parse(JSON.stringify(s));
        },
    },
    mounted() {
        this.checkJson = this.cJson ? this.depthCopy(this.cJson) : undefined
        if(this.checkJson && this.checkJson.answer2){
            setTimeout(() => {
                this.checkJson.answer2 += "*0*%*";
                setTimeout(() => {
                    this.checkJson.answer2 = this.checkJson.answer2.replaceAll("*0*%*", "");
                }, 0);
            }, 100);
        }
    }
}
</script>

<style scoped>

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

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

.binfo_input {
    width: 100%;
    margin: 0;
    padding: 12px 14px;
    display: block;
    min-width: 0;
    outline: none;
    box-sizing: border-box;
    background: none;
    border: none;
    border-radius: 4px;
    background: #fff;
    font-size: 16px;
    resize: none;
    font-family: 'Microsoft YaHei';
    min-height: 48px;
    /* border: 1px solid #3682fc00; */
    border: 1.5px solid #CAD1DC;
}

.binfo_textarea {
    border: 1.5px solid #CAD1DC;
    font-size: 16px;
    resize: none;
    /* background: #f6f6f6; */
    font-family: 'Microsoft YaHei';
}

.binfo_input:focus-visible {
    border: 1.5px solid #3681FC !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);
}

.choices>textarea{
	border-color: #E7E7E7;
	border-radius: 8px;
}
</style>