Merge pull request 'Modal de producto muestra cantidad pedida' (#19) from refactor/cantidades-producto into master
Reviewed-on: #19
This commit is contained in:
		
						commit
						9991337b87
					
				
					 5 changed files with 26 additions and 17 deletions
				
			
		
							
								
								
									
										11
									
								
								resources/js/app.js
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										11
									
								
								resources/js/app.js
									
										
									
									
										vendored
									
									
								
							|  | @ -56,6 +56,17 @@ const app = new Vue({ | |||
|         pedido: null | ||||
|       } | ||||
|     }, | ||||
|     computed: { | ||||
|       productos: function() { | ||||
|         return this.pedido.productos | ||||
|       } | ||||
|     }, | ||||
|     methods: { | ||||
|       cantidad(producto) { | ||||
|         let pedido = this.productos.some(p => p.id == producto.id) | ||||
|         return pedido ? this.productos.find(p => p.id == producto.id).pivot.cantidad : 0 | ||||
|       } | ||||
|     }, | ||||
|     mounted() { | ||||
|       Event.$on('obtener-sesion', () => { | ||||
|         axios.get('/subpedidos/obtener_sesion') | ||||
|  |  | |||
|  | @ -45,14 +45,9 @@ | |||
| 
 | ||||
| <script> | ||||
|     export default { | ||||
|         data() { | ||||
|             return { | ||||
|                 subpedido: this.$root.pedido | ||||
|             } | ||||
|         }, | ||||
|         computed: { | ||||
|             productos: function() { | ||||
|                 return this.$root.pedido.productos | ||||
|                 return this.$root.productos | ||||
|             }, | ||||
|             cantidadBonosDeTransporte: function() { | ||||
|                 return this.$root.pedido.subtotal_bonos_de_transporte / 15 | ||||
|  |  | |||
|  | @ -11,7 +11,7 @@ | |||
|         <p class="navbar-item"> | ||||
|           <slot name="subpedido"></slot> | ||||
|         </p> | ||||
|         <chismosa-dropdown class="hide-above-1023"></chismosa-dropdown> | ||||
|         <chismosa-dropdown v-if="this.$root.pedido != null" class="hide-above-1023" id="mobile"></chismosa-dropdown> | ||||
|         <a role="button" class="navbar-burger" :class="{'is-active':burgerActiva}" aria-label="menu" aria-expanded="false" data-target="nav-bar" @click="toggleBurger"> | ||||
|           <span aria-hidden="true"></span> | ||||
|           <span aria-hidden="true"></span> | ||||
|  | @ -28,7 +28,7 @@ | |||
|               </a> | ||||
|               <input class="input is-small" type="text" placeholder="Harina" v-model="searchString"  @keyup.enter="buscar" > | ||||
|             </div> | ||||
|             <chismosa-dropdown v-if="this.$root.pedido != null" class="hide-below-1024"></chismosa-dropdown> | ||||
|             <chismosa-dropdown v-if="this.$root.pedido != null" class="hide-below-1024" id="wide"></chismosa-dropdown> | ||||
|             <div class="block navbar-item"> | ||||
|                 <a onclick="event.preventDefault(); document.getElementById('logout-form').submit();" class="text-a"> | ||||
|                     Cerrar sesión | ||||
|  |  | |||
|  | @ -26,7 +26,7 @@ | |||
|                   <p class="subtitle is-5"><span v-text="producto.descripcion"></span></p> | ||||
|                   <div class="field has-addons is-centered is-thin-centered"> | ||||
|                       <p class="control"> | ||||
|                           <button class="button" @click="cant !== 0 ? cant-- : cant"> | ||||
|                           <button class="button" @click="cantidad !== 0 ? cantidad-- : cantidad"> | ||||
|                       <span class="icon is-small"> | ||||
|                         <!-- Habría que ver de poner un ícono de - --> | ||||
|                       </span> | ||||
|  | @ -34,10 +34,10 @@ | |||
|                           </button> | ||||
|                       </p> | ||||
|                       <p class="control"> | ||||
|                           <input id="cantidad" class="input" type="number" v-model.number="cant" style="text-align: center"> | ||||
|                           <input id="cantidad" class="input" type="number" v-model.number="cantidad" style="text-align: center"> | ||||
|                       </p> | ||||
|                       <p class="control"> | ||||
|                           <button class="button" @click="cant++"> | ||||
|                           <button class="button" @click="cantidad++"> | ||||
|                       <span class="icon is-small"> | ||||
|                         <!-- Habría que ver de poner un ícono de + --> | ||||
|                       </span> | ||||
|  | @ -49,7 +49,7 @@ | |||
|           </section> | ||||
|           <footer class="modal-card-foot"> | ||||
|               <!-- Habría que ver si cambiar el botón cuando al cantidad es 0 --> | ||||
|               <button class="button is-success" :disabled="cant <= 0" @click="agregarProducto">Aceptar</button> | ||||
|               <button class="button is-success" :disabled="cantidad <= 0" @click="agregarProducto">Aceptar</button> | ||||
|               <button class="button" @click.capture="cerrar">Cancelar</button> | ||||
|           </footer> | ||||
|       </div> | ||||
|  | @ -62,7 +62,7 @@ | |||
| 		    return { | ||||
| 		      producto: null, | ||||
| 		      visible: false, | ||||
| 		      cant: 0 | ||||
| 		      cantidad: 0 | ||||
| 		    } | ||||
| 		  }, | ||||
| 		  computed: { | ||||
|  | @ -75,15 +75,15 @@ | |||
| 		  }, | ||||
| 		  methods: { | ||||
| 		    cerrar() { | ||||
| 		        this.cant = 0; | ||||
| 		        this.cantidad = 0; | ||||
| 		        this.visible = false; | ||||
| 		        Event.$emit("migas-pop"); | ||||
| 		    }, | ||||
| 		    agregarProducto() { | ||||
| 		        if (this.cant < 0) alert("No se puede agregar cantidades negativas") | ||||
| 		        else if (!Number.isInteger(this.cant)) alert("Las cantidades deben ser números enteros") | ||||
| 		        if (this.cantidad < 0) alert("No se puede agregar cantidades negativas") | ||||
| 		        else if (!Number.isInteger(this.cantidad)) alert("Las cantidades deben ser números enteros") | ||||
| 		        else { | ||||
| 		            Event.$emit('sync-subpedido',this.cant, this.producto.id); | ||||
| 		            Event.$emit('sync-subpedido',this.cantidad, this.producto.id); | ||||
| 		            this.cerrar(); | ||||
| 		        } | ||||
| 		    } | ||||
|  | @ -91,6 +91,7 @@ | |||
| 		  mounted() { | ||||
| 		    Event.$on('producto-seleccionado', (producto) =>  { | ||||
| 		      this.producto = producto; | ||||
|               this.cantidad = this.$root.cantidad(producto) | ||||
| 		      this.visible = true; | ||||
| 		      Event.$emit("migas-agregar",this.miga); | ||||
| 		    }); | ||||
|  |  | |||
|  | @ -20,6 +20,7 @@ | |||
|                   <p class="title is-6" v-text="producto.nombre"></p> | ||||
|                   <p class="subtitle is-7" v-text="producto.proveedor"></p> | ||||
|                   <p class="subtitle is-7">$<span v-text="producto.precio"></span></p> | ||||
|                   <p class="subtitle has-text-right is-7" v-if="producto.cantidad != 0"><span v-text="producto.cantidad"></span> en chismosa</p> | ||||
|                 </div> | ||||
|               </div> | ||||
|             </div> | ||||
|  | @ -56,6 +57,7 @@ export default { | |||
| 	        params: this.params(filtro,valor) | ||||
| 	      }).then(response => { | ||||
| 	        this.productos = response.data.data; | ||||
| 			this.productos.forEach(p => p.cantidad = this.$root.cantidad(p)) | ||||
| 	      }); | ||||
| 	      this.visible = true; | ||||
| 	      Event.$emit("migas-agregar",this.miga); | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue