ConcernementMapPopup.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <script>
  2. // import { RouterLink, RouterView } from 'vue-router'
  3. import { mapState, mapActions } from 'pinia'
  4. // import { UserStore } from '@/stores/user'
  5. import { ConcernementsStore } from '@/stores/concernements'
  6. export default {
  7. name: 'concernementMapPopup',
  8. props: ['infos'],
  9. data() {
  10. return {
  11. dom: null,
  12. type: null,
  13. concernement: null,
  14. entite: null,
  15. besoin: null,
  16. reponse: null
  17. }
  18. },
  19. created () {
  20. // console.log(`popup created type: ${this.infos.type}`, this.infos);
  21. if (this.infos.type === 'concernement') {
  22. this.concernement = this.concernementsByID[this.infos.id];
  23. } else if(this.infos.type === 'entite') {
  24. this.entite = this.allEntitesById[this.infos.id];
  25. } else if (this.infos.type === 'besoin') {
  26. this.besoin = this.allBesoinsById[this.infos.id];
  27. } else if (this.infos.type === 'reponse') {
  28. for (let i = 0; i < this.allBesoinsById[this.infos.bid].reponses.length; i++) {
  29. if (this.allBesoinsById[this.infos.bid].reponses[i].id === this.infos.id) {
  30. this.reponse = this.allBesoinsById[this.infos.bid].reponses[i];
  31. break;
  32. }
  33. }
  34. }
  35. },
  36. mounted () {
  37. // console.log('APP onMounted')
  38. this.dom = this.$refs['map-popup'];
  39. window.addEventListener('mousemove', this.onMousemove);
  40. },
  41. computed: {
  42. ...mapState(ConcernementsStore,['concernements']),
  43. ...mapState(ConcernementsStore,['concernementsByID']),
  44. ...mapState(ConcernementsStore,['allEntitesById']),
  45. ...mapState(ConcernementsStore,['allBesoinsById'])
  46. },
  47. watch: {
  48. infos: {
  49. handler (n, o){
  50. if (n.type === 'concernement') {
  51. this.concernement = this.concernementsByID[n.id];
  52. } else if(n.type === 'entite') {
  53. this.entite = this.allEntitesById[this.infos.id];
  54. } else if (n.type === 'besoin') {
  55. this.besoin = this.allBesoinsById[this.infos.id];
  56. } else if (n.type === 'reponse') {
  57. }
  58. },
  59. deep: true
  60. },
  61. },
  62. methods: {
  63. onMousemove(e){
  64. // console.log(`popup move type: ${this.infos.type}`);
  65. let v = "top";
  66. let h = "right";
  67. if (e.clientX + this.dom.clientWidth > document.body.clientWidth) {
  68. h = "left";
  69. } else {
  70. h = "right";
  71. }
  72. if (e.clientY - this.dom.clientHeight < 0) {
  73. v = "bottom";
  74. } else {
  75. v = "top";
  76. }
  77. this.dom.setAttribute("pos", `${v}-${h}`);
  78. switch (h) {
  79. case "right":
  80. this.dom.style.left = `${e.clientX+2}px`;
  81. break;
  82. case "left":
  83. this.dom.style.left = `${e.clientX - this.dom.clientWidth-2}px`;
  84. break;
  85. }
  86. switch (v) {
  87. case "top":
  88. this.dom.style.top = `${e.clientY - this.dom.clientHeight-2}px`;
  89. break;
  90. case "bottom":
  91. this.dom.style.top = `${e.clientY+2}px`;
  92. break;
  93. }
  94. }
  95. },
  96. components: {
  97. }
  98. }
  99. </script>
  100. <template>
  101. <div id="map-popup" ref="map-popup">
  102. <div class="popup-content-wrapper">
  103. <section v-if="infos.type === 'concernement'" class="concernement-map-popup">
  104. <h1>{{ concernement.title }}</h1>
  105. <ul class="icons">
  106. <li v-if="concernement.has_puissancedagir" ><span class="icon puissancedagir"></span></li>
  107. <li v-if="concernement.has_proximite" ><span class="icon proximite"></span></li>
  108. <li v-if="concernement.has_superposition" ><span class="icon superposition"></span></li>
  109. <li v-if="concernement.has_agissantes" ><span class="icon action"></span></li>
  110. <li v-if="concernement.has_doleance" ><span class="icon doleancer"></span></li>
  111. </ul>
  112. </section>
  113. <section v-if="infos.type === 'entite'" class="entite-map-popup">
  114. <h1>{{ entite.entite.title }}</h1>
  115. </section>
  116. <section v-if="infos.type === 'besoin'" class="besoin-map-popup">
  117. <div v-html="besoin.description"></div>
  118. </section>
  119. <section v-if="infos.type === 'reponse'" class="reponse-map-popup">
  120. <div v-if="reponse.qui"><label>Qui</label><p v-html="reponse.qui"/></div>
  121. <div v-if="reponse.quoi"><label>Quoi</label><p v-html="reponse.quoi"/></div>
  122. <div v-if="reponse.ou"><label>Où</label><p v-html="reponse.ou"/></div>
  123. <div v-if="reponse.avec"><label>Avec</label><p v-html="reponse.avec"/></div>
  124. </section>
  125. </div>
  126. </div>
  127. </template>
  128. <style lang="scss" scoped>
  129. </style>