Usando store para pedidos

This commit is contained in:
Alejandro Tasistro 2025-05-21 19:10:47 -03:00
parent 191f01a398
commit 248b346f78

View file

@ -34,7 +34,7 @@
</template> </template>
<script> <script>
import { mapActions, mapState } from "vuex"; import { mapActions, mapMutations, mapState } from "vuex";
export default { export default {
async mounted() { async mounted() {
@ -42,32 +42,26 @@ export default {
}, },
data() { data() {
return { return {
searchString: null, searchString: null
pedidos: []
} }
}, },
computed: { computed: {
...mapState('barrio',["grupo_de_compra_id"]), ...mapState('barrio',["grupo_de_compra_id","pedidos"]),
deshabilitado: function () { deshabilitado: function () {
return !this.searchString?.trim() return !this.searchString?.trim()
|| this.pedidos.some(p => p.nombre.toLowerCase() === this.searchString.toLowerCase()) || this.pedidos.some(p => p.nombre.toLowerCase() === this.searchString.toLowerCase())
} }
}, },
methods: { methods: {
...mapActions('barrio',["getGrupoDeCompra"]), ...mapActions('barrio',["getGrupoDeCompra","getPedidos"]),
...mapMutations('barrio',["setPedidos"]),
onType() { onType() {
if (!this.searchString) { if (!this.searchString) {
this.pedidos = []; this.setPedidos([]);
return; return;
} }
axios.get("/api/subpedidos", {
params: { this.getPedidos(this.searchString);
nombre: this.searchString,
grupo_de_compra: this.grupo_de_compra_id
}
}).then(response => {
this.pedidos = response.data
});
}, },
submit() { submit() {
axios.post("/api/subpedidos", { axios.post("/api/subpedidos", {