Guest User

Untitled

a guest
Aug 14th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.78 KB | None | 0 0
  1. <div class="form-filter">
  2. <select name="type" v-model="filter_unit" v-on:change="onSelectUnitChange">
  3. <option value="metric">Metric</option>
  4. <option value="standard">Standard</option>
  5. </select>
  6. </div><!-- /filter -->
  7.  
  8. <table style="text-align: center;">
  9. <thead>
  10. <tr>
  11. <th v-for="column in columns">
  12. <a
  13. href="#"
  14. v-on:click="sort(column.shortcode)">{{column.label}}
  15. </a>
  16. </th>
  17. </tr>
  18. </thead>
  19. <tbody>
  20. <tr v-for="(product) in showProducts">
  21. <td>{{product.pn}}</td>
  22. <td>{{product.od}}</td>
  23. <td>{{product.id}}</td>
  24. <td>{{product.thickness}}</td>
  25. <td>{{product.lo}}</td>
  26. <td>{{product.weight}}</td>
  27. </tr>
  28. </tbody>
  29. </table>
  30. </div><!-- /app -->
  31.  
  32. var vm = new Vue({
  33. el: '#app',
  34. data: {
  35. currentSort: 'pn',
  36. currentSortDir: 'asc',
  37. category: 'all',
  38. filter_unit: 'metric',
  39. search: '',
  40. columns: [
  41. { label: 'P/N', shortcode: 'pn' },
  42. { label: 'OD (De,mm)', shortcode: 'od' },
  43. { label: 'ID (De,mm)', shortcode: 'id' },
  44. { label: 'Thickness (De,mm)', shortcode: 'thickness' },
  45. { label: 'LO', shortcode: 'lo' },
  46. { label: 'Weight (kg/1000)', shortcode: 'weight' },
  47. ], // columns
  48. products: [
  49. {
  50. pn: 170158,
  51. od: 13,
  52. id: .44,
  53. thickness: 1,
  54. lo: .45,
  55. weight: .7,
  56. category: 'chrome',
  57. },{
  58. pn: 1803561,
  59. od: 12,
  60. id: .8,
  61. thickness: .7,
  62. lo: .11,
  63. weight: .5,
  64. category: 'chrome',
  65. },{
  66. pn: 170149,
  67. od: 9,
  68. id: .64,
  69. thickness: .6,
  70. lo: .75,
  71. weight: .3,
  72. category: 'stainless',
  73. },{
  74. pn: 150149,
  75. od: 15,
  76. id: .22,
  77. thickness: .3,
  78. lo: .55,
  79. weight: .9,
  80. category: 'chrome',
  81. },
  82. ], // products
  83. },
  84. computed: {
  85. showProducts(){
  86. return this.products
  87. .filter(a => {
  88. return (a.pn + '').includes(this.search)
  89. })
  90. .sort((a, b) => {
  91. if (this.currentSortDir === 'asc') {
  92. //console.log( this.currentSort );
  93. return a[this.currentSort] >= b[this.currentSort];
  94. }
  95. return a[this.currentSort] <= b[this.currentSort];
  96. })
  97. }
  98. },
  99. methods: {
  100. sort:function(col) {
  101. // if you click the same label twice
  102. if(this.currentSort == col){
  103. // sort by asc
  104. this.currentSortDir = this.currentSortDir === 'asc' ? 'desc' : 'asc';
  105. }else{
  106. this.currentSort = col;
  107. }
  108. }, // sort
  109.  
  110. onSelectUnitChange:function(){
  111. if(this.filter_unit == 'standard'){
  112. // change values of OD using this equation. current OD value * 0.0393701
  113. // change table header OD(De,mm) to OD(De,in)
  114. // also will be doing a similar process to ID and Thickness
  115. console.log('standard change');
  116. }
  117. },
  118.  
  119. }, // methods
  120. }); // vue
  121.  
  122. filteredProducts() {
  123. let filteredProducts = []
  124. let _product
  125. this.showProducts.forEach(product => {
  126. _product = product
  127. // do the logic here
  128. if (this.filter_unit === 'metric') {
  129. _product.displayWeight = _product.weight * 25
  130. } else if (this.filter_unit === 'standard') {
  131. _product.displayWeight = _product.weight + 10
  132. }
  133. filteredProducts.push(_product)
  134. })
  135. return filteredProducts
  136. }
  137.  
  138. onSelectUnitChange:function(){
  139. if(this.filter_unit == 'standard'){
  140. this.products.forEach(p => {
  141. p.od *= 0.0393701
  142. p.id *= 0.0393701
  143. p.thickness *= 0.0393701
  144. })
  145. this.columns[1].label = "OD(De,in)"
  146. this.columns[2].label = "ID(De,in)"
  147. this.columns[3].label = "Thickness(De,in)"
  148. } else {
  149. this.products.forEach(p => {
  150. p.od /= 0.0393701
  151. p.id /= 0.0393701
  152. p.thickness /= 0.0393701
  153. })
  154. this.columns[1].label = "OD(De,mm)"
  155. this.columns[2].label = "ID(De,mm)"
  156. this.columns[3].label = "Thickness(De,mm)"
  157. }
  158. }
Add Comment
Please, Sign In to add comment