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

export default {
  namespaced: true,
  state: {},
  mutations: {
  },
  actions: {
    getFlashbuyTemplateList () { // 获取抢购活动模板
      return new Promise((resolve, reject) => {
        ajax(api.activityManager.getFlashbuyTemplateList.url, {
          method: api.activityManager.getFlashbuyTemplateList.method,
        }).then(res => {
          resolve(res)
        }).catch(reject)
      })
    },
    getFlashbuyList ({ commit }, payload) { // 获取抢购活动列表
      return new Promise((resolve, reject) => {
        ajax(api.activityManager.getFlashbuyList.url, {
          method: api.activityManager.getFlashbuyList.method,
          queryData: { ...payload }
        }).then(res => {
          resolve(res)
        }).catch(reject)
      })
    },
    addFlashbuy ({ commit }, payload) { // 新增抢购活动
      return new Promise((resolve, reject) => {
        ajax(api.activityManager.addFlashbuy.url, {
          method: api.activityManager.addFlashbuy.method,
          data: { info: JSON.stringify(payload) }
        }).then(res => {
          resolve(res)
        }).catch(reject)
      })
    },
    getFlashbuyById ({ commit }, id) { // 获取抢购信息
      return new Promise((resolve, reject) => {
        ajax(api.activityManager.getFlashbuyById.url, {
          method: api.activityManager.getFlashbuyById.method,
          urlData: {
            id,
          },
        }).then(res => {
          resolve(res)
        }).catch(reject)
      })
    },
    editFlashbuy ({ commit }, payload) { // 更新抢购活动
      return new Promise((resolve, reject) => {
        ajax(api.activityManager.editFlashbuy.url, {
          method: api.activityManager.editFlashbuy.method,
          data: { info: JSON.stringify(payload) }
        }).then(res => {
          resolve(res)
        }).catch(reject)
      })
    },
    deleteFlashbuy ({ commit }, id) { // 删除抢购活动
      return new Promise((resolve, reject) => {
        ajax(api.activityManager.deleteFlashbuy.url, {
          method: api.activityManager.deleteFlashbuy.method,
          urlData: {
            id,
          },
        }).then(res => {
          resolve(res)
        }).catch(reject)
      })
    },
    getFlashbuyRecordsById ({ commit }, payload) { // 获取抢购活动记录列表
      return new Promise((resolve, reject) => {
        ajax(api.activityManager.getFlashbuyRecordsById.url, {
          method: api.activityManager.getFlashbuyRecordsById.method,
          urlData: {
            id: payload.id
          },
          queryData: { ...payload.info }
        }).then(res => {
          resolve(res)
        }).catch(reject)
      })
    },
    updateFlashbuyStatus ({ commit }, payload) { // 更新抢购活动状态
      return new Promise((resolve, reject) => {
        ajax(api.activityManager.updateFlashbuyStatus.url, {
          method: api.activityManager.updateFlashbuyStatus.method,
          urlData: {...payload},
        }).then(res => {
          resolve(res)
        }).catch(reject)
      })
    },
    getCardListByCaseId ({ commit }, id) { // 获取案场下卡列表
      return new Promise((resolve, reject) => {
        ajax(api.activityManager.getCardListByCaseId.url, {
          method: api.activityManager.getCardListByCaseId.method,
          urlData: {
            id,
          },
        }).then(res => {
          resolve(res)
        }).catch(reject)
      })
    },
    getCouponListByCaseId ({ commit }, id) { // 获取案场下券列表
      return new Promise((resolve, reject) => {
        ajax(api.activityManager.getCouponListByCaseId.url, {
          method: api.activityManager.getCouponListByCaseId.method,
          urlData: {
            id,
          },
        }).then(res => {
          resolve(res)
        }).catch(reject)
      })
    },
  }
}
