procurement-vuex
Version:
Commerce vuex module
65 lines (61 loc) • 1.8 kB
JavaScript
import retailTeamService from './retailteam.service'
import humps from 'lodash-humps'
const { doFetchList,doFetchRetailTeamLookUpList } = retailTeamService
export default{
namespaced: true,
state: {
list: [],
retailTeamLookUpList:[],
inProgress: false
},
mutations: {
inProgress(state, yesOrNo) {
state.inProgress = yesOrNo
},
setList(state, list) {
state.list = list
},
setRetailTeamLookUpList(state, list) {
state.retailTeamLookUpList = list;
},
},
actions: {
fetchList: async ({ commit }) => {
/*eslint-disable*/
//debugger
commit('inProgress', true)
const list = await doFetchList()
if (list) {
commit('setList', humps((list)))
commit('inProgress', false)
return list
} else
commit('setList', [])
commit('inProgress', false)
},
retailTeamLookUpList: async ({ commit}, { retailTeam }) => {
commit('inProgress', true);
try {
const response = await doFetchRetailTeamLookUpList({ retailTeam});
if(response){
commit('setRetailTeamLookUpList', humps(response));
//commit('setList', humps((response.items ? response.items : [])));
//commit('setListCount', Number(response.items? response.items.length : 0));
commit('inProgress', false);
return humps((response))
} else{
commit('setRetailTeamLookUpList', []);
commit('inProgress', false);
return []
}
}
// eslint-disable-next-line no-useless-catch
catch (err) {
throw err
}
finally {
commit('inProgress', false)
}
},
}
}