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

// 请求数据
export default {
  namespaced: true,
  state: {
    list: [],
    detail: {}
  },
  mutations: {
    setList (state, data) {
      state.list = data.list || []
    },
    setDetail (state, data) {
      let cover = data.Imgs.splice(0, 1)
      state.detail = data || {}
      state.detail.cover = cover[0]
    }
  },
  actions: {
    getList (context) {
      return new Promise((resolve, reject) => {
        Ajax({
          ...api.calendar.getCalendarList,
          queryData: {
            page: 1,
            pagesize: 10000
          }
        }).then(res => {
          context.commit('setList', res)
          resolve(res)
        }).catch((err) => {
          reject(err)
        })
      })
    },
    getDetail (context, data) {
      return new Promise((resolve, reject) => {
        Ajax({
          ...api.calendar.getCalendarDetail,
          urlData: { ...data }
        }).then(res => {
          context.commit('setDetail', res)
          resolve()
        }).catch((err) => {
          reject(err)
        })
      })
    },
  }
}
