EdIndexes.vue 3.4 KB

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