UNPKG

commerce-vuex

Version:
59 lines (57 loc) 2.01 kB
import brandProductsService from './brand_products.service' const { doFetchList } = brandProductsService import humps from 'lodash-humps'; export default { namespaced: true, state: { list: [], selected: [], recordsCount: 0, inProgress: false, error: null }, mutations: { inProgress(state, yesOrNo) { state.inProgress = yesOrNo }, setList(state, list) { state.selected = []; for (let i in state.list) { state.selected.push(false); state.selected[i] = false; } state.list = list; }, setListCount(state, number) { state.recordsCount = number; } }, actions: { fetchList: async ({ commit }, { appId, nameLike, skuLike,brandId,brandCatalogId,brandProductId, pageNumber, limit }) => { commit('inProgress', true); try { let offset = (pageNumber - 1) * limit; const response = await doFetchList({ appId, nameLike, skuLike,brandId,brandCatalogId,brandProductId, limit, offset }); if (response.range != null) { let recordsCount = response.range.split("/"); commit('setListCount', Number(recordsCount[1])); const list = await response.data; if (list) { commit('setList', humps((list))); } else commit('setList', []); /*if (recursive && state.list[0].appId != rootState.appOne.one.id) { dispatch('appOne/fetchOne', state.list[0].appId, { root: true }); }*/ } } // eslint-disable-next-line no-useless-catch catch (err) { throw err } finally { commit('inProgress', false) } }, } }