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

// 请求数据
export default {
  namespaced: true,
  state: {
    gymCardList: [],
    gymCardDetail: ''
  },
  mutations: {
    setgymCardList (state, data) {
      state.gymCardList = data.list
    },
    setgymCardDetail (state, data) {
      state.gymCardDetail = data
    }
  },
  actions: {
    getCardList (context) { // 获取体验卡列表
      return new Promise((resolve) => {
        Ajax(api.card.getCardList.url, {
          method: api.card.getCardList.method,
        }).then(res => {
          resolve(res)
        }).catch((err) => {
          reject(err)
        })
      })
    },
    getCardInfo (context, { id }) { // 获取体验卡详情
      return new Promise((resolve) => {
        Ajax(api.card.getCardInfo.url, {
          method: api.card.getCardInfo.method,
          urlData: {
            id,
          }
        }).then(res => {
          resolve(res)
        }).catch((err) => {
          reject(err)
        })
      })
    },
    getgymCardList (context, data) {
      return new Promise((resolve) => {
        Ajax(api.user.gymCard.url, {
          method: api.user.gymCard.method,
          queryData: {
            ...data
          }
        }).then(res => {
          context.commit('setgymCardList', res)
          resolve(res)
        }).catch((err) => {
          reject(err)
        })
      })
    },
    getgymCardDetail (context, data) {
      return new Promise((resolve, reject) => {
        Ajax(api.user.gymCardDetail.url, {
          method: api.user.gymCardDetail.method,
          urlData: {
            ...data
          }
        }).then(res => {
          context.commit('setgymCardDetail', res)
          resolve(res)
        }).catch((err) => {
          reject(err)
        })
      })
    }
  }
}
