import ajax from '../../util/ajax'
import api from '../../util/api'

export default {
  namespaced: true,
  state: {
    courseVerifs: [],
  },
  mutations: {
    updateCourseList (state, payload) {
      state.courseVerifs = payload || []
    },
  },
  actions: {
    GetCourseVerList ({ commit }, payload) {
      ajax(api.verification.coursebycode.url, {
        method: api.verification.coursebycode.method,
        urlData: {
          id: payload.id
        },
        queryData: {
          ...payload
        }
      }).then(res => {
        commit('updateCourseList', res)
      })
    },
    GetCourseVerListByTel ({ commit }, payload) {
      ajax(api.verification.coursebytel.url, {
        method: api.verification.coursebytel.method,
        urlData: {
          tel: payload.tel
        },
        queryData: {
          ...payload
        }
      }).then(res => {
        commit('updateCourseList', res)
      })
    },
    CourseVerifs ({ commit }, payload) {
      ajax(api.verification.courseverify.url, {
        method: api.verification.courseverify.method,
        urlData: {
          id: payload.id
        }
      }).then(res => {
        if (payload.callback) {
          payload.callback()
        }
      })
    }
  },
}
