Cotisation.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <!--
  2. Cotisation bar
  3. Barre d'alerte qui s'affiche pour donner l'état de la cotisation
  4. -->
  5. <template>
  6. <main>
  7. <!-- TODO : fonctionnement à valider -->
  8. <UiSystemBar v-if="showCotisationAccess" background-color="ot-info" text-color="ot-white">
  9. <template #bar.text>
  10. <a @click="goOn('AFFILIATION')">
  11. <v-icon small>fas fa-info-circle</v-icon>
  12. {{$t('cotisation_access')}}
  13. </a>
  14. </template>
  15. </UiSystemBar>
  16. <UiSystemBar v-else-if="showUploadInvoice" background-color="ot-info" text-color="ot-white">
  17. <template #bar.text>
  18. <a @click="goOn('INVOICE')">
  19. <v-icon small>fas fa-info-circle</v-icon>
  20. {{$t('upload_cotisation_invoice')}}
  21. </a>
  22. </template>
  23. </UiSystemBar>
  24. <UiSystemBar v-else-if="showRenewInsurance" background-color="ot-info" text-color="ot-white">
  25. <template #bar.text>
  26. <a @click="goOn('INSURANCE')">
  27. <v-icon small>fas fa-info-circle</v-icon>
  28. {{$t('renew_insurance_cmf')}}
  29. </a>
  30. </template>
  31. </UiSystemBar>
  32. <UiSystemBar v-else-if="showInsuranceSubscription" background-color="ot-info" text-color="ot-white">
  33. <template #bar.text>
  34. <a @click="goOn('ADVERTISINGINSURANCE')">
  35. <v-icon small>fas fa-info-circle</v-icon>
  36. {{$t('insurance_cmf_subscription')}}
  37. </a>
  38. </template>
  39. </UiSystemBar>
  40. </main>
  41. </template>
  42. <script setup lang="ts">
  43. import {useOrganizationProfileStore} from "~/stores/organizationProfile";
  44. import {Ref} from "vue";
  45. import Url from "~/services/utils/url";
  46. import {ALERT_STATE_COTISATION} from "~/types/enum/enums";
  47. import {useAsyncData} from "#app";
  48. import {useEntityFetch} from "~/composables/data/useEntityFetch";
  49. import {Cotisation} from "~/models/Organization/Cotisation";
  50. const { fetch } = useEntityFetch()
  51. const organizationProfile = useOrganizationProfileStore()
  52. const runtimeConfig = useRuntimeConfig()
  53. const baseLegacyUrl: string = runtimeConfig.baseUrlAdminLegacy
  54. const cotisationYear: Ref<number | null> = ref(null)
  55. const showCotisationAccess: Ref<Boolean> = ref(false)
  56. const showUploadInvoice: Ref<Boolean> = ref(false)
  57. const showRenewInsurance: Ref<Boolean> = ref(false)
  58. const showInsuranceSubscription: Ref<Boolean> = ref(false)
  59. /**
  60. * On récupère l'état des cotisations via l'API
  61. */
  62. useAsyncData(async () => {
  63. if (!organizationProfile.id) {
  64. throw new Error('missing organization id')
  65. }
  66. const { data: cotisation } = await fetch(Cotisation, organizationProfile.id)
  67. if (cotisation.value !== null) {
  68. cotisationYear.value = cotisation.value.cotisationYear
  69. handleShow(cotisation.value.alertState)
  70. }
  71. })
  72. /**
  73. * Suivant l'état de l'alerte on affiche tel ou tel message
  74. * @param alertState
  75. */
  76. const handleShow = (alertState: ALERT_STATE_COTISATION) =>{
  77. switch(alertState){
  78. case ALERT_STATE_COTISATION.AFFILIATION :
  79. showCotisationAccess.value = true
  80. break;
  81. case ALERT_STATE_COTISATION.INVOICE :
  82. showUploadInvoice.value = true
  83. break;
  84. case ALERT_STATE_COTISATION.INSURANCE :
  85. showRenewInsurance.value = true
  86. break;
  87. case ALERT_STATE_COTISATION.ADVERTISINGINSURANCE :
  88. showInsuranceSubscription.value = true
  89. break;
  90. }
  91. }
  92. /**
  93. * Suivant le bandeau, une action différente est réalisée
  94. * @param type
  95. */
  96. const goOn = (type: ALERT_STATE_COTISATION) => {
  97. switch(type){
  98. case ALERT_STATE_COTISATION.AFFILIATION :
  99. if (!organizationProfile.id) {
  100. throw new Error('missing organization id')
  101. }
  102. window.location.href = Url.join(baseLegacyUrl, '/cotisation/cotisation_steps', organizationProfile.id, 'steps/1')
  103. break;
  104. case ALERT_STATE_COTISATION.INVOICE :
  105. if (!cotisationYear.value) {
  106. throw new Error('no cotisation year defined')
  107. }
  108. window.open(
  109. Url.join(baseLegacyUrl, 'cotisation/invoice', cotisationYear.value),
  110. '_blank'
  111. )
  112. break;
  113. case ALERT_STATE_COTISATION.INSURANCE :
  114. window.location.href = Url.join(baseLegacyUrl, 'cotisation/insuranceedit')
  115. break;
  116. case ALERT_STATE_COTISATION.ADVERTISINGINSURANCE :
  117. window.open(
  118. 'https://www.cmf-musique.org/services/assurances/assurance-de-groupe/',
  119. '_blank'
  120. )
  121. break;
  122. }
  123. }
  124. </script>
  125. <style scoped lang="scss">
  126. .v-system-bar {
  127. font-size: 14px;
  128. }
  129. .v-icon {
  130. height: 20px;
  131. margin: 0 6px;
  132. }
  133. </style>