//全科学情分析数据
import Mock from 'mockjs';//引入mock模块
import mockTools from '@/mock';
import classList from '@/static/classList.json' //模拟班级数据
import scatter from '@/static/scatter.json' //模拟学生数据
import testScatter from '@/static/testScatter.json' //模拟试题分析落点数据
import examList from '@/static/examList.json' //模拟评测数据
import knowledgeList from '@/static/knowledgeList.json' //模拟知识点数据
import exerciseList from '@/static/exerciseList.json' //模拟知识点数据
import chineseList from '@/static/chinesePoint.json' //模拟语文知识点数据
import questions from '@/static/questionList.json' //模拟题目数据
import filter from '@/static/filter.json' //模拟题目数据
import subjectPercent from '@/static/percent.json' //模拟各科平均分数据


export default {
  state: {
    classList: classList,
    subjectPercent: subjectPercent,
    memberList: mockTools.data.studentList,
    examList: examList,
    knowledgeList: knowledgeList,
    questions: questions,
    scatter: scatter,
    testScatter: testScatter,
    exerciseList: exerciseList,
    filterData: filter,
    baseBarData: mockTools.data.subjectList,
    subjectList: [],
    pieData: [
      { value: 3, name: "方程与不等式", id: 1, itemStyle: { color: '#00cc66' } },
      { value: 2, name: "图形的性质", id: 2, itemStyle: { color: '#b6a2df' } },
      { value: 2, name: "统计与概率", id: 3, itemStyle: { color: '#59b2ef' } },
      { value: 2, name: "函数", id: 4, itemStyle: { color: '#ffba82' } },
      { value: 1, name: "图形的变化", id: 5, itemStyle: { color: '#db7984' } },
    ],
    radarData: [70, 80, 65, 72, 82, 70],
    entryData:0
  },
  getters: {
    getRandomBarData() {
      let newData = Mock.mock({
        'subjectList|10': [{
          "id|+1": 1,
          "className|1-10": 1,
          "chinese|60-120": 60,
          "math|60-120": 60,
          "english|60-120": 60,
          "physics|60-120": 60,
          "chemistry|60-120": 60,
          "biology|60-120": 60,
        }]
      });
      return newData;
    }
  },
  mutations: {
    //修改首页成绩分析的及格率百分比
    updatePercent(state, val) {
      val.forEach(item => {
        item.classRate = (90 - Math.ceil(Math.random() * 20)) + '%';
        item.gradeRate = (90 - Math.ceil(Math.random() * 20)) + '%';
        item.areaRate = (90 - Math.ceil(Math.random() * 20)) + '%';
      })
      state.subjectPercent = val;
    },

    //更新均分分析柱状图
    updateBaseBarData(state, val) {
      //console.log(newData);
      let newData = Mock.mock({
        'subjectList|10': [{
          "id|+1": 1,
          "className|1-10": 1,
          "chinese|60-120": 60,
          "math|60-120": 60,
          "english|60-120": 60,
          "physics|60-120": 60,
          "chemistry|60-120": 60,
          "biology|60-120": 60,
        }]
      });

      newData.subjectList.forEach(item => {
        item.className = '初一' + item.id + '班'
      })
      state.baseBarData = newData.subjectList;
    },

    //更新科目选择科目列表数据
    updateSubjectList(state, list) {
      state.subjectList = list;
    },

    //更新试题落点数据
    updateScatterData(state, val) {
      val.forEach(item => {
        item.x = Math.random().toFixed(2);
        item.y = Math.floor(Math.random() * 100);
      })
      state.scatter = val;
    },

    //更新试题落点数据
    updateTestScatterData(state, val) {
      val.forEach(item => {
        item.x = Math.random().toFixed(2);
        item.y = Math.floor(Math.random() * 100);
      })
      state.testScatter = val;
    },

    //更新知识点占比数据
    updatePieData(state, subject) {
      let list = ['文言文', '古代诗歌', '现代文', '文学常识', '语言表达与应用'];
      let mathList = ['图形的变化', '方程与不等式', '图形的性质', '统计与概率', '函数'];

        state.pieData.forEach((item, index) => {
          item.name = subject == 0 ? list[index] : mathList[index];
          item.value = Math.floor(Math.random() * 3) + 1;
        })

      state.exerciseList = subject == 0 ? chineseList : exerciseList;
    },

    //更新认知层次分布数据
    updateRadarData(state) {
      let list = JSON.parse(JSON.stringify(state.radarData)); //必须转化深拷贝才能监听到State内部的数据变化
      for (let i = 0; i < list.length; i++) {
        list[i] = 90 - Math.floor(Math.random() * 30);
      }
      state.radarData = list;
    },

    updateEntryData(state, data) {
      state.entryData = data;
    },

    updateSubjectPercent(state, data) {
      state.subjectList = data;
    }
  },
  actions: {
    updateRadarData(context) {
      context.commit('updateRadarData')
    }
  }
}
