import { ref } from "vue";
import dayjs from "dayjs";
import Api from '@/api/api';
import router from "@/router/"
import store from "@/store/"

export function useExamTest() {
    let list = ref<selectTestQuestionInfo.row[]>([
        {
            createTime: '2021-11-05 10:25:51',
            id: 20,
            image: null,
            imageYdt: null,
            answer: '√',
            answerkeyword: null,
            explainGif: 'https://t1-1305573081.file.myqcloud.com/qb/gif/20.gif',
            explainJq: '题目中看到“追究”.答对；“不追究”.答错。',
            explainJs:
                '《道路交通安全法》第九十九条：未取得机动车驾驶证、机动车驾驶证被吊销或者机动车驾驶证被暂扣期间驾驶机动车的，由公安机关交通管理部门处二百元以上二千元以下罚款，可以并处十五日以下拘留。',
            explainMp3: 'https://t1-1305573081.file.myqcloud.com/qb/mp3/explain20.mp3',
            issue: '对未取得驾驶证驾驶机动车的，追究其法律责任。',
            opts: '√-×',
            optsArr: ['√', '×'],
            skillkeyword: '追究-答对',
            titlekeyword: '追究',
            issuemp3: 'https://t1-1305573081.file.myqcloud.com/qb/issue/issue20.mp3',
            answermp3: 'https://t1-1305573081.file.myqcloud.com/qb/answer/answer20.mp3',
            explainjsmp3: 'https://t1-1305573081.file.myqcloud.com/qb/explainjs/explainJS20.mp3',
            liceCar: '1',
            liceBus: '1',
            liceTruck: '1',
            liceMoto: '0',
            sequeIssue: '2',
            classIssue: '32',
            placeIssue: '0',
            excellIssue: '1',
            copyIssue: '0',
            mockIssue: '0',
            sequeIssueName: '练习二',
            placeIssueName: null,
            excellIssueName: '必学题一',
            classIssueName: '刑法题',
            questionType: 1,
            subject: 1,
            classSort: 16,
            excellSort: 39,
            sequeSort: 118,
            placeSort: null,
            userAnswer: '',
        },
        {
            createTime: '2021-11-05 10:25:51',
            id: 20,
            image: null,
            imageYdt: null,
            answer: '√',
            answerkeyword: null,
            explainGif: 'https://t1-1305573081.file.myqcloud.com/qb/gif/20.gif',
            explainJq: '题目中看到“追究”.答对；“不追究”.答错。',
            explainJs:
                '《道路交通安全法》第九十九条：未取得机动车驾驶证、机动车驾驶证被吊销或者机动车驾驶证被暂扣期间驾驶机动车的，由公安机关交通管理部门处二百元以上二千元以下罚款，可以并处十五日以下拘留。',
            explainMp3: 'https://t1-1305573081.file.myqcloud.com/qb/mp3/explain20.mp3',
            issue: '对未取得驾驶证驾驶机动车的，追究其法律责任。',
            opts: '√-×',
            optsArr: ['√', '×'],
            skillkeyword: '追究-答对',
            titlekeyword: '追究',
            issuemp3: 'https://t1-1305573081.file.myqcloud.com/qb/issue/issue20.mp3',
            answermp3: 'https://t1-1305573081.file.myqcloud.com/qb/answer/answer20.mp3',
            explainjsmp3: 'https://t1-1305573081.file.myqcloud.com/qb/explainjs/explainJS20.mp3',
            liceCar: '1',
            liceBus: '1',
            liceTruck: '1',
            liceMoto: '0',
            sequeIssue: '2',
            classIssue: '32',
            placeIssue: '0',
            excellIssue: '1',
            copyIssue: '0',
            mockIssue: '0',
            sequeIssueName: '练习二',
            placeIssueName: null,
            excellIssueName: '必学题一',
            classIssueName: '刑法题',
            questionType: 1,
            subject: 1,
            classSort: 16,
            excellSort: 39,
            sequeSort: 118,
            placeSort: null,
            userAnswer: '',
        },
        {
            createTime: '2021-11-05 10:25:51',
            id: 20,
            image: null,
            imageYdt: null,
            answer: '√',
            answerkeyword: null,
            explainGif: 'https://t1-1305573081.file.myqcloud.com/qb/gif/20.gif',
            explainJq: '题目中看到“追究”.答对；“不追究”.答错。',
            explainJs:
                '《道路交通安全法》第九十九条：未取得机动车驾驶证、机动车驾驶证被吊销或者机动车驾驶证被暂扣期间驾驶机动车的，由公安机关交通管理部门处二百元以上二千元以下罚款，可以并处十五日以下拘留。',
            explainMp3: 'https://t1-1305573081.file.myqcloud.com/qb/mp3/explain20.mp3',
            issue: '对未取得驾驶证驾驶机动车的，追究其法律责任。',
            opts: '√-×',
            optsArr: ['√', '×'],
            skillkeyword: '追究-答对',
            titlekeyword: '追究',
            issuemp3: 'https://t1-1305573081.file.myqcloud.com/qb/issue/issue20.mp3',
            answermp3: 'https://t1-1305573081.file.myqcloud.com/qb/answer/answer20.mp3',
            explainjsmp3: 'https://t1-1305573081.file.myqcloud.com/qb/explainjs/explainJS20.mp3',
            liceCar: '1',
            liceBus: '1',
            liceTruck: '1',
            liceMoto: '0',
            sequeIssue: '2',
            classIssue: '32',
            placeIssue: '0',
            excellIssue: '1',
            copyIssue: '0',
            mockIssue: '0',
            sequeIssueName: '练习二',
            placeIssueName: null,
            excellIssueName: '必学题一',
            classIssueName: '刑法题',
            questionType: 1,
            subject: 1,
            classSort: 16,
            excellSort: 39,
            sequeSort: 118,
            placeSort: null,
            userAnswer: '',
        },
        {
            createTime: '2021-11-05 10:25:51',
            id: 20,
            image: null,
            imageYdt: null,
            answer: '√',
            answerkeyword: null,
            explainGif: 'https://t1-1305573081.file.myqcloud.com/qb/gif/20.gif',
            explainJq: '题目中看到“追究”.答对；“不追究”.答错。',
            explainJs:
                '《道路交通安全法》第九十九条：未取得机动车驾驶证、机动车驾驶证被吊销或者机动车驾驶证被暂扣期间驾驶机动车的，由公安机关交通管理部门处二百元以上二千元以下罚款，可以并处十五日以下拘留。',
            explainMp3: 'https://t1-1305573081.file.myqcloud.com/qb/mp3/explain20.mp3',
            issue: '对未取得驾驶证驾驶机动车的，追究其法律责任。',
            opts: '√-×',
            optsArr: ['√', '×'],
            skillkeyword: '追究-答对',
            titlekeyword: '追究',
            issuemp3: 'https://t1-1305573081.file.myqcloud.com/qb/issue/issue20.mp3',
            answermp3: 'https://t1-1305573081.file.myqcloud.com/qb/answer/answer20.mp3',
            explainjsmp3: 'https://t1-1305573081.file.myqcloud.com/qb/explainjs/explainJS20.mp3',
            liceCar: '1',
            liceBus: '1',
            liceTruck: '1',
            liceMoto: '0',
            sequeIssue: '2',
            classIssue: '32',
            placeIssue: '0',
            excellIssue: '1',
            copyIssue: '0',
            mockIssue: '0',
            sequeIssueName: '练习二',
            placeIssueName: null,
            excellIssueName: '必学题一',
            classIssueName: '刑法题',
            questionType: 1,
            subject: 1,
            classSort: 16,
            excellSort: 39,
            sequeSort: 118,
            placeSort: null,
            userAnswer: '',
        },
        {
            createTime: '2021-11-05 10:25:51',
            id: 20,
            image: null,
            imageYdt: null,
            answer: '√',
            answerkeyword: null,
            explainGif: 'https://t1-1305573081.file.myqcloud.com/qb/gif/20.gif',
            explainJq: '题目中看到“追究”.答对；“不追究”.答错。',
            explainJs:
                '《道路交通安全法》第九十九条：未取得机动车驾驶证、机动车驾驶证被吊销或者机动车驾驶证被暂扣期间驾驶机动车的，由公安机关交通管理部门处二百元以上二千元以下罚款，可以并处十五日以下拘留。',
            explainMp3: 'https://t1-1305573081.file.myqcloud.com/qb/mp3/explain20.mp3',
            issue: '对未取得驾驶证驾驶机动车的，追究其法律责任。',
            opts: '√-×',
            optsArr: ['√', '×'],
            skillkeyword: '追究-答对',
            titlekeyword: '追究',
            issuemp3: 'https://t1-1305573081.file.myqcloud.com/qb/issue/issue20.mp3',
            answermp3: 'https://t1-1305573081.file.myqcloud.com/qb/answer/answer20.mp3',
            explainjsmp3: 'https://t1-1305573081.file.myqcloud.com/qb/explainjs/explainJS20.mp3',
            liceCar: '1',
            liceBus: '1',
            liceTruck: '1',
            liceMoto: '0',
            sequeIssue: '2',
            classIssue: '32',
            placeIssue: '0',
            excellIssue: '1',
            copyIssue: '0',
            mockIssue: '0',
            sequeIssueName: '练习二',
            placeIssueName: null,
            excellIssueName: '必学题一',
            classIssueName: '刑法题',
            questionType: 1,
            subject: 1,
            classSort: 16,
            excellSort: 39,
            sequeSort: 118,
            placeSort: null,
            userAnswer: '',
        },
        {
            createTime: '2021-11-05 10:25:51',
            id: 20,
            image: null,
            imageYdt: null,
            answer: '√',
            answerkeyword: null,
            explainGif: 'https://t1-1305573081.file.myqcloud.com/qb/gif/20.gif',
            explainJq: '题目中看到“追究”.答对；“不追究”.答错。',
            explainJs:
                '《道路交通安全法》第九十九条：未取得机动车驾驶证、机动车驾驶证被吊销或者机动车驾驶证被暂扣期间驾驶机动车的，由公安机关交通管理部门处二百元以上二千元以下罚款，可以并处十五日以下拘留。',
            explainMp3: 'https://t1-1305573081.file.myqcloud.com/qb/mp3/explain20.mp3',
            issue: '对未取得驾驶证驾驶机动车的，追究其法律责任。',
            opts: '√-×',
            optsArr: ['√', '×'],
            skillkeyword: '追究-答对',
            titlekeyword: '追究',
            issuemp3: 'https://t1-1305573081.file.myqcloud.com/qb/issue/issue20.mp3',
            answermp3: 'https://t1-1305573081.file.myqcloud.com/qb/answer/answer20.mp3',
            explainjsmp3: 'https://t1-1305573081.file.myqcloud.com/qb/explainjs/explainJS20.mp3',
            liceCar: '1',
            liceBus: '1',
            liceTruck: '1',
            liceMoto: '0',
            sequeIssue: '2',
            classIssue: '32',
            placeIssue: '0',
            excellIssue: '1',
            copyIssue: '0',
            mockIssue: '0',
            sequeIssueName: '练习二',
            placeIssueName: null,
            excellIssueName: '必学题一',
            classIssueName: '刑法题',
            questionType: 1,
            subject: 1,
            classSort: 16,
            excellSort: 39,
            sequeSort: 118,
            placeSort: null,
            userAnswer: '',
        },
        {
            createTime: '2021-11-05 10:25:51',
            id: 20,
            image: null,
            imageYdt: null,
            answer: '√',
            answerkeyword: null,
            explainGif: 'https://t1-1305573081.file.myqcloud.com/qb/gif/20.gif',
            explainJq: '题目中看到“追究”.答对；“不追究”.答错。',
            explainJs:
                '《道路交通安全法》第九十九条：未取得机动车驾驶证、机动车驾驶证被吊销或者机动车驾驶证被暂扣期间驾驶机动车的，由公安机关交通管理部门处二百元以上二千元以下罚款，可以并处十五日以下拘留。',
            explainMp3: 'https://t1-1305573081.file.myqcloud.com/qb/mp3/explain20.mp3',
            issue: '对未取得驾驶证驾驶机动车的，追究其法律责任。',
            opts: '√-×',
            optsArr: ['√', '×'],
            skillkeyword: '追究-答对',
            titlekeyword: '追究',
            issuemp3: 'https://t1-1305573081.file.myqcloud.com/qb/issue/issue20.mp3',
            answermp3: 'https://t1-1305573081.file.myqcloud.com/qb/answer/answer20.mp3',
            explainjsmp3: 'https://t1-1305573081.file.myqcloud.com/qb/explainjs/explainJS20.mp3',
            liceCar: '1',
            liceBus: '1',
            liceTruck: '1',
            liceMoto: '0',
            sequeIssue: '2',
            classIssue: '32',
            placeIssue: '0',
            excellIssue: '1',
            copyIssue: '0',
            mockIssue: '0',
            sequeIssueName: '练习二',
            placeIssueName: null,
            excellIssueName: '必学题一',
            classIssueName: '刑法题',
            questionType: 1,
            subject: 1,
            classSort: 16,
            excellSort: 39,
            sequeSort: 118,
            placeSort: null,
            userAnswer: '',
        },
        {
            createTime: '2021-11-05 10:25:51',
            id: 20,
            image: null,
            imageYdt: null,
            answer: '√',
            answerkeyword: null,
            explainGif: 'https://t1-1305573081.file.myqcloud.com/qb/gif/20.gif',
            explainJq: '题目中看到“追究”.答对；“不追究”.答错。',
            explainJs:
                '《道路交通安全法》第九十九条：未取得机动车驾驶证、机动车驾驶证被吊销或者机动车驾驶证被暂扣期间驾驶机动车的，由公安机关交通管理部门处二百元以上二千元以下罚款，可以并处十五日以下拘留。',
            explainMp3: 'https://t1-1305573081.file.myqcloud.com/qb/mp3/explain20.mp3',
            issue: '对未取得驾驶证驾驶机动车的，追究其法律责任。',
            opts: '√-×',
            optsArr: ['√', '×'],
            skillkeyword: '追究-答对',
            titlekeyword: '追究',
            issuemp3: 'https://t1-1305573081.file.myqcloud.com/qb/issue/issue20.mp3',
            answermp3: 'https://t1-1305573081.file.myqcloud.com/qb/answer/answer20.mp3',
            explainjsmp3: 'https://t1-1305573081.file.myqcloud.com/qb/explainjs/explainJS20.mp3',
            liceCar: '1',
            liceBus: '1',
            liceTruck: '1',
            liceMoto: '0',
            sequeIssue: '2',
            classIssue: '32',
            placeIssue: '0',
            excellIssue: '1',
            copyIssue: '0',
            mockIssue: '0',
            sequeIssueName: '练习二',
            placeIssueName: null,
            excellIssueName: '必学题一',
            classIssueName: '刑法题',
            questionType: 1,
            subject: 1,
            classSort: 16,
            excellSort: 39,
            sequeSort: 118,
            placeSort: null,
            userAnswer: '',
        },
        {
            createTime: '2021-11-05 10:25:51',
            id: 20,
            image: null,
            imageYdt: null,
            answer: '√',
            answerkeyword: null,
            explainGif: 'https://t1-1305573081.file.myqcloud.com/qb/gif/20.gif',
            explainJq: '题目中看到“追究”.答对；“不追究”.答错。',
            explainJs:
                '《道路交通安全法》第九十九条：未取得机动车驾驶证、机动车驾驶证被吊销或者机动车驾驶证被暂扣期间驾驶机动车的，由公安机关交通管理部门处二百元以上二千元以下罚款，可以并处十五日以下拘留。',
            explainMp3: 'https://t1-1305573081.file.myqcloud.com/qb/mp3/explain20.mp3',
            issue: '对未取得驾驶证驾驶机动车的，追究其法律责任。',
            opts: '√-×',
            optsArr: ['√', '×'],
            skillkeyword: '追究-答对',
            titlekeyword: '追究',
            issuemp3: 'https://t1-1305573081.file.myqcloud.com/qb/issue/issue20.mp3',
            answermp3: 'https://t1-1305573081.file.myqcloud.com/qb/answer/answer20.mp3',
            explainjsmp3: 'https://t1-1305573081.file.myqcloud.com/qb/explainjs/explainJS20.mp3',
            liceCar: '1',
            liceBus: '1',
            liceTruck: '1',
            liceMoto: '0',
            sequeIssue: '2',
            classIssue: '32',
            placeIssue: '0',
            excellIssue: '1',
            copyIssue: '0',
            mockIssue: '0',
            sequeIssueName: '练习二',
            placeIssueName: null,
            excellIssueName: '必学题一',
            classIssueName: '刑法题',
            questionType: 1,
            subject: 1,
            classSort: 16,
            excellSort: 39,
            sequeSort: 118,
            placeSort: null,
            userAnswer: '',
        },
        {
            createTime: '2021-11-05 10:25:51',
            id: 20,
            image: null,
            imageYdt: null,
            answer: '√',
            answerkeyword: null,
            explainGif: 'https://t1-1305573081.file.myqcloud.com/qb/gif/20.gif',
            explainJq: '题目中看到“追究”.答对；“不追究”.答错。',
            explainJs:
                '《道路交通安全法》第九十九条：未取得机动车驾驶证、机动车驾驶证被吊销或者机动车驾驶证被暂扣期间驾驶机动车的，由公安机关交通管理部门处二百元以上二千元以下罚款，可以并处十五日以下拘留。',
            explainMp3: 'https://t1-1305573081.file.myqcloud.com/qb/mp3/explain20.mp3',
            issue: '对未取得驾驶证驾驶机动车的，追究其法律责任。',
            opts: '√-×',
            optsArr: ['√', '×'],
            skillkeyword: '追究-答对',
            titlekeyword: '追究',
            issuemp3: 'https://t1-1305573081.file.myqcloud.com/qb/issue/issue20.mp3',
            answermp3: 'https://t1-1305573081.file.myqcloud.com/qb/answer/answer20.mp3',
            explainjsmp3: 'https://t1-1305573081.file.myqcloud.com/qb/explainjs/explainJS20.mp3',
            liceCar: '1',
            liceBus: '1',
            liceTruck: '1',
            liceMoto: '0',
            sequeIssue: '2',
            classIssue: '32',
            placeIssue: '0',
            excellIssue: '1',
            copyIssue: '0',
            mockIssue: '0',
            sequeIssueName: '练习二',
            placeIssueName: null,
            excellIssueName: '必学题一',
            classIssueName: '刑法题',
            questionType: 1,
            subject: 1,
            classSort: 16,
            excellSort: 39,
            sequeSort: 118,
            placeSort: null,
            userAnswer: '',
        },
    ]);
    let correctScore = ref(0)
    let errorScore = ref(0)
    let beforeSubmitVisible = ref(false)
    let submitVisible = ref(false)
    let submitScore = () => {
        list.value.forEach(item => {
            correctScore.value += item.answer == item.userAnswer ? 1 : 0
            if (item.userAnswer) {
                errorScore.value += item.answer == item.userAnswer ? 0 : 1
            }

        })
        beforeSubmitVisible.value = true
        store.commit('SET_ENDTIME', {
            endTime: `${dayjs().format('MM-DD HH:mm:ss')}`,
        });


    }
    let listIndex = ref(0);

    let changeListIndex = (e: PointerEvent) => {
        if (e.target?.dataset?.key) {
            listIndex.value = Number(e.target?.dataset?.key) - 1;
        }
    };
    let selectExamAnswer = (item: string) => {
        list.value[listIndex.value] = { ...list.value[listIndex.value], userAnswer: item };
        console.log(list.value[listIndex.value], item);
    };
    let beforeTopic = () => {
        if (listIndex.value == 0) {
            return;
        }
        listIndex.value = listIndex.value - 1;
    };
    let nextTopic = () => {
        if (listIndex.value == list.value.length - 1) {
            return;
        }
        listIndex.value = listIndex.value + 1;
    };

    let getPgae = () => {
        console.log(router)
        let params = {
            liceBus: "",
            liceCar: "",
            liceMoto: "",
            liceTruck: "",
            subject: Number(router.currentRoute.value.query.subject)
        }
        if (router.currentRoute.value.query && router.currentRoute.value.query.type) {
            switch (router.currentRoute.value.query.type as string) {
                case "liceBus":
                    params.liceBus = "1"
                    break;
                case "liceCar":
                    params.liceCar = "1"
                    break;
                case "liceMoto":
                    params.liceMoto = "1"
                    break;
                case "liceTruck":
                    params.liceTruck = "1"
                    break;
            }
        }
        Api.openApiqustionInfoSelectTestQuestionInfo(params).then((res) => {
            res.data.rows.forEach((item) => {
                item.optsArr = item.opts.split('-');
                item.userAnswer = '';
            });
            list.value = res.data.rows;
        });
    }
    return {
        submitScore,
        changeListIndex,
        selectExamAnswer,
        beforeTopic,
        nextTopic,
        getPgae,
        listIndex,
        list,
        correctScore,
        errorScore,
        beforeSubmitVisible,
        submitVisible





    }
}



