import { getCourseInfo } from "@/api/home";

import store from '@/store/index.js';

// 暴露请求方法
export const getCourseInfoData = () => {
    let courseList = [];
    const teacherId = store.state.user.teacher.id;
    getCourseInfo(teacherId).then(response => {
        let a = response.data;
        console.log(a);
        let b
        // b为测试数据，使用时把b替换为a
        b = {
            0: [
                {
                    gradeAlias: "",
                    weekValue: 1,
                    courseTitle: "",
                },
                {
                    gradeAlias: "",
                    weekValue: 2,
                    courseTitle: "",
                },
                {
                    gradeAlias: "",
                    weekValue: 3,
                    courseTitle: "",
                },
                {
                    gradeAlias: "",
                    weekValue: 4,
                    courseTitle: "",
                }
            ],
            1: [
                {
                    gradeAlias: "",
                    weekValue: 1,
                    courseTitle: "",
                },
                {
                    gradeAlias: "",
                    weekValue: 2,
                    courseTitle: "",
                },
                {
                    gradeAlias: "",
                    weekValue: 3,
                    courseTitle: "",
                },
                {
                    gradeAlias: "高一二班",
                    weekValue: 4,
                    courseTitle: "物理",
                }
            ],
            2: [
                {
                    gradeAlias: "高一二班",
                    weekValue: 1,
                    courseTitle: "物理",
                },
                {
                    gradeAlias: "高一二班",
                    weekValue: 2,
                    courseTitle: "数学",
                },
                {
                    gradeAlias: "高一二班",
                    weekValue: 3,
                    courseTitle: "英语",
                },
                {
                    gradeAlias: "",
                    weekValue: 4,
                    courseTitle: "",
                },
                {
                    gradeAlias: "高一二班",
                    weekValue: 5,
                    courseTitle: "英语",
                },
                {
                    gradeAlias: "高一二班",
                    weekValue: 6,
                    courseTitle: "英语",
                },
                {
                    gradeAlias: "高一二班",
                    weekValue: 7,
                    courseTitle: "英语",
                },
            ],
            3: [
                {
                    gradeAlias: "高一二班",
                    weekValue: 1,
                    courseTitle: "数学",
                },
                {
                    gradeAlias: "高一二班",
                    weekValue: 2,
                    courseTitle: "英语",
                },
                {
                    gradeAlias: "高一二班",
                    weekValue: 3,
                    courseTitle: "语文",
                },
                {
                    gradeAlias: "高一二班",
                    weekValue: 4,
                    courseTitle: "物理",
                }
            ],
            4: [
                {
                    gradeAlias: "高一二班",
                    weekValue: 1,
                    courseTitle: "数学",
                },
                {
                    gradeAlias: "高一二班",
                    weekValue: 2,
                    courseTitle: "英语",
                },
                {
                    gradeAlias: "高一二班",
                    weekValue: 3,
                    courseTitle: "语文",
                },
                {
                    gradeAlias: "高一二班",
                    weekValue: 4,
                    courseTitle: "物理",
                }
            ],
            5: [
                {
                    gradeAlias: "高一二班",
                    weekValue: 1,
                    courseTitle: "数学",
                },
                {
                    gradeAlias: "高一二班",
                    weekValue: 2,
                    courseTitle: "英语",
                },
                {
                    gradeAlias: "高一二班",
                    weekValue: 3,
                    courseTitle: "语文",
                },
                {
                    gradeAlias: "高一二班",
                    weekValue: 4,
                    courseTitle: "物理",
                }
            ],
            6: [
                {
                    gradeAlias: "高一二班",
                    weekValue: 1,
                    courseTitle: "数学",
                },
                {
                    gradeAlias: "高一二班",
                    weekValue: 2,
                    courseTitle: "英语",
                },
                {
                    gradeAlias: "高一二班",
                    weekValue: 3,
                    courseTitle: "语文",
                },
                {
                    gradeAlias: "高一二班",
                    weekValue: 4,
                    courseTitle: "物理",
                }
            ],
        }
        //遍历对象分别拿到里面的数组，一个数组为一排
        Object.keys(a).forEach((key, index) => {
            let obj = {};
            switch (key*1-1) {
                case 0:
                    obj.sortName = '第一节课';
                    break;
                case 1:
                    obj.sortName = '第二节课';
                    break;
                case 2:
                    obj.sortName = '第三节课';
                    break;
                case 3:
                    obj.sortName = '第四节课';
                    break;
                case 4:
                    obj.sortName = '第五节课';
                    break;
                case 5:
                    obj.sortName = '第六节课';
                    break;
                case 6:
                    obj.sortName = '第七节课';
                    break;
                case 7:
                    obj.sortName = '第八节课';
                    break;
                case 8:
                    obj.sortName = '第九节课';
                    break;
                case 9:
                    obj.sortName = '第十节课';
                    break;
                default:
                    break;
            }
            a[key].forEach((item, index) => {
                // 判断weekValue的值，将对应的课程信息放入对应的位置
                if (item.weekValue == 1) {
                    obj.monday = item.courseTitle
                    obj.mondayGradeAlias = item.gradeAlias,
                        obj.mondayWeekValue = item.weekValue
                } else if (item.weekValue == 2) {
                    obj.tuesday = item.courseTitle
                    obj.tuesdayGradeAlias = item.gradeAlias,
                        obj.tuesdayWeekValue = item.weekValue
                } else if (item.weekValue == 3) {
                    obj.wednesday = item.courseTitle
                    obj.wednesdayGradeAlias = item.gradeAlias,
                        obj.wednesdayWeekValue = item.weekValue
                } else if (item.weekValue == 4) {
                    obj.thursday = item.courseTitle
                    obj.thursdayGradeAlias = item.gradeAlias,
                        obj.thursdayWeekValue = item.weekValue
                } else if (item.weekValue == 5) {
                    obj.friday = item.courseTitle
                    obj.fridayGradeAlias = item.gradeAlias,
                        obj.fridayWeekValue = item.weekValue
                } else if (item.weekValue == 6) {
                    obj.saturday = item.courseTitle
                    obj.saturdayGradeAlias = item.gradeAlias,
                        obj.saturdayWeekValue = item.weekValue
                } else if (item.weekValue == 7) {
                    obj.sunday = item.courseTitle
                    obj.sundayGradeAlias = item.gradeAlias,
                        obj.sundayWeekValue = item.weekValue
                }
            })

            courseList.push(obj)
        })
        console.log(this.courseList);

    }).catch(error => {
    })
    return courseList
}

