|
-
-
-
- var app = new Vue({
- el: '#app-document-form',
- data: {
- document: [],
- idDocument: 0,
- typeDocument: '',
- idUser: '',
- productsArray: [],
- productAddId: 0,
- productAddPrice: '',
- productAddQuantity: 1,
- ordersArray: [],
- total: 0,
- total_with_tax: 0
- },
- mounted: function() {
- this.init() ;
- },
- methods: {
- formatPrice: formatPrice,
- init: function() {
- var idDocument = $('#app-document-form').attr('data-id-document') ;
- this.idDocument = idDocument ;
- var classDocument = $('#app-document-form').attr('data-class-document') ;
- this.classDocument = classDocument ;
-
- if(idDocument) {
- var app = this ;
- axios.get(UrlManager.getBaseUrlAbsolute()+"document/ajax-init",{params: {
- idDocument: idDocument,
- classDocument: classDocument
- }})
- .then(function(response) {
- if(response.data.return == 'success') {
- app.document = response.data.document ;
- app.idUser = response.data.idUser ;
- app.productsArray = response.data.products ;
- app.ordersArray = response.data.orders ;
- app.total = response.data.total ;
- app.total_with_tax = response.data.total_with_tax ;
- }
- }) ;
- }
- },
- changeUser: function(event) {
- var app = this ;
- axios.get(UrlManager.getBaseUrlAbsolute()+"document/ajax-address-user",{params: {
- idUser: app.idUser
- }})
- .then(function(response) {
- if(response.data.return == 'success') {
- Vue.set(app.document, 'address', response.data.address);
- }
- else {
- app.document.address = '' ;
- }
- }) ;
- },
- formatPrice: formatPrice,
- validateDocument: function() {
- var app = this ;
- axios.get(UrlManager.getBaseUrlAbsolute()+"document/ajax-validate-document",{params: {
- idDocument: app.idDocument,
- classDocument: app.classDocument,
- }})
- .then(function(response) {
- appAlerts.alertResponse(response) ;
- app.init() ;
- }) ;
- },
- getStepProductAdd: function() {
- return parseInt(this.productsArray[this.productAddId].step) ;
- },
- changeProductAdd: function(event) {
- var idProduct = event.currentTarget.value ;
- this.productAddId = idProduct ;
- this.productAddPrice = parseFloat(this.productsArray[idProduct].price_with_tax).toFixed(2) ;
- this.productAddQuantity = this.getStepProductAdd() ;
- },
- changeQuantityProductAdd: function(quantity) {
- var step = this.getStepProductAdd() ;
- quantity = quantity * step ;
- this.productAddQuantity += quantity ;
- if(this.productAddQuantity < 1) {
- this.productAddQuantity = step ;
- }
- },
- submitProductAdd: function() {
- var app = this ;
- axios.get(UrlManager.getBaseUrlAbsolute()+"document/ajax-add-product",{params: {
- idDocument: app.idDocument,
- classDocument: app.classDocument,
- idProduct: app.productAddId,
- quantity: app.productAddQuantity,
- price: app.productAddPrice,
- }})
- .then(function(response) {
- appAlerts.alertResponse(response) ;
- app.productAddId = 0 ;
- app.init() ;
- }) ;
- },
- deleteProductOrder: function(idProductOrder) {
- var app = this ;
- axios.get(UrlManager.getBaseUrlAbsolute()+"document/ajax-delete-product-order",{params: {
- idProductOrder: idProductOrder
- }})
- .then(function(response) {
- appAlerts.alertResponse(response) ;
- app.init() ;
- }) ;
- },
- formatProductAddPrice: function() {
- this.productAddPrice = Number(this.productAddPrice).toFixed(2).replace(',', '.');
- if(isNaN(this.productAddPrice)) {
- this.productAddPrice = 0 ;
- }
- },
- formatProductAddQuantity: function() {
- this.productAddQuantity = parseInt(this.productAddQuantity) ;
- if(isNaN(this.productAddQuantity)) {
- this.productAddQuantity = 1 ;
- }
- }
- }
- });
-
|