Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

148 lines
4.7KB

  1. // Reference array sent to dynamic staticRenderFns
  2. var staticRenderFns = [];
  3. Vue.component('component-unit', {
  4. props: ['template', 'keyForm', 'taxRateValue'],
  5. data() {
  6. return {
  7. templateRender: null,
  8. unit: null,
  9. price: null,
  10. priceWithTax: null
  11. };
  12. },
  13. mounted: function() {
  14. this.unit = $('#value-unit-'+this.keyForm).val() ;
  15. this.price = parseFloat($('#value-price-'+this.keyForm).val()).toFixed(3) ;
  16. this.priceUpdate('priceWithTax') ;
  17. },
  18. methods: {
  19. getUnitReference: function () {
  20. if (this.unit == 'g') {
  21. return 'kg';
  22. } else if (this.unit == 'ml') {
  23. return 'L';
  24. } else {
  25. return this.unit;
  26. }
  27. },
  28. changeTaxRate: function() {
  29. this.$emit('tax-rate-change') ;
  30. this.changePriceWithTax() ;
  31. },
  32. changePrice: function() {
  33. this.priceUpdate('price') ;
  34. },
  35. changePriceWithTax: function() {
  36. this.priceUpdate('priceWithTax') ;
  37. },
  38. priceUpdate: function(priceType) {
  39. var taxRate = this.getTaxRate() ;
  40. if(priceType == 'priceWithTax') {
  41. this.price = parseFloat(this.price.replace(',','.')).toFixed(3) ;
  42. this.priceWithTax = getPriceWithTax(this.price, taxRate);
  43. }
  44. else {
  45. this.priceWithTax = parseFloat(this.priceWithTax.replace(',','.')).toFixed(2) ;
  46. this.price = getPrice(this.priceWithTax, taxRate) ;
  47. }
  48. },
  49. getTaxRate: function() {
  50. var taxRate = this.taxRateValue ;
  51. if(this.taxRateValue == -1) {
  52. var taxRate = $('#productfamily_taxRate').find('option:selected').data('tax-rate-value');
  53. if(typeof taxRate == 'undefined') {
  54. taxRate = 0 ;
  55. }
  56. }
  57. return taxRate ;
  58. }
  59. },
  60. render(h) {
  61. if (!this.templateRender) {
  62. return h('div', 'loading...');
  63. } else { // If there is a template, I'll show it
  64. return this.templateRender();
  65. }
  66. },
  67. watch: {
  68. taxRateValue: function(newVal, oldVal) {
  69. this.changePriceWithTax() ;
  70. },
  71. // Every time the template prop changes, I recompile it to update the DOM
  72. template: {
  73. immediate: true, // makes the watcher fire on first render, too.
  74. handler() {
  75. if (this.template) {
  76. var res = Vue.compile(this.template);
  77. this.templateRender = res.render;
  78. // staticRenderFns belong into $options,
  79. // appearantly
  80. this.$options.staticRenderFns = []
  81. // clean the cache of static elements
  82. // this is a cache with the results from the staticRenderFns
  83. this._staticTrees = []
  84. // Fill it with the new staticRenderFns
  85. for (var i in res.staticRenderFns) {
  86. //staticRenderFns.push(res.staticRenderFns[i]);
  87. this.$options.staticRenderFns.push(res.staticRenderFns[i])
  88. }
  89. }
  90. }
  91. }
  92. }
  93. });
  94. appProductFamily = new Vue({
  95. el: '#lc-product-family-edit',
  96. delimiters: ['${', '}'],
  97. data: {
  98. indexFormProduct: 0,
  99. taxRateValue: -1,
  100. formProductArray: [],
  101. currentSection: 'general',
  102. sectionsArray: [
  103. {
  104. name: 'general',
  105. nameDisplay: 'Général'
  106. },
  107. {
  108. name: 'price',
  109. nameDisplay: 'Prix / stock'
  110. },
  111. {
  112. name: 'products',
  113. nameDisplay: 'Déclinaisons'
  114. }
  115. ]
  116. },
  117. methods: {
  118. changeSection: function (section) {
  119. this.currentSection = section.name;
  120. },
  121. setTaxRateValue: function()  {
  122. this.taxRateValue = $('#productfamily_taxRate').find('option:selected').data('tax-rate-value') ;
  123. },
  124. addFormProduct: function() {
  125. var collectionHolder = $('ul.products');
  126. var prototype = collectionHolder.data('prototype');
  127. var newForm = prototype;
  128. newForm = newForm.replace(/__name__/g, this.indexFormProduct);
  129. this.formProductArray.push(newForm) ;
  130. this.indexFormProduct ++ ;
  131. },
  132. deleteFormProduct: function(key) {
  133. this.formProductArray.splice(key, 1) ;
  134. }
  135. },
  136. mounted() {
  137. }
  138. });