forked from nathalie/pedi2
		
	Merge pull request 'seleccionar-subpedido-existente' (#1) from seleccionar-subpedido-existente into master
Reviewed-on: nathalie/pedi2#1
This commit is contained in:
		
						commit
						0200160aa8
					
				
					 2 changed files with 50 additions and 25 deletions
				
			
		
							
								
								
									
										35
									
								
								public/js/subpedidos-create.js
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										35
									
								
								public/js/subpedidos-create.js
									
										
									
									
										vendored
									
									
								
							|  | @ -5,13 +5,30 @@ Vue.component('subpedido-select', { | ||||||
| 			subpedidosExistentes: [] | 			subpedidosExistentes: [] | ||||||
| 		} | 		} | ||||||
| 	}, | 	}, | ||||||
|  |   computed: { | ||||||
|  |     nombresDeSubpedidos: function() { | ||||||
|  |       return this.subpedidosExistentes.map(a => a.nombre.toLowerCase()) | ||||||
|  |     }, | ||||||
|  |     botonCrearDesabilitado : function() { | ||||||
|  |       return !this.subpedido || this.nombresDeSubpedidos.includes(this.subpedido.toLowerCase()) | ||||||
|  |     } | ||||||
|  |   }, | ||||||
| 	props: ["gdcid"], | 	props: ["gdcid"], | ||||||
| 	mounted() { | 	mounted() { | ||||||
| 		console.log("ready"); | 		console.log("ready"); | ||||||
|   	}, |   	}, | ||||||
| 	methods: { | 	methods: { | ||||||
|   		onType() { |   		onType() { | ||||||
| 	    	axios.get("/api/subpedidos?nombre=" + this.subpedido).then(response => { |         if (!this.subpedido){ | ||||||
|  |           this.subpedidosExistentes = []; | ||||||
|  |           return; | ||||||
|  |         } | ||||||
|  | 	    	axios.get("/api/subpedidos", { | ||||||
|  |           params: { | ||||||
|  |             nombre: this.subpedido, | ||||||
|  |             grupo_de_compra: this.gdcid | ||||||
|  |           } | ||||||
|  |         }).then(response => { | ||||||
| 	    		this.subpedidosExistentes = response.data | 	    		this.subpedidosExistentes = response.data | ||||||
| 	    	}); | 	    	}); | ||||||
|   		}, |   		}, | ||||||
|  | @ -20,14 +37,16 @@ Vue.component('subpedido-select', { | ||||||
|   				nombre: this.subpedido, |   				nombre: this.subpedido, | ||||||
|   				grupo_de_compra_id: this.gdcid |   				grupo_de_compra_id: this.gdcid | ||||||
|   			}).then(response => { |   			}).then(response => { | ||||||
| 
 |  | ||||||
|           //se creo el subpedido, guardamos el subpedido en sesion
 |           //se creo el subpedido, guardamos el subpedido en sesion
 | ||||||
|   				axios.post("/subpedidos/guardar_sesion", { |           this.guardarSubpedidoEnSesion(response.data); | ||||||
|   					subpedido: response.data |  | ||||||
|   				}).then(response => { |  | ||||||
|   						window.location.href = 'productos'; |  | ||||||
|   				}); |  | ||||||
|   			}); |   			}); | ||||||
|   		} |   		}, | ||||||
|  |       guardarSubpedidoEnSesion(subpedido) { | ||||||
|  |         axios.post("/subpedidos/guardar_sesion", { | ||||||
|  |           subpedido: subpedido | ||||||
|  |         }).then(response => { | ||||||
|  |           window.location.href = 'productos'; | ||||||
|  |         }); | ||||||
|  |       } | ||||||
|   	} |   	} | ||||||
| }); | }); | ||||||
|  | @ -10,25 +10,31 @@ | ||||||
|     Bienvenidx a la aplicación de compras del <strong>Mercado Popular de Subsistencia</strong> |     Bienvenidx a la aplicación de compras del <strong>Mercado Popular de Subsistencia</strong> | ||||||
|   </p> |   </p> | ||||||
|   <subpedido-select inline-template gdcid="{{Auth::user()->grupoDeCompra->id}}"> |   <subpedido-select inline-template gdcid="{{Auth::user()->grupoDeCompra->id}}"> | ||||||
|   	<div class="block"> |   	<div> | ||||||
| 		<div class="field"> | 	    <label class="label">Escribí el nombre de tu familia o grupo de convivencia</label> | ||||||
| 		    <label class="label">Escribí el nombre de tu familia o grupo de convivencia</label> |   		<div class="columns"> | ||||||
| 	        <div class="control"> | 	  		<div class="column is-two-thirds"> | ||||||
|         		<input class="input" @input="onType" v-model="subpedido"></input> | 				<div class="field"> | ||||||
|  | 			        <div class="control"> | ||||||
|  | 		        		<input class="input" @input="onType" v-model="subpedido"></input> | ||||||
|  | 					</div> | ||||||
|  | 					<p class="help">Debe ser claro para que tus compas del barrio te identifiquen.</p> | ||||||
|  | 				</div> | ||||||
|  | 			</div> | ||||||
|  | 	  		<div class="column is-one-third buttons"> | ||||||
|  | 			  	<button class="button is-danger" :disabled="botonCrearDesabilitado" @click="submit">Crear nuevo pedido</button> | ||||||
| 			</div> | 			</div> | ||||||
| 			<p class="help">Intentá que sea claro como para que tus compas del barrio te identifiquen.</p> |  | ||||||
| 		</div> | 		</div> | ||||||
| 		<div class="buttons"> | 		<div v-if="subpedidosExistentes.length" class="block"> | ||||||
| 		  	<button class="button is-primary" @click="submit">Crear nuevo pedido</button> | 			<label class="label">Si ya comenzaste a hacer tu pedido este mes, elegilo en esta lista:</label> | ||||||
| 		</div> | 			<p class="help">Podés seguir escribiendo en el campo de arriba para refinar la búsqueda.</p> | ||||||
| 	  	<div class="table-container"> |   				<div class="columns is-mobile" v-for="(subpedidoExistente, index) in subpedidosExistentes" :class="{'has-background-grey-lighter': index % 2}"> | ||||||
| 	  		<table class="table is-hoverable"> |   					<div class="column is-half-mobile is-two-thirds-desktop is-two-thirds-tablet"><p style="padding-top: calc(.5em - 1px); margin-bottom: .5rem" v-text="subpedidoExistente.nombre"></p></div> | ||||||
| 	  			<tbody> | 					<div class="buttons column is-half-mobile is-one-third-desktop is-one-third-tablet"> | ||||||
| 	  				<tr v-for="subpedidoExistente in subpedidosExistentes"  > | 					  	<button class="button is-danger" @click="guardarSubpedidoEnSesion(subpedidoExistente)">Continuar pedido</button> | ||||||
| 	  					<td><a v-text="subpedidoExistente.nombre" :href="subpedidoExistente.nombre"></a></td> |   					</div> | ||||||
| 	  				</tr> |   				</div> | ||||||
| 	  			</tbody> | 			</div>		 | ||||||
| 	  		</table> |  | ||||||
| 		</div> | 		</div> | ||||||
| 	</div> | 	</div> | ||||||
|   </subpedido-select> |   </subpedido-select> | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue