Agregado modulo productos + cambios de nombre
This commit is contained in:
parent
7bfbbd9309
commit
a512f8e162
3 changed files with 65 additions and 5 deletions
10
resources/js/store/index.js
vendored
10
resources/js/store/index.js
vendored
|
@ -2,8 +2,9 @@ import Vue from 'vue';
|
|||
import Vuex from 'vuex';
|
||||
import admin from "./modules/admin";
|
||||
import login from "./modules/login";
|
||||
import chismosa from "./modules/pedido";
|
||||
import session from "./modules/barrio";
|
||||
import pedido from "./modules/pedido";
|
||||
import barrio from "./modules/barrio";
|
||||
import productos from "./modules/productos";
|
||||
|
||||
Vue.use(Vuex);
|
||||
|
||||
|
@ -11,7 +12,8 @@ export default new Vuex.Store({
|
|||
modules: {
|
||||
admin,
|
||||
login,
|
||||
chismosa,
|
||||
session,
|
||||
pedido,
|
||||
barrio,
|
||||
productos,
|
||||
},
|
||||
});
|
||||
|
|
1
resources/js/store/modules/barrio.js
vendored
1
resources/js/store/modules/barrio.js
vendored
|
@ -1,7 +1,6 @@
|
|||
import axios from "axios";
|
||||
|
||||
const state = {
|
||||
lastFetch: null,
|
||||
grupo_de_compra_id: null,
|
||||
grupo_de_compra: null,
|
||||
devoluciones_habilitadas: null,
|
||||
|
|
59
resources/js/store/modules/productos.js
vendored
Normal file
59
resources/js/store/modules/productos.js
vendored
Normal file
|
@ -0,0 +1,59 @@
|
|||
import axios from "axios";
|
||||
|
||||
const state = {
|
||||
lastFetch: null,
|
||||
categorias: [],
|
||||
productos: [],
|
||||
filtro: null,
|
||||
};
|
||||
|
||||
const mutations = {
|
||||
setCategorias(state, categorias) {
|
||||
state.lastFetch = new Date();
|
||||
state.categorias = categorias;
|
||||
console.log(state);
|
||||
},
|
||||
setProductos(state, productos) {
|
||||
state.lastFetch = new Date();
|
||||
state.productos = productos;
|
||||
},
|
||||
setFiltro(state, filtro) {
|
||||
state.lastFetch = new Date();
|
||||
state.filtro = filtro;
|
||||
},
|
||||
};
|
||||
|
||||
const actions = {
|
||||
async init({ dispatch }) {
|
||||
if (state.lastFetch)
|
||||
return;
|
||||
dispatch('getCategorias');
|
||||
dispatch('getProductos');
|
||||
},
|
||||
async getCategorias({ commit }) {
|
||||
const response = await axios.get('api/categorias');
|
||||
commit('setCategorias', response.data);
|
||||
},
|
||||
async getProductos({ commit }) {
|
||||
const response = await axios.get("/api/productos");
|
||||
commit('setFiltro', null);
|
||||
commit('setProductos', response.data.data);
|
||||
},
|
||||
async seleccionarCategoria({ commit }, { categoria }) {
|
||||
const response = await axios.get("/api/productos");
|
||||
commit('setFiltro', { clave: "categoria", valor: categoria });
|
||||
commit('setProductos', response.data.data);
|
||||
},
|
||||
async filtrarProductos({ commit }, { filtro, valor }) {
|
||||
const response = await axios.get("/api/productos");
|
||||
commit('setFiltro', { clave: filtro, valor: valor });
|
||||
commit('setProductos', response.data.data);
|
||||
}
|
||||
};
|
||||
|
||||
export default {
|
||||
namespaced: true,
|
||||
state,
|
||||
mutations,
|
||||
actions,
|
||||
};
|
Loading…
Add table
Reference in a new issue