import { getBanner, addBanner, updateBanner, deleteBanner, getByBannerId, carouselAnnouncementBanner, carouselActivityBanner, carouselGetBanner } from '@/api/banner'

const banner = {
  actions: {

    // 根据条件查询 banner
    GetBanner({ commit }, listQuery) {
      return new Promise((resolve, reject) => {
        getBanner(listQuery).then(response => {
          const data = response.data
          resolve(data)
        }).catch(error => {
          reject(error)
        })
        resolve
      })
    },

    // 添加 banner
    AddBanner({ commit }, banner) {
      return new Promise((resolve, reject) => {
        addBanner(banner).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },

    // 修改 banner
    UpdateBanner({ commit }, banner) {
      return new Promise((resolve, reject) => {
        updateBanner(banner).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },

    // 删除 banner
    DeleteBanner({ commit }, bannerId) {
      return new Promise((resolve, reject) => {
        deleteBanner(bannerId).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },

    // 根据bannerId查询 banner
    GetByBannerId({ commit }, bannerId) {
      return new Promise((resolve, reject) => {
        getByBannerId(bannerId).then(response => {
          const data = response.data
          resolve(data)
        }).catch(error => {
          reject(error)
        })
      })
    },
    CarouselAnnouncementBanner({ commit }, num) { // 修改公告的Banner数量
      return new Promise((resolve, reject) => {
        carouselAnnouncementBanner(num).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    CarouselActivityBanner({ commit }, num) { //  修改活动的Banner数量
      return new Promise((resolve, reject) => {
        carouselActivityBanner(num).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    CarouselGetBanner({ commit }) { // 获取设置的Banner数量
      return new Promise((resolve, reject) => {
        carouselGetBanner().then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    }
  }
}

export default banner
