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

// 请求数据
export default {
  namespaced: true,
  state: {
    rushDetail: {}
  },
  mutations: {
    setDetail (state, data) {
      state.rushDetail = data.flashBuy || {}
    }
  },
  actions: {
    getRush (context, data) {
      return new Promise((resolve, reject) => {
        Ajax({
          ...api.rush.getRush,
          urlData: { ...data }
        }).then(res => {
          context.commit('setDetail', res)
          resolve(res)
        }).catch((err) => {
          reject(err)
        })
      })
    },
    setRush (context, data) {
      return new Promise((resolve, reject) => {
        Ajax({
          ...api.rush.setRush,
          urlData: { ...data }
        }).then(res => {
          resolve(res)
        }).catch((err) => {
          reject(err)
        })
      })
    },
    IsNewCustomer (context) {
      return new Promise((resolve, reject) => {
        Ajax({
          ...api.rush.IsNewCustomer
        }).then(res => {
          resolve(res)
        }).catch((err) => {
          reject(err)
        })
      })
    },
    AddNewFlashBuyCustomer (context, data) {
      return new Promise((resolve, reject) => {
        Ajax({
          ...api.rush.AddNewFlashBuyCustomer,
          urlData: { ...data }
        }).then(res => {
          resolve(res)
        }).catch((err) => {
          reject(err)
        })
      })
    },
    UpdateFlashBuyCustomer (context, data) {
      return new Promise((resolve, reject) => {
        Ajax({
          ...api.rush.UpdateFlashBuyCustomer,
          urlData: { ...data }
        }).then(res => {
          resolve(res)
        }).catch((err) => {
          reject(err)
        })
      })
    }
  }
}
