<template>
    <div class="main" v-if="loaded==true">
        <div class="white-bg">
            <h2 class="test-title align-center f20 weight-normal" style="border-bottom:0">{{$route.query.title}}</h2>
        </div>
        <p class="line-height46 align-center darkgray-font">本套试卷含有主观题，针对主观题请自行参考解析评分</p>
        <div class="clearfix test-con">
            <div>
                <div class="test-type-box">
                    <ul class="test-list">
                        <li v-for="(citem,i) in testList" :key="citem.tkid" class="white-bg" >
                            <ks-analyze-subjective :item="citem" :index="i" :action="2" v-if="citem.tktype==1||citem.tktype==5||citem.tktype==6"/>
                        </li>
                    </ul>
                </div>
            </div>
        </div>
        <div class="mt20 align-center">
            <ks-button type="danger" @click="save" class="mb20">提交看成绩</ks-button>
        </div>
        <ks-dialog :visible.sync="isShowOpera" title="提示" width="300px" align="center" top="30%" isshowclose="1">
            <div class="tips-con">
                <i class="f50 iconfont vertical-align" :class="operatstatus==0 && 'red-font icon-shibai'||operatstatus==1 && 'green-font icon-chenggong'||operatstatus==3 && 'red-font icon-jinggao'"></i>
                <font class="f16 vertical-align ml10">{{operaTips}}</font>
            </div>
        </ks-dialog>
    </div>
</template>
<script>
    import {PaperSubjective,SubmitGrade} from '@/api/exam'
    export default {
        name:'YourselfReading',
        data(){
            return{
                curr:0,
                loaded:false,
                getParameters:{
                    answerid:this.$route.query.answerid,
                    paperid:this.$route.query.paperid,
                },
                option:[],
                testList:[],
                subjectNum:0,
                isFixed:false,
                is_feel:0,
                isShowOpera:false,
                operatstatus:0,
                operaTips:''
            }
        },
        methods:{
            getCurr(val){
                this.curr = val
            },
            /**把阿拉伯数字全部转换为大写（1，2，3.... = 一、二、三、） */
            num(n) {
                if(!/(^[1-9]\d*$)/){
                    return '非法数字';
                }
                var uppercase='千百亿千百十万千百十个';
                var nLength=n.length;
                var newStr='';
                if(uppercase.length-nLength<0){
                    return '数字过长';
                }
                uppercase=uppercase.substr(uppercase.length-nLength);
                for(var i=0;i<nLength;i++){
                    newStr +='零一二三四五六七八九'.charAt(n[i])+uppercase.charAt(i);
                };
                newStr=newStr.substr(0,newStr.length-1);
                return newStr;
            },
            
            /**获取试卷 */
            loadPage(){
                PaperSubjective(this.getParameters).then(res=>{
                    if(res.result){
                        res.data.map(item=>{
                            if(item.tktype==6){
                                item.tkinfo.childtk.map(citem=>{
                                    citem.new_score = ''
                                })
                            }else{
                                item.new_score = ''
                            }
                        })
                        this.testList = res.data
                        
                    }else{
                        this.testList = []
                    }
                })
                this.loaded = true
            },
            save(){
                let scorelist=[]
                this.testList.map(item=>{
                    let userscore = []
                    if(item.tktype==6){
                        item.tkinfo.childtk.map((citem,c)=>{
                            if(citem.new_score){
                                citem.userscore = citem.new_score
                            }
                            userscore.push({
                                tkid:c,
                                userscore:citem.userscore
                            })
                        })
                    }else{
                        if(item.new_score){
                            item.userscore = item.new_score
                        }
                        userscore.push(item.userscore)
                    }
                    scorelist.push({
                        tkid:item.tkid,
                        userscore:userscore
                    })
                })
                let data = {
                    paperid:this.getParameters.paperid,
                    answerid:this.getParameters.answerid,
                    scorelist:scorelist
                }
                
                SubmitGrade(data).then(res=>{
                    if(res.result){
                        this.operatstatus = 1
                        this.isShowOpera = true
                        this.operaTips = '提交成功'
                        setTimeout(()=>{
                            this.$router.push({
                                name:'ExaminationResult',
                                query:{
                                    answerid:this.getParameters.answerid,
                                    paperid:this.getParameters.paperid,
                                    type:this.$route.query.type,
                                    categoryid:this.$route.query.categoryid,
                                    dtnum:this.$route.query.dtnum,
                                    tknum:this.$route.query.tknum,
                                    answertime:this.$route.query.answertime,
                                    sumscore:this.$route.query.sumscore,
                                    schoolname:this.$route.query.schoolname,
                                }
                            })
                        },1500)
                    }else{
                        this.isShowOpera = true
                        this.operatstatus = 0
                        this.operaTips = res.msg
                        setTimeout(()=>{
                            this.isShowOpera = false
                        },1500)
                    }
                })
                
            }
        },
        mounted(){
            this.loadPage()
        },
    }
</script>
<style scoped>
    .test-tips{
        margin-bottom: 35px;
    }
    .test-con-left{
        width: 920px;
    }
    .test-type-tips{
        margin:17px 0;
        padding: 20px;
    }
    .test-list li{
        padding:28px 44px;
        margin-bottom: 26px;
    }
    .test-option{
        margin: 14px 7px;
    }
    .test-con-right,.test-right-inner{
        width: 256px;
    }
    .top-application{
        margin: 17px 0;
        padding: 20px 0;
    }
    .top-application li{
        width: 33.33%;
        border-right: 1px solid #efefef;
        box-sizing: border-box;
    }
    .top-application li:last-child{
        border-right:0;
    }
    .top-application li p{
        height: 26px;
    }
    .answer-sheet-box{
        padding: 20px 25px;
    }
    .answer-sheet-box h2{
        margin-bottom: 20px;
    }
    .answer-sheet-box h3{
        margin-bottom: 16px;
    }
    .answer-sheet ul li{
        width: 20px;
        height: 20px;
        border: 1px solid #bbb;
        line-height: 20px;
        margin-right: 7px;
        margin-bottom: 7px;
        box-sizing: border-box;
        cursor: pointer;
    }
    .answer-sheet{
        margin-bottom: 28px;
    }
    .isFixed{
        position:fixed;
        top:0;
        z-index:999;
    }
    .w50{
        width: 50%;
    }
    
</style>
<style>
    .y-r .right-box{
        display: none;
    }
</style>
