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 }, { id, payload }) {
      return new Promise((resolve, reject) => {
        ajax(api.verification.coursebycode.url, {
          method: api.verification.coursebycode.method,
          urlData: {
            id,
          },
          queryData: {
            ...payload
          }
        }).then(res => {
          commit('updateCourseList', res)
          resolve(res)
        }).catch(reject)
      })
    },
    GetCourseVerListByTel ({ commit }, payload) {
      return new Promise((resolve, reject) => {
        ajax(api.verification.coursebytel.url, {
          method: api.verification.coursebytel.method,
          urlData: {
            tel: payload.tel
          },
          queryData: {
            ...payload
          }
        }).then(res => {
          commit('updateCourseList', res)
          resolve(res)
        }).catch(reject)
      })
    },
    CourseVerifs ({ commit }, payload) {
      ajax(api.verification.courseverify.url, {
        method: api.verification.courseverify.method,
        urlData: {
          id: payload.id
        }
      }).then(res => {
        if (payload.callback) {
          payload.callback()
        }
      })
    },
    drawVerify ({ commit }, { id }) {
      return new Promise((resolve, reject) => {
        ajax(api.verification.drawVerify.url, {
          method: api.verification.drawVerify.method,
          urlData: {
            id,
          }
        }).then(res => {
          resolve(res)
        }).catch(reject)
      })
    },
    drawVerifyList ({ commit }, { id }) {
      return new Promise((resolve, reject) => {
        ajax(api.verification.drawVerifyList.url, {
          method: api.verification.drawVerifyList.method,
          urlData: {
            id,
          }
        }).then(res => {
          resolve(res)
        }).catch(reject)
      })
    },
    getCustomerName ({ commit }, { id }) {
      return new Promise((resolve, reject) => {
        ajax(api.verification.getCustomerName.url, {
          method: api.verification.getCustomerName.method,
          urlData: {
            id,
          }
        }).then(res => {
          resolve(res)
        }).catch(reject)
      })
    },
    flashbuyVerifyList ({ commit }, payload) {
      return new Promise((resolve, reject) => {
        ajax(api.verification.flashbuyVerifyList.url, {
          method: api.verification.flashbuyVerifyList.method,
          urlData: {
            id: payload.code,
            caseid: payload.caseid
          }
        }).then(res => {
          resolve(res)
        }).catch(reject)
      })
    },
    flashbuyVerify ({ commit }, id) {
      return new Promise((resolve, reject) => {
        ajax(api.verification.flashbuyVerify.url, {
          method: api.verification.flashbuyVerify.method,
          urlData: {
            id,
          }
        }).then(res => {
          resolve(res)
        }).catch(reject)
      })
    },
  },
}
