/* 
 * 模拟部分活动模块的学生作答数据（作业活动/投票活动/问卷活动等）
 * 获取学生名单 - 自定义作答数据结构 - 保存活动数据
 * 2020-07-20 OnePsycho
 * */
import apiTools from '@/api'
var Mock = require('mockjs')

const CLASS_CODE = ["HBCN0101", "HBCN0102"]
const SCHOOL_CODE = 'HBCN'
const activityId = '40e3da01-b9c8-4524-a588-fec246eaeb5f'
const activityType = 'homework'
let studentList = []
let resultList = []

async function initMockAnswers(){
	studentList = await getStudentList()
	let mockData = doMock(studentList)
	let resultData = await saveMockData(mockData)
	console.log(resultData)
}


/* 获取学生清单 */
function getStudentList(){
	return new Promise((r,j) => {
		apiTools.courseMgmt.getClassroomStudent({
			classroomCode: CLASS_CODE,
			schoolCode: SCHOOL_CODE
		}).then(res => {
			if (!res.error && res.result.data) {
				r(res.result.data)
			} else {
				j(500)
			}
		})
	})
}

/* 根据活动类型模拟作答数据 */
function doMock(arr){
	let result = []
	arr.forEach(i => {
		result.push({
			id:activityId,
			code:i.code,
			content:[{
				answers:Mock.mock('@cparagraph(2)'),
				resource:[]
			}],
			submit:true,
			submitTime: new Date(Mock.mock('@datetime')).getTime()
		})
	})
	return result
}

/* 获取学生清单 */
function saveMockData(list){
	return new Promise((r,j) => {
		apiTools.learnActivity.SaveRecords(list).then(res => {
			if (!res.error && res.result.data) {
				r(res.result.data)
			} else {
				j(500)
			}
		})
	})
}


export default {
	initMockAnswers
}


