let mixinPriceWithTaxField = { data() { return { price: null, priceWithTax: null, buyingPrice: null, buyingPriceWithTax: null, differentSupplierTaxRate: null, multiplyingFactor: null, priceByRefUnit:null, priceByRefUnitWithTax:null }; }, computed:{ taxRateValue: function () { return $('#productfamily_taxRate').find('option[value="'+this.taxRate+'"]').data('tax-rate-value'); }, supplierTaxRateValue: function () { if($('#productfamily_supplierTaxRate').find('option[value="'+this.supplierTaxRate+'"]').data('tax-rate-value') == 'inherited') { return this.taxRateValue; }else{ return $('#productfamily_supplierTaxRate').find('option[value="'+this.supplierTaxRate+'"]').data('tax-rate-value'); } }, }, mounted: function () { }, methods: { /*changeTaxRate: function () { this.$emit('tax-rate-change'); this.changePriceWithTax(); },*/ changeBuyingPrice: function () { this.buyingPriceUpdate('buyingPrice'); }, changeBuyingPriceWithTax: function () { this.buyingPriceUpdate('buyingPriceWithTax'); }, changePrice: function () { this.priceUpdate('price'); this.setMultiplyingFactor(); }, changePriceWithTax: function () { this.priceUpdate('priceWithTax'); this.setMultiplyingFactor(); }, priceUpdate: function (priceType) { if (priceType == 'priceWithTax' && this.price) { this.price = parseFloat(this.price.replace(',', '.')).toFixed(3); this.priceWithTax = getPriceWithTax(this.price, this.taxRateValue); } else if (this.priceWithTax) { if(typeof this.priceWithTax !="number"){ this.priceWithTax = parseFloat(this.priceWithTax.replace(',', '.')); } this.priceWithTax = this.priceWithTax.toFixed(2); this.price = getPrice(this.priceWithTax, this.taxRateValue); } this.priceByRefUnitUpdate(); }, buyingPriceUpdate: function (priceType) { if (priceType == 'buyingPriceWithTax' && this.buyingPrice) { this.buyingPrice = parseFloat(this.buyingPrice.replace(',', '.')).toFixed(3); this.buyingPriceWithTax = getPriceWithTax(this.buyingPrice, this.supplierTaxRateValue); } else if (this.buyingPriceWithTax) { this.buyingPriceWithTax = parseFloat(this.buyingPriceWithTax.replace(',', '.')).toFixed(2); this.buyingPrice = getPrice(this.buyingPriceWithTax, this.supplierTaxRateValue); } this.setMultiplyingFactor(); this.priceByRefUnitUpdate(); }, updateMultiplyingFactor: function () { this.priceWithTax = this.buyingPriceValue * this.multiplyingFactor; this.priceUpdate('price'); }, setMultiplyingFactor:function () { if(this.priceWithTax || this.buyingPrice) { this.multiplyingFactor = parseFloat(this.priceWithTaxValue / this.buyingPriceValue).toFixed(3); } }, priceByRefUnitUpdate:function () { if(this.unitArray[this.unitValue]){ this.priceByRefUnit = parseFloat((this.priceValue / this.quantityValue) *this.unitArray[this.unitValue].coefficient).toFixed(2); this.priceByRefUnitWithTax = parseFloat((this.priceWithTaxValue / this.quantityValue )*this.unitArray[this.unitValue].coefficient).toFixed(2); } } }, watch: { } }; let mixinUnit = { data() { return Object.assign( { quantity:null, unit: null, unitArray: null }, window.mixinUnitValues); }, computed: { unitReference: function () { if (this.unit) { return this.unitArray[this.unit].ref } else { return ''; } } } }; let mixinTemplate = { data() { return { templateRender: null, } }, render(h) { if (!this.templateRender) { return h('div', 'loading...'); } else { // If there is a template, I'll show it return this.templateRender(); } }, watch: { // Every time the template prop changes, I recompile it to update the DOM template: { immediate: true, // makes the watcher fire on first render, too. handler() { if (this.template) { var res = Vue.compile(this.template); this.templateRender = res.render; // staticRenderFns belong into $options, // appearantly this.$options.staticRenderFns = [] // clean the cache of static elements // this is a cache with the results from the staticRenderFns this._staticTrees = [] // Fill it with the new staticRenderFns for (var i in res.staticRenderFns) { //staticRenderFns.push(res.staticRenderFns[i]); this.$options.staticRenderFns.push(res.staticRenderFns[i]) } } } } } }