EdIndexes.vue 3.5 KB

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