/* eslint-disable no-empty */
// import { branchQueryPage } from '@/api/specialSetting'
import { getSubject, getTeacher,findEducationUsers,getEmployeeOrgan } from '@/api/buildTeam'
import { getSchool } from '@/api/systemManage'
import { vipGroupCategory } from "@/api/vipSeting"

/**
 *
 * 为避免重复请求全局参数，将需要使用的全局参数放到vuex中缓存
 *
 * 使用:
 *
 * 按照需要直接使用 this.$store.dispatch('action', force: Bool 是否强制刷新)
 *
 * 直接从this.$store.state.name 中获取数据
 */

export default {
  state: {
    branchs: [],
    subjects: [],
    teachers: [],
    schools: [],
    vipGroupCategory: [],
    educations:[]
  },
  mutations: {
    commit_branchs: (state, branchs) => {
      state.branchs = branchs
    },
    commit_subjects: (state, subjects) => {
      state.subjects = subjects
    },
    commit_teachers: (state, teachers) => {
      state.teachers = teachers.map(teacher=>{
        return {
          id:teacher.id,
          userId:teacher.id,
          userName:teacher.realName,
          realName:teacher.realName
        }
      })
    },
    commit_schools: (state, schools) => {
      state.schools = schools
    },
    commit_vip_group_category: (state, vipGroupCategory) => {
      state.vipGroupCategory = vipGroupCategory
    },
    commit_educations:(state,educations)=>{
      state.educations = educations
    }
  },
  actions: {
    async setBranchs ({ commit, state }, force) {
      if (!state.branchs.length || force === true) {
        try {
          const res = await getEmployeeOrgan()
          commit('commit_branchs', res.data)
        } catch (error) { }
      }
    },
    async setSubjects ({ commit, state }, force) {
      if (!state.subjects.length || force === true) {
        try {
          const res = await getSubject({rows: 9999, tenantId: '1'})
          commit('commit_subjects', res.data)
        } catch (error) { }
      }
    },
    async setTeachers ({ commit, state }, force) {
      if (!state.teachers.length || force === true) {

        try {
          const res = await getTeacher()
          commit('commit_teachers', res.data)
        } catch (error) { }
      }
    },
    async setSchools ({ commit, state }, force) {
      if (!state.schools.length || force === true) {
        try {
          const res = await getSchool()
          commit('commit_schools', res.data)
        } catch (error) { }
      }
    },
    async setVipGroupCategory ({ commit, state }, force) {
      if (!state.vipGroupCategory.length || force === true) {
        try {
          const res = await vipGroupCategory()
          commit('commit_vip_group_category', res.data)
        } catch (error) { }
      }
    },
    async setEducations({commit,state},force){
      if (!state.educations.length || force === true) {
        try {

          const res = await findEducationUsers()
          commit('commit_educations', res.data)
        } catch (error) { }
      }
    }
  }
}
