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 |         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() { |     mounted() { | ||||||
|       Event.$on('obtener-sesion', () => { |       Event.$on('obtener-sesion', () => { | ||||||
|         axios.get('/subpedidos/obtener_sesion') |         axios.get('/subpedidos/obtener_sesion') | ||||||
|  |  | ||||||
|  | @ -45,14 +45,9 @@ | ||||||
| 
 | 
 | ||||||
| <script> | <script> | ||||||
|     export default { |     export default { | ||||||
|         data() { |  | ||||||
|             return { |  | ||||||
|                 subpedido: this.$root.pedido |  | ||||||
|             } |  | ||||||
|         }, |  | ||||||
|         computed: { |         computed: { | ||||||
|             productos: function() { |             productos: function() { | ||||||
|                 return this.$root.pedido.productos |                 return this.$root.productos | ||||||
|             }, |             }, | ||||||
|             cantidadBonosDeTransporte: function() { |             cantidadBonosDeTransporte: function() { | ||||||
|                 return this.$root.pedido.subtotal_bonos_de_transporte / 15 |                 return this.$root.pedido.subtotal_bonos_de_transporte / 15 | ||||||
|  |  | ||||||
|  | @ -11,7 +11,7 @@ | ||||||
|         <p class="navbar-item"> |         <p class="navbar-item"> | ||||||
|           <slot name="subpedido"></slot> |           <slot name="subpedido"></slot> | ||||||
|         </p> |         </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"> |         <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> | ||||||
|           <span aria-hidden="true"></span> |           <span aria-hidden="true"></span> | ||||||
|  | @ -28,7 +28,7 @@ | ||||||
|               </a> |               </a> | ||||||
|               <input class="input is-small" type="text" placeholder="Harina" v-model="searchString"  @keyup.enter="buscar" > |               <input class="input is-small" type="text" placeholder="Harina" v-model="searchString"  @keyup.enter="buscar" > | ||||||
|             </div> |             </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"> |             <div class="block navbar-item"> | ||||||
|                 <a onclick="event.preventDefault(); document.getElementById('logout-form').submit();" class="text-a"> |                 <a onclick="event.preventDefault(); document.getElementById('logout-form').submit();" class="text-a"> | ||||||
|                     Cerrar sesión |                     Cerrar sesión | ||||||
|  |  | ||||||
|  | @ -26,7 +26,7 @@ | ||||||
|                   <p class="subtitle is-5"><span v-text="producto.descripcion"></span></p> |                   <p class="subtitle is-5"><span v-text="producto.descripcion"></span></p> | ||||||
|                   <div class="field has-addons is-centered is-thin-centered"> |                   <div class="field has-addons is-centered is-thin-centered"> | ||||||
|                       <p class="control"> |                       <p class="control"> | ||||||
|                           <button class="button" @click="cant !== 0 ? cant-- : cant"> |                           <button class="button" @click="cantidad !== 0 ? cantidad-- : cantidad"> | ||||||
|                       <span class="icon is-small"> |                       <span class="icon is-small"> | ||||||
|                         <!-- Habría que ver de poner un ícono de - --> |                         <!-- Habría que ver de poner un ícono de - --> | ||||||
|                       </span> |                       </span> | ||||||
|  | @ -34,10 +34,10 @@ | ||||||
|                           </button> |                           </button> | ||||||
|                       </p> |                       </p> | ||||||
|                       <p class="control"> |                       <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> | ||||||
|                       <p class="control"> |                       <p class="control"> | ||||||
|                           <button class="button" @click="cant++"> |                           <button class="button" @click="cantidad++"> | ||||||
|                       <span class="icon is-small"> |                       <span class="icon is-small"> | ||||||
|                         <!-- Habría que ver de poner un ícono de + --> |                         <!-- Habría que ver de poner un ícono de + --> | ||||||
|                       </span> |                       </span> | ||||||
|  | @ -49,7 +49,7 @@ | ||||||
|           </section> |           </section> | ||||||
|           <footer class="modal-card-foot"> |           <footer class="modal-card-foot"> | ||||||
|               <!-- Habría que ver si cambiar el botón cuando al cantidad es 0 --> |               <!-- 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> |               <button class="button" @click.capture="cerrar">Cancelar</button> | ||||||
|           </footer> |           </footer> | ||||||
|       </div> |       </div> | ||||||
|  | @ -62,7 +62,7 @@ | ||||||
| 		    return { | 		    return { | ||||||
| 		      producto: null, | 		      producto: null, | ||||||
| 		      visible: false, | 		      visible: false, | ||||||
| 		      cant: 0 | 		      cantidad: 0 | ||||||
| 		    } | 		    } | ||||||
| 		  }, | 		  }, | ||||||
| 		  computed: { | 		  computed: { | ||||||
|  | @ -75,15 +75,15 @@ | ||||||
| 		  }, | 		  }, | ||||||
| 		  methods: { | 		  methods: { | ||||||
| 		    cerrar() { | 		    cerrar() { | ||||||
| 		        this.cant = 0; | 		        this.cantidad = 0; | ||||||
| 		        this.visible = false; | 		        this.visible = false; | ||||||
| 		        Event.$emit("migas-pop"); | 		        Event.$emit("migas-pop"); | ||||||
| 		    }, | 		    }, | ||||||
| 		    agregarProducto() { | 		    agregarProducto() { | ||||||
| 		        if (this.cant < 0) alert("No se puede agregar cantidades negativas") | 		        if (this.cantidad < 0) alert("No se puede agregar cantidades negativas") | ||||||
| 		        else if (!Number.isInteger(this.cant)) alert("Las cantidades deben ser números enteros") | 		        else if (!Number.isInteger(this.cantidad)) alert("Las cantidades deben ser números enteros") | ||||||
| 		        else { | 		        else { | ||||||
| 		            Event.$emit('sync-subpedido',this.cant, this.producto.id); | 		            Event.$emit('sync-subpedido',this.cantidad, this.producto.id); | ||||||
| 		            this.cerrar(); | 		            this.cerrar(); | ||||||
| 		        } | 		        } | ||||||
| 		    } | 		    } | ||||||
|  | @ -91,6 +91,7 @@ | ||||||
| 		  mounted() { | 		  mounted() { | ||||||
| 		    Event.$on('producto-seleccionado', (producto) =>  { | 		    Event.$on('producto-seleccionado', (producto) =>  { | ||||||
| 		      this.producto = producto; | 		      this.producto = producto; | ||||||
|  |               this.cantidad = this.$root.cantidad(producto) | ||||||
| 		      this.visible = true; | 		      this.visible = true; | ||||||
| 		      Event.$emit("migas-agregar",this.miga); | 		      Event.$emit("migas-agregar",this.miga); | ||||||
| 		    }); | 		    }); | ||||||
|  |  | ||||||
|  | @ -20,6 +20,7 @@ | ||||||
|                   <p class="title is-6" v-text="producto.nombre"></p> |                   <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" v-text="producto.proveedor"></p> | ||||||
|                   <p class="subtitle is-7">$<span v-text="producto.precio"></span></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> |               </div> | ||||||
|             </div> |             </div> | ||||||
|  | @ -56,6 +57,7 @@ export default { | ||||||
| 	        params: this.params(filtro,valor) | 	        params: this.params(filtro,valor) | ||||||
| 	      }).then(response => { | 	      }).then(response => { | ||||||
| 	        this.productos = response.data.data; | 	        this.productos = response.data.data; | ||||||
|  | 			this.productos.forEach(p => p.cantidad = this.$root.cantidad(p)) | ||||||
| 	      }); | 	      }); | ||||||
| 	      this.visible = true; | 	      this.visible = true; | ||||||
| 	      Event.$emit("migas-agregar",this.miga); | 	      Event.$emit("migas-agregar",this.miga); | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue