<template>
    <div>
        <!--按人 学生信息 -->
        <div class="filter-tab-wrap">
            <span :class="['filter-tab-item', tabIndex == 0 ? 'filter-tab-item-active':'']" @click="tabIndex = 0">
                {{`${$t('task.mLabel3')} ( ${unmarked} )`}}
            </span>
            <span :class="['filter-tab-item', tabIndex == 1 ? 'filter-tab-item-active':'']" @click="tabIndex = 1">
                {{`${$t('task.mLabel4')} ( ${marking.length} )`}}
            </span>
            <span :class="['filter-tab-item', tabIndex == 2 ? 'filter-tab-item-active':'']" @click="tabIndex = 2">
                {{`${$t('task.mLabel2')} ( ${marked.length} )`}}
            </span>
        </div>
        <!-- 已阅、未阅、进行中学生 -->
        <div class="setting-block stu-name-wrap">
            <div class="setting-content stu-name-content">
                <div class="stu-wrap">
                    <div class="stu-list-wrap no-stu-wrap" v-show="tabIndex == 0">
                        <p class="no-mark-text" v-if="unmarked > 0 && unmarked < total">
                            {{$t('task.lastLabel1')}}
                            <span class="no-mark-count">{{unmarked}}</span>
                            {{$t('task.lastLabel2')}}
                            <span class="continue-mark" @click="toByStuView()">
                                {{$t('task.continue')}}
                            </span>
                        </p>
                        <p class="no-mark-text" v-else-if="unmarked > 0">
                            {{$t('task.totalLabel1')}}
                            <span class="no-mark-count">{{unmarked}}</span>
                            {{$t('task.totalLabel2')}}
                            <span class="continue-mark" @click="toByStuView()">
                                {{$t('task.start')}}
                            </span>
                        </p>
                        <EmptyData v-else :textContent="$t('task.noUnmark')"></EmptyData>
                    </div>
                    <div class="stu-list-wrap" v-show="tabIndex == 1">
                        <span class="stu-name" v-for="(item,index) in marking" :key="index" @click="toByStuView(item.stuId)">{{item.stuId}}</span>
                        <EmptyData :textContent="$t('task.noMarking')" v-show="!marking.length"></EmptyData>
                    </div>
                    <div class="stu-list-wrap" v-show="tabIndex == 2">
                        <span class="stu-name" v-for="(item,index) in marked" :key="index" @click="toByStuView(item.stuId)">{{item.stuId}}</span>
                        <EmptyData :top="0" :textContent="$t('task.noMarked')" v-show="!marked.length"></EmptyData>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>
<script>
export default {
    props: {
        stusData: {
            required: true,
            type: Array,
            default: () => {
                return []
            }
        },
        total: {
            required: true,
            type: Number,
            default: 0
        },
        //老师需要批阅的题目，如果为空数组代表是批阅所有题目
        qus: {
            required: true,
            type: Array,
            default: () => {
                return []
            }
        },
        // 试卷题号和题目简要信息
        quNoList: {
            required: true,
            type: Array,
            default: () => {
                return []
            }
        }
    },
    data() {
        return {
            tabIndex: 0
        }
    },
    methods: {
        toByStuView(stuId) {
            this.$emit('getStuId', stuId)
        }
    },
    computed: {
        //当前阅卷任务未阅数量
        unmarked() {
            let res = this.total - this.marked.length - this.marking.length
            if (res == 0) {
                if (this.marking.length == 0) {
                    this.tabIndex = 2
                } else {
                    this.tabIndex = 1
                }
            }
            return res
        },
        //当前阅卷任务已阅学生信息
        marked() {
            if (this.stusData) {
                return this.stusData.filter((item) => {
                    let scores = item.item.map(scoreItem => {
                        return scoreItem.sc
                    })
                    //如果是按题分配的任务，只验证指定给老师的题目
                    if (this.qus.length) {
                        scores = scores.filter((sItem, sIndex) => {
                            return this.qus.includes(sIndex)
                        })
                    }
                    //如果是按人分配，则需要排除客观题（自动评分）
                    else {
                        scores = scores.filter((sItem, sIndex) => {
                            return !this.quNoList[sIndex].disabled
                        })
                    }
                    return !scores.includes(-1)
                })
            } else {
                return []
            }
        },
        //当前阅卷任务进行中学生信息
        marking() {
            if (this.stusData) {
                return this.stusData.filter((item) => {
                    let scores = item.item.map(scoreItem => {
                        return scoreItem.sc
                    })
                    //如果是按题分配的任务，只验证指定给老师的题目
                    if (this.qus.length) {
                        scores = scores.filter((sItem, sIndex) => {
                            return this.qus.includes(sIndex)
                        })
                    }
                    return scores.includes(-1)
                })
            } else {
                return []
            }
        },
    },
    watch: {
        // stusData: {
        //     handler(n, o) {
        //     },
        //     deep: true
        // }
    }
}
</script>
<style scoped lang="less">
.filter-tab-wrap {
    margin-top: 15px;
}
.filter-tab-item {
    display: inline-block;
    width: 80px;
    text-align: center;
    background: white;
    color: var(--second-text-color);
    margin-right: 1px;
    border-top-right-radius: 15px;
    padding: 2px 0px;
    font-size: 12px;
    cursor: pointer;
    border-bottom: none;
}
.filter-tab-item-active {
    background: var(--input-bg-color);
    color: var(--primary-text-color);
    font-weight: bold;
    // border: 1px solid rgba(98, 97, 101, 0.4);
    border-bottom: none;
}
.setting-block {
    margin-top: 30px;
}
.stu-name-wrap {
    margin-top: -1px;
}
.setting-content {
    background: var(--input-bg-color);
    border: 1px solid var(--vorder-color);
    padding: 15px 10px;
    border-radius: 5px;
    margin-right: 12px;
    margin-top: 8px;
    padding: 15px 10px 25px 10px;
}
.stu-name-content {
    margin-top: 0px;
    border-top-left-radius: 0px !important;
}
.stu-list-wrap {
    min-height: 151px;
}
.no-stu-wrap {
    display: flex;
    align-items: center;
}
.no-mark-text {
    user-select: none;
    .no-mark-count {
        color: var(--primary-text-color);
        font-size: 24px;
        display: inline-block;
        margin: 0px 5px;
    }
    .continue-mark {
        color: #fff;
        padding: 4px 15px;
        border-radius: 4px;
        cursor: pointer;
        background: #1cc0f3;
    }
}
.stu-name {
    font-size: 12px;
    margin: 5px 5px 5px 2px;
    padding: 2px 12px;
    border-radius: 55px;
    display: inline-block;
    cursor: pointer;
    user-select: none;
    
    background: white;
    color: var(--primary-text-color);
    &:hover {
        background: var(--hover-text-color);
        font-weight: bold;
        // color: #ddd;
    }
}
</style>