UNPKG

procurement-vuex

Version:
93 lines (90 loc) 2.73 kB
import humps from "lodash-humps"; import paymentTermsService from "./purchase_order_payment_terms.service"; const { doFetchList, doPaymentTermsLookupList, doGetPaymentReport } = paymentTermsService; export default { namespaced: true, state: { list: [], listWithAmountDetails:[], 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; }, setListWithAmountDetails(state, list) { state.selected = []; for (let i in state.list) { state.selected.push(false); state.selected[i] = false; } state.listWithAmountDetails = list; }, setListCount(state, number) { state.recordsCount = number; }, }, actions: { fetchList: async ({ commit }, { appId, businessId, pageNumber, limit }) => { // debugger; // commit("inProgress", true); // try { // let offset = (pageNumber - 1) * limit; // const response = await doFetchList({ // appId, // businessId, // 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)); // commit("inProgress", false); // return humps(list); // } else commit("setList", []); // commit("inProgress", false); // } // } catch (err) { // // eslint-disable-next-line no-useless-catch // throw err; // } finally { // commit("inProgress", false); // } }, paymentTermsLookupList: async ({ commit }, { filter }) => { commit("inProgress", true); try { const response = await doPaymentTermsLookupList({ filter }); // commit("setPaymentList", humps(response)); commit("setListWithAmountDetails", humps(response.items ? response : [])); commit("setList", humps(response.items ? response.items : [])); commit( "setListCount", Number(response.items ? response.items.length : 0) ); commit("inProgress", false); return humps(response.items); } catch (err) { // eslint-disable-next-line no-useless-catch throw err; } finally { commit("inProgress", false); } }, }, };