import axios from 'axios'
const api = {
  query: '/api/content/query',
  details: '/api/content/details/'
}
const state = {
  items: [],
  total: 0,
  contentitem: ''
}
const mutations = {
  content (state, payload) {
    state.items = payload.data
    state.total = payload.total
  },
  details (state, payload) {
    state.contentitem = payload.data
  }
}
const actions = {
  async getcontent ({ commit }, { code, skip, limit } = {}) {
    const res = await axios.get(api.query, { params: { columns: code, skip, limit } })
    if (res.data.errcode === 0) commit('content', res.data)
    return res
  },
  async getdetails ({ commit }, { id } = {}) {
    const res = await axios.get(`${api.details}${id}`)
    if (res.data.errcode === 0) commit('details', res.data)
    return res
  }
}
export default { state, mutations, actions, namespaced: true }
