You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

vuejs-mixins.js 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. let mixinPriceWithTaxField = {
  2. data() {
  3. return {
  4. price: null,
  5. priceWithTax: null,
  6. buyingPrice: null,
  7. buyingPriceWithTax: null,
  8. differentSupplierTaxRate: null,
  9. multiplyingFactor: null,
  10. priceByRefUnit: null,
  11. priceByRefUnitWithTax: null
  12. };
  13. },
  14. computed: {
  15. taxRateValue: function () {
  16. return $('#productfamily_taxRate').find('option[value="' + this.taxRate + '"]').data('tax-rate-value');
  17. },
  18. supplierTaxRateValue: function () {
  19. if ($('#productfamily_supplierTaxRate').find('option[value="' + this.supplierTaxRate + '"]').data('tax-rate-value') == 'inherited') {
  20. return this.taxRateValue;
  21. } else {
  22. return $('#productfamily_supplierTaxRate').find('option[value="' + this.supplierTaxRate + '"]').data('tax-rate-value');
  23. }
  24. },
  25. },
  26. mounted: function () {
  27. },
  28. methods: {
  29. /*changeTaxRate: function () {
  30. this.$emit('tax-rate-change');
  31. this.changePriceWithTax();
  32. },*/
  33. changeBuyingPrice: function () {
  34. this.buyingPriceUpdate('buyingPrice');
  35. },
  36. changeBuyingPriceWithTax: function () {
  37. this.buyingPriceUpdate('buyingPriceWithTax');
  38. },
  39. changePrice: function () {
  40. this.priceUpdate('price');
  41. this.setMultiplyingFactor();
  42. },
  43. changePriceWithTax: function () {
  44. this.priceUpdate('priceWithTax');
  45. this.setMultiplyingFactor();
  46. },
  47. priceUpdate: function (priceType) {
  48. if (priceType == 'priceWithTax' && this.price) {
  49. this.price = parseFloat(this.price.replace(',', '.')).toFixed(3);
  50. this.priceWithTax = getPriceWithTax(this.price, this.taxRateValue);
  51. } else if (this.priceWithTax) {
  52. if (typeof this.priceWithTax != "number") {
  53. this.priceWithTax = parseFloat(this.priceWithTax.replace(',', '.'));
  54. }
  55. this.priceWithTax = this.priceWithTax.toFixed(2);
  56. this.price = getPrice(this.priceWithTax, this.taxRateValue);
  57. }
  58. this.priceByRefUnitUpdate();
  59. },
  60. buyingPriceUpdate: function (priceType) {
  61. if (priceType == 'buyingPriceWithTax' && this.buyingPrice) {
  62. this.buyingPrice = parseFloat(this.buyingPrice.replace(',', '.')).toFixed(3);
  63. this.buyingPriceWithTax = getPriceWithTax(this.buyingPrice, this.supplierTaxRateValue);
  64. } else if (this.buyingPriceWithTax) {
  65. this.buyingPriceWithTax = parseFloat(this.buyingPriceWithTax.replace(',', '.')).toFixed(2);
  66. this.buyingPrice = getPrice(this.buyingPriceWithTax, this.supplierTaxRateValue);
  67. }
  68. this.setMultiplyingFactor();
  69. this.priceByRefUnitUpdate();
  70. },
  71. updateMultiplyingFactor: function () {
  72. this.priceWithTax = this.buyingPriceValue * this.multiplyingFactor;
  73. this.priceUpdate('price');
  74. },
  75. setMultiplyingFactor: function () {
  76. if (this.priceWithTax || this.buyingPrice) {
  77. this.multiplyingFactor = parseFloat(this.priceWithTaxValue / this.buyingPriceValue).toFixed(3);
  78. }
  79. },
  80. priceByRefUnitUpdate: function () {
  81. if (this.unitCoefficient && this.quantityValue) {
  82. this.priceByRefUnit = parseFloat((this.priceValue / this.quantityValue) * this.unitCoefficient).toFixed(2);
  83. this.priceByRefUnitWithTax = parseFloat((this.priceWithTaxValue / this.quantityValue) * this.unitCoefficient).toFixed(2);
  84. }
  85. }
  86. },
  87. watch: {}
  88. };
  89. let mixinUnit = {
  90. data() {
  91. return Object.assign(
  92. {
  93. quantity: null,
  94. unit: null
  95. }, window.mixinUnitValues);
  96. },
  97. computed: {
  98. unitCoefficient: function () {
  99. if (this.unit) {
  100. unitCoefficient = $('#productfamily_unit').find('option[value="' + this.unit + '"]').data('coefficient');
  101. return unitCoefficient;
  102. } else {
  103. return 0;
  104. }
  105. },
  106. unitReference: function () {
  107. if (this.unit) {
  108. unitRef = $('#productfamily_unit').find('option[value="' + this.unit + '"]').data('unit-reference');
  109. return unitRef;
  110. } else {
  111. return '';
  112. }
  113. }
  114. }
  115. };
  116. let mixinTemplate = {
  117. data() {
  118. return {
  119. templateRender: null,
  120. }
  121. },
  122. render(h) {
  123. if (!this.templateRender) {
  124. return h('div', 'loading...');
  125. } else { // If there is a template, I'll show it
  126. return this.templateRender();
  127. }
  128. },
  129. watch: {
  130. // Every time the template prop changes, I recompile it to update the DOM
  131. template: {
  132. immediate: true, // makes the watcher fire on first render, too.
  133. handler() {
  134. log(this.template);
  135. if (this.template) {
  136. var res = Vue.compile(this.template);
  137. this.templateRender = res.render;
  138. // staticRenderFns belong into $options,
  139. // appearantly
  140. this.$options.staticRenderFns = []
  141. // clean the cache of static elements
  142. // this is a cache with the results from the staticRenderFns
  143. this._staticTrees = []
  144. // Fill it with the new staticRenderFns
  145. for (var i in res.staticRenderFns) {
  146. //staticRenderFns.push(res.staticRenderFns[i]);
  147. this.$options.staticRenderFns.push(res.staticRenderFns[i])
  148. }
  149. }
  150. }
  151. }
  152. }
  153. }