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

export default {
  namespaced: true,
  state: {
    luckDrawList: {},
    luckDrawShareList: {}
  },
  mutations: {
    updateLuckDrawList (state, payload) {
      state.luckDrawList = payload || {}
    },
    updateLuckDrawShareList (state, payload) {
      state.luckDrawShareList = payload || {}
    },
  },
  actions: {
    getLuckDrawList ({ commit }, payload) { // 获取抽奖列表
      return new Promise((resolve, reject) => {
        ajax({
          ...api.luckDraw.luckDrawList,
          queryData: {
            ...payload,
          }
        }).then(res => {
          commit('updateLuckDrawList', res)
          resolve(res)
        }).catch(reject)
      })
    },
    getLuckDrawShareList ({ commit }, payload) { // 获取抽奖分享列表
      return new Promise((resolve, reject) => {
        ajax({
          ...api.luckDraw.luckDrawShareList,
          queryData: {
            ...payload
          }
        }).then(res => {
          commit('updateLuckDrawShareList', res)
          resolve(res)
        }).catch(reject)
      })
    }
  }
}
