Advertisement
Guest User

Untitled

a guest
Aug 18th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. <script>
  2.  
  3. export default {
  4.  
  5. props: ['value'],
  6. watch: {
  7. value: function(value) {
  8. this.relaod(value);
  9. this.fetchSubCategories(value);
  10. }
  11. },
  12. methods: {
  13. relaod: function(value) {
  14.  
  15. var select = $(this.$el);
  16.  
  17. select.val(value || this.value);
  18. select.material_select('destroy');
  19. select.material_select();
  20. },
  21. fetchSubCategories: function(value) {
  22. var mdl = this;
  23. var catID = value || this.value;
  24.  
  25. mdl.$emit("reset-subcats");
  26.  
  27. if (catID) {
  28.  
  29. axios.get(API.URL + '/subcategories/' + catID)
  30. .then(function(response) {
  31. response = response.data.subcatData;
  32. response.unshift({
  33. subcat_id: '0',
  34. subcategory_name: 'All Subcategories'
  35. });
  36. mdl.$emit("update-subcats", response);
  37.  
  38. $('.subdropdown').fadeIn();
  39. })
  40. .catch(function(error) {
  41. if (error.response.data) {
  42.  
  43. swal({
  44. title: "Something went wrong",
  45. text: "Please try again",
  46. type: "error",
  47. html: false
  48. });
  49.  
  50. }
  51. });
  52. }
  53. } else {
  54. if ($('.subdropdown').is(":visible") == true) {
  55. $('.subdropdown').fadeOut();
  56. }
  57. }
  58. }
  59. },
  60. mounted: function() {
  61.  
  62. var vm = this;
  63. var select = $(this.$el);
  64.  
  65. select
  66. .val(this.value)
  67. .on('change', function() {
  68. vm.$emit('input', this.value);
  69. });
  70.  
  71. select.material_select();
  72. },
  73. updated: function() {
  74.  
  75. this.relaod();
  76. },
  77. destroyed: function() {
  78.  
  79. $(this.$el).material_select('destroy');
  80. }
  81. }
  82. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement