<template>
    <div class="stuff position-relative">
        <h3 class="weight-normal line-height28 f14">
            {{action==1?'小题':'题目'}}{{index+1}}：
            <span v-for="(item,index) in topicArr" :key="index">
                <span v-if="action==1"><input type="text" v-model="item.inputvalue" class="stuff-input" v-if="item.type === 'input'" @change="getStuff2"/><font v-else>{{item.value}}</font></span>
                <span v-else><input type="text" v-model="item.inputvalue" class="stuff-input" v-if="item.type === 'input'" @change="getStuff"/><font v-else>{{item.value}}</font></span>  
            </span>
        </h3>
        <p v-if="data.is_hearing">
            <audio class="success" :src="data.tkinfo.audiofile" controls></audio>
        </p>
        <div class="right-box darkgray-font" v-if="action!=1">
            <span class="mr10" @click="redress(data)" v-if="data.iscorrection">
                <i class="iconfont icon-iconzhuanqu04 f20 vertical-align"></i>
                <b class="weight-normal vertical-align">纠错</b>
            </span>
            <span class="mr10" @click="setFlag(data)">
                <i :class="data.flag==0?'iconfont icon-thin-_pin_bookma f16 vertical-align':'iconfont icon-biaoji green-font f16 vertical-align'"></i>
                <b class="weight-normal vertical-align">标记</b>
            </span>
            <span @click="setCollect(data)" v-if="isshow_collect">
                <i :class="data.collect==0?'iconfont icon-shoucang f18 vertical-align':'iconfont icon-shoucang1 yellow-font f18 vertical-align'"></i>
                <b class="weight-normal vertical-align">收藏</b>
            </span>
        </div>
    </div>
</template>
<script>
export default {
    name:'Stuff',
    props:{
        data:{},
        index:null,
        topic:String,
        action:null,
        parentid:null,
        isshow_collect:null,
        is_saveanswer:null,
        is_powertf:null
    },
    data(){
        return{
            topicArr:[]
        }
    },
    methods:{
        redress(data){
            this.$emit('redressStatus',data.tkid)
        },
        setFlag(data){
            data.flag ? data.flag = 0 : data.flag = 1 
            this.$emit('flagStatus',data.flag,data.tkid)
        },
        setCollect(data){
            data.collect ? data.collect = 0 : data.collect = 1 
            this.$emit('collectStatus',data.collect,data.tkid)
        },
        getStuff(val){
            let inputArr = []
            if(this.topicArr.length){
                this.topicArr.map(item=>{
                    if(item.type=='input'){
                        inputArr.push(item.inputvalue)
                    }
                })
            }
            this.$emit('ifDoexam',this.data.tkid,inputArr)  
           
        },
        getStuff2(val){
            let inputArr = []
            if(this.topicArr.length){
                this.topicArr.map(item=>{
                    if(item.type=='input'){
                        inputArr.push(item.inputvalue)
                    }
                })
            }
            this.$emit('ifDoexam',this.parentid,inputArr,this.index)  
           
        },

    },
    mounted(){
        // let str = '搞好统计调查，_________________才能进行科学的汇总与整理，才能开展统计分析工作，___充分发挥统计信息、咨询、监督的作用。'

        /**
         * 拆分题目
         * 说明：_字符大于3个表示一个可填文本区域
         */
        let topicSplitArr = this.data.title.split(/_{3,}/)
        let _topicArr = []
        topicSplitArr.map((text,i)=>{
            if(i>0){
                _topicArr.push({
                    type:'input',
                    value:'',
                    inputvalue:''
                })
                _topicArr.push({
                    type:'text',
                    value:text,
                })
            }else{
                _topicArr.push({
                    type:'text',
                    value:text,
                })
            }
            
        })
        this.topicArr = _topicArr

        let newTopicArr = []
        let s = 0//计算有值的个数
        if(this.data.useranswer){
            if(this.data.tktype==5){
            
                _topicArr.map((titem,t)=>{
                    if(titem.type=='input'){
                        newTopicArr.push(t)
                    }
                })
                newTopicArr.map((nitem,n)=>{
                    this.topicArr[nitem].inputvalue = this.data.useranswer[n]
                })
                this.data.useranswer.map(sitem=>{
                    if(sitem.toString()){
                        s++
                    }else{
                        return s
                    }
                })
                if(s){
                    this.data.ifdoexam = 1
                }else{
                    this.data.ifdoexam = 0
                }
            }

        }else{
            this.data.ifdoexam=0
        }

        // if(this.is_saveanswer==1||this.is_powertf==1){
        //     let newTopicArr = []
        //     let s = 0//计算有值的个数
        //     if(this.data.useranswer){
        //         if(this.data.tktype==5){
                
        //             _topicArr.map((titem,t)=>{
        //                 if(titem.type=='input'){
        //                     newTopicArr.push(t)
        //                 }
        //             })
        //             newTopicArr.map((nitem,n)=>{
        //                 this.topicArr[nitem].inputvalue = this.data.useranswer[n]
        //             })
        //             this.data.useranswer.map(sitem=>{
        //                 if(sitem.toString()){
        //                     s++
        //                 }else{
        //                     return s
        //                 }
        //             })
        //             if(s){
        //                 this.data.ifdoexam = 1
        //             }else{
        //                 this.data.ifdoexam = 0
        //             }
        //         }

        //     }else{
        //         this.data.ifdoexam=0
        //     }

            
        // }   
        
        
        
    }
}
</script>
<style scoped>
    .stuff{
        line-height: 22px;
        padding-bottom: 40px;
    }
    .stuff-input{
        border:0;
        border-bottom: 1px solid #666;
        min-width: 60px;
    }
    .right-box{
        position: absolute;
        right: 0;
        bottom: 0;
    }
    .right-box span{
      cursor: pointer;
    }
    .success{
        margin-top: 20px;
        width: 400px;
    }
    .childtk h3{
        margin-bottom: 10px !important;
    }
</style>
