new Vue({ el: "#remates", data: { tituloModal: '' , datosResultado: [] } , methods: { abreModal: async function( titulo, cnl ) { this.tituloModal = titulo; this.datosResultado = []; try { let res = await axios.get('/rest/plaza/subasta-vivo/subasta-resumen/PGD002/CATALOGO-HACIENDA?cnl=' + cnl ); this.datosResultado = res.data; } catch(error) { console.log(error) }; } , formatMoney: function(v, c, m, d, t) { let s, i, j; m = m == undefined ? "$" : m.trim() + " ", c = isNaN(c = Math.abs(c)) ? 2 : c, d = d == undefined ? "," : d, t = t == undefined ? "." : t, s = v < 0 ? "-" : "", i = parseInt(v = Math.abs(+v || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0; return m + s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(v - i).toFixed(c).slice(2) : ""); } } , computed: { datosOrdenados: function() { let _ordenados = this.datosResultado.sort( function(a, b) { let _ret = 0; if ( a.orden < b.orden || a.orden == b.orden && a.categoria < b.categoria ) { _ret = -1; } if ( a.orden >= b.orden || a.orden == b.orden && a.categoria > b.categoria ) { _ret = 1; } return _ret; } ) return _ordenados; }, machos: function() { return this.datosOrdenados.filter( function( elem ) { return elem.grupo == 'M'; }); }, hembras: function() { return this.datosOrdenados.filter( function( elem ) { return elem.grupo == 'H'; }); }, machosyHembras: function() { return this.datosOrdenados.filter( function( elem ) { return elem.grupo == 'X'; }); }, haciendaGeneral: function() { return this.datosOrdenados.filter( function( elem ) { return elem.grupo != 'M' && elem.grupo != 'H' && elem.grupo != 'X'; }); }, totalMachos: function() { return this.machos.reduce( function( total, elem ) { return total + elem.cabezas }, 0 ); }, totalHembras: function() { return this.hembras.reduce( function( total, elem ) { return total + elem.cabezas }, 0 ); }, totalMachosyHembras: function() { return this.machosyHembras.reduce( function( total, elem ) { return total + elem.cabezas }, 0 ); }, totalHaciendaGeneral: function() { return this.haciendaGeneral.reduce( function( total, elem ) { return total + elem.cabezas }, 0 ); } } });