import {FindCalendarList,FindHaveTeacherList,FindNoHaveTeacherList,
  DeleteArrangeByTeacher,
  AddArrangeByTeacher,
  FindTeamTeacherList,
  TeacherThisMonthDutyList,SaveSysTeacherDuty,DutyTemplateList, GetManagerListForChecker,
  TeacherListForChecker,
  TeacherHomeworkListForChecker,
  FindArrangeTemplateIntervalList,
  StudentHomeworkNoFeedbackList,
  StudentHomeworkDetail
} from '@/api/scheduling'
  import { IMG_BASE_URL, APPOR_BASE_URL } from "@/config";
  import axios from '@/axios'
  import router from "@/router"
  import { Message } from 'element-ui'
  const user = {
    state: {
      FindCalendarList:[],
      NextMonthFindCalendarList:[],
      FindHaveTeacherList:[],
      FindNoHaveTeacherList:[],
      FindTeamTeacherList:[],
      TeacherThisMonthDutyList:[],
      DeleteArrangeByTeacher:'',
      AddArrangeByTeacherStatus:'',
      SaveSysTeacherDutyStatus:'',
      DutyTemplateListInfo:[],
      DutyTemplateListSTUS:'',
      NextMonthlistSTUS:'',
      TeacherThisMonthDutySucess:'',
      TeacherThisMonthDutyREfultInfo:"",
      NextOrNewMonthStatus:false,
      GetManagerListForChecker:[],
      TeacherListForChecker:[],
      TeacherHomeworkListForChecker:[],
      FindArrangeTemplateIntervalList:[],
      FindArrangeTemplateIntervalListStatus:"",
      StudentHomeworkNoFeedbackList:[],
      StudentHomeworkDetail:[]
    },
  
    mutations: {
      SET_STUDENT_HOMEWORK_DETAIL_LIST: (state, StudentHomeworkDetail) => {
        state.StudentHomeworkDetail = StudentHomeworkDetail
      },
      SET_STUDENT_NO_FEEDBACK_LIST: (state, StudentHomeworkNoFeedbackList) => {
        state.StudentHomeworkNoFeedbackList = StudentHomeworkNoFeedbackList
      },
      SET_FIND_ARRANGE_TEMPLATE_LIST: (state, FindArrangeTemplateIntervalList) => {
        state.FindArrangeTemplateIntervalList = FindArrangeTemplateIntervalList
      },
      SET_FIND_ARRANGE_TEMPLATE_LIST_STATUS: (state, FindArrangeTemplateIntervalListStatus) => {
        state.FindArrangeTemplateIntervalListStatus = FindArrangeTemplateIntervalListStatus
      },
      SET_TEACHER_LIST_FOR_CHECKER: (state, TeacherListForChecker) => {
        state.TeacherListForChecker = TeacherListForChecker
      },
      SET_TEACHER_HOMEWORK_FOR_CHECKER: (state, TeacherHomeworkListForChecker) => {
        state.TeacherHomeworkListForChecker = TeacherHomeworkListForChecker
      },
      SET_MANAGER_FOR_CHECKER: (state, GetManagerListForChecker) => {
        state.GetManagerListForChecker = GetManagerListForChecker
      },
      SET_NEXTORNEW_MONTHLIST: (state, NextOrNewMonthStatus) => {
        state.NextOrNewMonthStatus = NextOrNewMonthStatus
      },
      SET_CALENDAR_LIST: (state, FindCalendarList) => {
        state.FindCalendarList = FindCalendarList
      },
      SET_NEXTMONTH_CALENDAR_LIST: (state, NextMonthFindCalendarList) => {
        state.NextMonthFindCalendarList = NextMonthFindCalendarList
      },
      SET_HAVETEACHER_LIST: (state, FindHaveTeacherList) => {
        state.FindHaveTeacherList = FindHaveTeacherList
      },
      SET_NOHAVETEACHER_LIST: (state, FindNoHaveTeacherList) => {
        state.FindNoHaveTeacherList = FindNoHaveTeacherList
      },
      SET_TEABTEACHER_LIST: (state, FindTeamTeacherList) => {
        state.FindTeamTeacherList = FindTeamTeacherList
      },
      SET_DELETETEABTEACHER_INFO: (state, DeleteArrangeByTeacher) => {
        state.DeleteArrangeByTeacher = DeleteArrangeByTeacher
      },
      SET_THISMONTHDUSTYLIST: (state, TeacherThisMonthDutyList) => {
        state.TeacherThisMonthDutyList = TeacherThisMonthDutyList
      },
      SET_ADDABTEACHER_INFO:(state, AddArrangeByTeacherStatus) => {
        state.AddArrangeByTeacherStatus = AddArrangeByTeacherStatus
      },
      SET_SAVE_SYSTEACHER_DUTY:(state, SaveSysTeacherDutyStatus) => {
        state.SaveSysTeacherDutyStatus = SaveSysTeacherDutyStatus
      },
      SET_TEMPIATE_TEACHER_DUTY:(state, DutyTemplateListInfo) => {
        // debugger
        state.DutyTemplateListInfo = DutyTemplateListInfo
      },
      SET_TEMPIATE_TEACHER_STATUS:(state, DutyTemplateListSTUS) => {
        // debugger
        state.DutyTemplateListSTUS = DutyTemplateListSTUS
      },
      SET_TEMPIATE_NEXTMONTH_STATUS:(state, NextMonthlistSTUS) => {
        // debugger
        state.NextMonthlistSTUS = NextMonthlistSTUS
      },
      SET__THISMONTHDUSTYLISTR_INFO:(state, TeacherThisMonthDutySucess) => {
        // debugger
        state.TeacherThisMonthDutySucess = TeacherThisMonthDutySucess
      },
      SET_TEMPIATE_TEACHER_REFULT:(state, TeacherThisMonthDutyREfultInfo) => {
        // debugger
        state.TeacherThisMonthDutyREfultInfo = TeacherThisMonthDutyREfultInfo
      },
    },
  
    actions: {
      //当月或下月排班表切换变量
      NextOrNewMonthAction({ commit, state }, data) {
        return new Promise((resolve, reject) => {
          commit('SET_NEXTORNEW_MONTHLIST', data);
        })
      },
     // 排班日历表(校区管理员)
     GetFindCalendarList({ commit, state }, data) {
      return new Promise((resolve, reject) => {
        axios.post(FindCalendarList, data).then(response => {
          const data = response.data || {}
          if (response.code === "999"){
            // debugger
            commit('SET_TEMPIATE_TEACHER_STATUS',new Date());
            commit('SET_CALENDAR_LIST', data);
          }
        }).catch(error => {
          reject(error)
        })
      })
    },
       // 下月排班日历表(校区管理员)
       GetNextmonthFindCalendarList({ commit, state }, data) {
        return new Promise((resolve, reject) => {
          axios.post(FindCalendarList, data).then(response => {
            const data = response.data || {}
            if (response.code === "999"){
              commit('SET_NEXTMONTH_CALENDAR_LIST', data);
              commit('SET_TEMPIATE_NEXTMONTH_STATUS',new Date());
            }
          }).catch(error => {
            reject(error)
          })
        })
      },
      // 已选时段老师列表(校区管理员)
      GetFindHaveTeacherList({ commit, state }, data) {
        commit('SET_HAVETEACHER_LIST', []);
        return new Promise((resolve, reject) => {
          axios.post(FindHaveTeacherList, data).then(response => {
            const data = response.data || {}
            if (response.code === "999"){
              // debugger
              commit('SET_HAVETEACHER_LIST', data);
            }
          }).catch(error => {
            reject(error)
          })
        })
      },
         // 未选时段老师列表(添加老师)(校区管理员)
      GetFindNoHaveTeacherList({ commit, state }, data) {
          return new Promise((resolve, reject) => {
            axios.post(FindNoHaveTeacherList, data).then(response => {
              const data = response.data || {}
              if (response.code === "999"){
                // debugger
                commit('SET_NOHAVETEACHER_LIST', data);
              }
            }).catch(error => {
              reject(error)
            })
          })
        },
             // 组内排班老师列表(校区管理员)
      GetFindTeamTeacherList({ commit, state }, data) {
        return new Promise((resolve, reject) => {
          axios.post(FindTeamTeacherList, data).then(response => {
            const data = response.data || {}
            if (response.code === "999"){
              commit('SET_TEABTEACHER_LIST', data);
            }
          }).catch(error => {
            reject(error)
          })
        })
      },
               // 校区群管理员列表（质检员角色查看）(质检员)
          GetManagerListForCheckerInfo({ commit, state }, data) {
          return new Promise((resolve, reject) => {
              axios.post(GetManagerListForChecker, data).then(response => {
              
                      const data = response.data || {}
                      if (response.code == "999"){
                        commit('SET_MANAGER_FOR_CHECKER', data);
                      }
                    }).catch(error => {
                      reject(error)
                    })
                  })
                },
                      // 校区群管理员列表（老师列表）(质检员)
          GetTeacherListForCheckerInfo({ commit, state }, data) {
            // debug
            return new Promise((resolve, reject) => {
                axios.post(TeacherListForChecker, data).then(response => {
                  
                        const data = response.data || {}
                        if (response.code == "999"){
                          commit('SET_TEACHER_LIST_FOR_CHECKER', data);
                        }
                      }).catch(error => {
                        reject(error)
                      })
                    })
                  },
                              // 校区群管理员列表（查看老师批改完的作业列表）
             GetTeacherHomeworkListForChecker({ commit, state }, data) {
            return new Promise((resolve, reject) => {
                axios.post(TeacherHomeworkListForChecker, data).then(response => {
                  
                        const data = response.data || {}
                        if (response.code == "999"){
                          commit('SET_TEACHER_HOMEWORK_FOR_CHECKER', data);
                        }
                      }).catch(error => {
                        reject(error)
                      })
                    })
                  },
                // 老师本月排班情况接口(老师)
      GetTeacherThisMonthDutyList({ commit, state }, data) {
        return new Promise((resolve, reject) => {
          axios.post(TeacherThisMonthDutyList, data).then(response => {
            const data = response.data || {}
            if (response.code == "999"){
              commit('SET_THISMONTHDUSTYLIST', data);
              commit('SET__THISMONTHDUSTYLISTR_INFO', new Date());
            }
          }).catch(error => {
            reject(error)
          })
        })
      },
      // 时段移除老师
      GetDeleteArrangeByTeacher({ commit, state }, data) {
        return new Promise((resolve, reject) => {
          axios.post(DeleteArrangeByTeacher, data).then(response => {
            const data = response || {}
            if (data.code == "999"){
              Message.success(response.msg)
              commit('SET_DELETETEABTEACHER_INFO', new Date());
            }
          }).catch(error => {
            reject(error)
          })
        })
      },
      //查询当月日历时间列表
      GetFindArrangeTemplateIntervalList({ commit, state }, data) {
        return new Promise((resolve, reject) => {
          axios.post(FindArrangeTemplateIntervalList, data).then(response => {
            const data = response.data || {}
            if (response.code == "999"){
              Message.success(response.msg)
              commit('SET_FIND_ARRANGE_TEMPLATE_LIST',data);
              commit('SET_FIND_ARRANGE_TEMPLATE_LIST_STATUS', new Date());
            }
            if (data.code == "000"){
              Message.error(data.msg)
            }
          }).catch(error => {
            reject(error)
          })
        })
      },
       // 时段添加老师
       GetAddArrangeByTeacher({ commit, state }, data) {
        return new Promise((resolve, reject) => {
          axios.post(AddArrangeByTeacher, data).then(response => {
            const data = response || {}
            if (data.code == "999"){
              Message.success(response.msg)
              commit('SET_ADDABTEACHER_INFO', new Date());
            }
            if (data.code == "000"){
              Message.error(data.msg)
            }
          }).catch(error => {
            reject(error)
          })
        })
      },
       // 保存排班设置
       GetSaveSysTeacherDuty({ commit, state }, data) {
        return new Promise((resolve, reject) => {
          axios.post(SaveSysTeacherDuty, data).then(response => {
            const data = response || {}
            if (data.code == "999"){
              // msg
              Message.success(data.msg)
              commit('SET_SAVE_SYSTEACHER_DUTY', new Date());
            }
            if (data.code == "000"){
              Message.error(data.msg)
            }
           
          }).catch(error => {
            reject(error)
          })
        })
      },
       // 排班设置
       GetDutyTemplateList({ commit, state }, data) {
        return new Promise((resolve, reject) => {
          axios.post(DutyTemplateList, data).then(response => {
            const data = response.data || {}
            // debugger
            if (response.code === "999"){
              // debugger
              Message.success(response.msg)
              commit('SET_TEMPIATE_TEACHER_DUTY',data);
              commit('SET_TEMPIATE_TEACHER_REFULT',new Date());
            }
          }).catch(error => {
            reject(error)
          })
        })
      },
      // 查看所有学生作业列表（不包含已批改）
      GetStudentHomeworkNoFeedbackList({ commit, state }, data) {
        return new Promise((resolve, reject) => {
          axios.post(StudentHomeworkNoFeedbackList, data).then(response => {
            const data = response.data || {}
            if (response.code == "999"){
              commit('SET_STUDENT_NO_FEEDBACK_LIST', data);
            }
          }).catch(error => {
            reject(error)
          })
        })
      },
      // 学生作业详情
      GetStudentHomeworkDetail({ commit, state }, data) {
        return new Promise((resolve, reject) => {
          axios.post(StudentHomeworkDetail, data).then(response => {
            const data = response.data || {}
            if (response.code == "999"){
              commit('SET_STUDENT_HOMEWORK_DETAIL_LIST', data);
            }
          }).catch(error => {
            reject(error)
          })
        })
      },
    }
  }
  
  export default user
  