import { carouselList, addCarousel, deleteCarouselBatch, selectCarousel, updateCarousel } from '@/api/carousel'

const carousel = {
  namespaced: true,

  actions: {
    getCarouselList({ commit, state }, data) {
      return new Promise((resolve, reject) => {
        carouselList(data).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    createCarlosel({ commit, state }, data) {
      return new Promise((resolve, reject) => {
        addCarousel(data).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    selectCarousel({ commit, state }, id) {
      return new Promise((resolve, reject) => {
        selectCarousel(id).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    updateCarousel({ commit, state }, params) {
      return new Promise((resolve, reject) => {
        updateCarousel(params.id, params.data).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    deleteCarousel({ commit, state }, data) { // 删除轮播图
      return new Promise((resolve, reject) => {
        deleteCarouselBatch(data).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    }

  }
}

export default carousel
