Advertisement
Guest User

Untitled

a guest
May 22nd, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. import Vue from 'vue'
  2. import Vuetify, {
  3. VCombobox
  4. } from 'vuetify/lib'
  5.  
  6. export default function makeCombobox(repositoryName) {
  7. return Vue.component('combobox', {
  8. inject: [repositoryName],
  9. components: { VCombobox },
  10. render (createElement) {
  11. const self = this
  12.  
  13. return createElement('v-combobox', {
  14. attrs: {
  15. required: true
  16. },
  17. domProps: {
  18. value: self.value
  19. },
  20. props: {
  21. 'item-value': 'id',
  22. 'item-text': 'name',
  23. items: this.items,
  24. loading: this.loading,
  25. label: this.label,
  26. clearable: true,
  27. rules: this.rules
  28. },
  29. on: {
  30. 'update:searchInput': this.handleSearch,
  31. click: this.itemsManagerData,
  32. input: this.handleInput
  33. }
  34. },
  35. [
  36. createElement('span', { slot: 'no-data' }, 'Não tem usuários')
  37. ])
  38. },
  39. props: {
  40. label: {
  41. type: String,
  42. required: true
  43. },
  44. searchApi: {
  45. type: Boolean,
  46. required: true
  47. },
  48. returnObject: {
  49. type: Boolean,
  50. default: false,
  51. required: false
  52. },
  53. rules: {
  54. type: Array,
  55. required: false
  56. }
  57. },
  58. mounted () {
  59. this.itemsManagerData()
  60. },
  61. data () {
  62. return {
  63. id: '',
  64. items: [],
  65. loading: false,
  66. selectedItem: ''
  67. }
  68. },
  69. methods: {
  70. itemsManagerData(search = '') {
  71. return this[repositoryName].get({ search }).then(({data}) => {
  72. this.items = data;
  73. })
  74. .catch((err) => {
  75. console.log(err);
  76. });
  77. },
  78. async handleSearch (name) {
  79. if(!this.searchApi) return
  80.  
  81. this.loading = true
  82. await this.itemsManagerData(name)
  83.  
  84. if(!this.items.length) {
  85. this.loading = 'warning'
  86. } else {
  87. this.loading = false
  88. }
  89. },
  90. handleInput (objectValue) {
  91. if (objectValue && objectValue.hasOwnProperty('id')) {
  92. const returneValue = this.returnObject ? objectValue : objectValue.id
  93.  
  94. this.$emit('input', returneValue)
  95. }
  96. }
  97. }
  98. })
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement