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

export default {
  namespaced: true,
  state: {
    goods: {},
    goodsType: {},
    goodsOrder: {},
    courseOrder: {},
    course: {},
    cardCoupon: {},
    cardCouponUsedList: {},
    courseVerifyList: {},
  },
  mutations: {
    updateGoods (state, payload) {
      state.goods = payload || {}
    },
    updateGoodsType (state, payload) {
      state.goodsType = payload || {}
    },
    updateGoodsOrder (state, payload) {
      state.goodsOrder = payload || {}
    },
    updateCourseOrder (state, payload) {
      state.courseOrder = payload || {}
    },
    updateCourseList (state, payload) {
      state.course = payload || {}
    },
    updateCardCouponList (state, payload) {
      state.cardCoupon = payload || {}
    },
    updateCardCouponUsedList (state, payload) {
      state.cardCouponUsedList = payload || {}
    },
    updateCourseVerifyList (state, payload) {
      state.courseVerifyList = payload || {}
    },
  },
  actions: {
    GetGoods ({ commit }, payload) {
      return new Promise((resolve, reject) => {
        ajax(api.statistics.goods.url, {
          method: api.statistics.goods.method,
          queryData: {
            ...payload,
          }
        }).then(res => {
          commit('updateGoods', res)
          resolve(res)
        }).catch(reject)
      })
    },
    getGoodsTypeList ({ commit }, payload) {
      return new Promise((resolve, reject) => {
        ajax(api.goodsManager.getGoodsTypeList.url, {
          method: api.goodsManager.getGoodsTypeList.method,
          queryData: {
            ...payload,
          }
        }).then(res => {
          commit('updateGoodsType', res)
          resolve(res)
        }).catch(reject)
      })
    },
    getGoodsOrderList ({ commit }, payload) {
      return new Promise((resolve, reject) => {
        ajax(api.statistics.goodsOrder.url, {
          method: api.statistics.goodsOrder.method,
          queryData: {
            ...payload,
          }
        }).then(res => {
          commit('updateGoodsOrder', res)
          resolve(res)
        }).catch(reject)
      })
    },
    getCourseOrderList ({ commit }, payload) {
      return new Promise((resolve, reject) => {
        ajax(api.statistics.courseOrder.url, {
          method: api.statistics.courseOrder.method,
          queryData: {
            ...payload,
          }
        }).then(res => {
          commit('updateCourseOrder', res)
          resolve(res)
        }).catch(reject)
      })
    },
    getCourseList ({ commit }, payload) {
      return new Promise((resolve, reject) => {
        ajax(api.statistics.courseList.url, {
          method: api.statistics.courseList.method,
          queryData: {
            ...payload,
          }
        }).then(res => {
          commit('updateCourseList', res)
          resolve(res)
        }).catch(reject)
      })
    },
    getCardCouponList ({ commit }, payload) {
      return new Promise((resolve, reject) => {
        ajax(api.statistics.cardCouponList.url, {
          method: api.statistics.cardCouponList.method,
          queryData: {
            ...payload,
          }
        }).then(res => {
          commit('updateCardCouponList', res)
          resolve(res)
        }).catch(reject)
      })
    },
    getCardCouponListExcel ({ commit }, payload) {
      return new Promise((resolve, reject) => {
        ajax(api.statistics.cardCouponListExcel.url, {
          method: api.statistics.cardCouponListExcel.method,
          queryData: {
            ...payload,
          }
        }).then(res => {
          resolve(res)
        }).catch(reject)
      })
    },
    getCardCouponUsedList ({ commit }, payload) {
      return new Promise((resolve, reject) => {
        ajax(api.statistics.cardCouponUsedList.url, {
          method: api.statistics.cardCouponUsedList.method,
          queryData: {
            ...payload,
          }
        }).then(res => {
          commit('updateCardCouponUsedList', res)
          resolve(res)
        }).catch(reject)
      })
    },
    getCourseVerifyList ({ commit }, payload) {
      return new Promise((resolve, reject) => {
        ajax(api.statistics.courseVerifyList.url, {
          method: api.statistics.courseVerifyList.method,
          queryData: {
            ...payload,
          }
        }).then(res => {
          commit('updateCourseVerifyList', res)
          resolve(res)
        }).catch(reject)
      })
    },
    getDashboardData ({ commit }, payload) {
      return new Promise((resolve, reject) => {
        ajax(api.dashboard.dashboardData.url, {
          method: api.dashboard.dashboardData.method,
          queryData: {
            ...payload,
          }
        }).then(res => {
          resolve(res)
        }).catch(reject)
      })
    },
    getDashboardBottomData ({ commit }, payload) {
      return new Promise((resolve, reject) => {
        ajax(api.dashboard.dashboardBottomData.url, {
          method: api.dashboard.dashboardBottomData.method,
          queryData: {
            ...payload,
          }
        }).then(res => {
          resolve(res)
        }).catch(reject)
      })
    },
  }
}
