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

export default {
  namespaced: true,
  state: {
    pageDetail: null
  },
  mutations: {
    updatePageDetail (state, payload) {
      state.pageDetail = { ...payload.data }
    },
    emptyPageDetail (state) {
      state.pageDetail = null
    }
  },
  actions: {
    getNewIndex ({ commit }, payload) {
      return new Promise((resolve, reject) => {
        Ajax(api.newIndex.url, {
          method: api.newIndex.method,
          urlData: { id: payload.id },
          queryData: { city: payload.city }
        }).then(res => {
          commit('updatePageDetail', res)
          resolve(res)
        }).catch((res) => {
          reject(res)
        })
      })
    }
  }
}
