EdIndexes.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <template>
  2. <div>
  3. <div
  4. v-for="(opts, key) in options"
  5. :key="key"
  6. >
  7. <v-select
  8. :id="key"
  9. type="select"
  10. :placeholder="key"
  11. append-to-body
  12. :calculate-position="dropDownMenuPos"
  13. :options="opts"
  14. :clearable="true"
  15. @input="onClickIndexItem"
  16. >
  17. <template v-slot:option="option">
  18. <span v-html="option.label" />
  19. </template>
  20. </v-select>
  21. </div>
  22. </div>
  23. </template>
  24. <script>
  25. import { createPopper } from '@popperjs/core'
  26. export default {
  27. name: 'EdIndexes',
  28. props: {
  29. indexes: Object
  30. },
  31. data: () => ({
  32. options: {},
  33. persons_selected: '',
  34. objects_selected: '',
  35. places_selected: ''
  36. }),
  37. created () {
  38. this.parseIndexesToOptions()
  39. },
  40. // watch: {
  41. // loadedtextsuuids (n, o) {
  42. // console.log('EdToc watch loadedtxtsuuids', o, n)
  43. // }
  44. // },
  45. methods: {
  46. parseIndexesToOptions () {
  47. console.log('EdIndexes parseIndexesToOptions', this.indexes)
  48. Object.keys(this.indexes).forEach(key => {
  49. // console.log('OPTION', key)
  50. this.options[key] = []
  51. Object.keys(this.indexes[key]).forEach(uuid => {
  52. // console.log('OPTIONS ITEM', key, uuid)
  53. this.options[key].push({
  54. code: uuid,
  55. label: `${this.indexes[key][uuid].title} [${this.indexes[key][uuid].quantity}]`
  56. })
  57. })
  58. if (!this.options[key].length) {
  59. delete this.options[key]
  60. }
  61. })
  62. },
  63. dropDownMenuPos (dropdownList, component, { width }) {
  64. /**
  65. * We need to explicitly define the dropdown width since
  66. * it is usually inherited from the parent with CSS.
  67. */
  68. dropdownList.style.width = width
  69. /**
  70. * Here we position the dropdownList relative to the $refs.toggle Element.
  71. *
  72. * The 'offset' modifier aligns the dropdown so that the $refs.toggle and
  73. * the dropdownList overlap by 1 pixel.
  74. *
  75. * The 'toggleClass' modifier adds a 'drop-up' class to the Vue Select
  76. * wrapper so that we can set some styles for when the dropdown is placed
  77. * above.
  78. */
  79. const popper = createPopper(component.$refs.toggle, dropdownList, {
  80. placement: 'top',
  81. modifiers: [
  82. {
  83. name: 'offset',
  84. options: {
  85. offset: [0, -1]
  86. }
  87. },
  88. {
  89. name: 'toggleClass',
  90. enabled: true,
  91. phase: 'write',
  92. fn ({ state }) {
  93. component.$el.classList.toggle('drop-up', state.placement === 'top')
  94. }
  95. }]
  96. })
  97. /**
  98. * To prevent memory leaks Popper needs to be destroyed.
  99. * If you return function, it will be called just before dropdown is removed from DOM.
  100. */
  101. return () => popper.destroy()
  102. },
  103. onClickIndexItem (o) {
  104. // this.page_selected = o
  105. // this.$emit('onClickPaginationItem', o)
  106. }
  107. }
  108. }
  109. </script>
  110. <style lang="scss" scoped>
  111. </style>