import {
	defineStore
} from 'pinia';
import http from '@/jtools/request/index';
import {
	queryQuestion
} from '@/jtools/api/question';
import storage from '@/jtools/storage';

const question = defineStore({
	id: 'question',
	state: () => ({
		currentCartype: storage.get('carType') || '1001',
		orderQuestion: [], //顺序做题
		currentIndex_subject1:0,//科目一索引 顺序做题
		currentIndex_subject4:0,//科目四索引 顺序做题
	}),

	actions: {
		// 获取顺序做题
		getOrderQuestion(val) {
			queryQuestion({
				carTypeId: this.currentCartype,
				subject: val,
				// questionIdList:[10982,10983,10985,10986]
			}).then(res => {
				if (res.code == '0000') {
					this.orderQuestion = res.data
					const falseList =storage.get(`wrongList_subject${val}`) || []
					const trueList =storage.get(`rightList_subject${val}`) || []
					const falseArr=[]
					const rightArr=[]
					this.orderQuestion.forEach(item=>{
						if(falseList.includes(item.questionId)){
							falseArr.push(item.questionId)
						}
						if(trueList.includes(item.questionId)){
							rightArr.push(item.questionId)
						}
					})
					console.log('falseArr',falseArr);
					storage.set(`wrongList_subject${val}`,falseArr)
					storage.set(`rightList_subject${val}`,rightArr)
					console.log(storage.get(`wrongList_subject${val}`));
				}
			})
		},
		//获取索引
		getCurrentIndex(index,val){
			this[`currentIndex_subject${val}`]=index
		}
	}
});

export default question;