RelatoriosPage.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. <template>
  2. <div>
  3. <DefaultHeaderPage>
  4. <template #after>
  5. <q-btn
  6. unelevated
  7. class="btn-export"
  8. :label="$t('relatorio.exportar_excel')"
  9. icon="mdi-download"
  10. padding="8px 16px"
  11. :loading="exportLoading"
  12. @click="onExport"
  13. />
  14. </template>
  15. </DefaultHeaderPage>
  16. <div class="relatorio-tabs-row q-mb-md">
  17. <div
  18. v-for="tab in tabs"
  19. :key="tab.name"
  20. class="relatorio-tab-card"
  21. :class="{ active: activeTab === tab.name }"
  22. @click="selectTab(tab.name)"
  23. >
  24. <q-icon :name="tab.icon" size="22px" color="violet-normal" />
  25. <div class="tab-body">
  26. <span class="tab-count">
  27. {{ counters[tab.counterKey] !== undefined ? counters[tab.counterKey] : '—' }}
  28. </span>
  29. <span class="tab-label">{{ tab.label }}</span>
  30. </div>
  31. </div>
  32. </div>
  33. <div v-if="activeTab === 'novos-associados'">
  34. <DefaultTableServerSide
  35. ref="tableRef"
  36. :key="tableKey"
  37. :columns="columnsNovosAssociados"
  38. :api-call="getNovoAssociadosPaginated"
  39. :add-item="false"
  40. :show-search-field="true"
  41. />
  42. </div>
  43. <div v-else-if="activeTab === 'contatos-associados'">
  44. <DefaultTableServerSide
  45. ref="tableRef"
  46. :key="tableKey"
  47. :columns="columnsContatos"
  48. :api-call="getContatosAssociadosPaginated"
  49. :add-item="false"
  50. :show-search-field="true"
  51. />
  52. </div>
  53. <div v-else-if="activeTab === 'exclusoes-mes'">
  54. <DefaultTableServerSide
  55. ref="tableRef"
  56. :key="tableKey"
  57. :columns="columnsExclusoes"
  58. :api-call="getExclusoesMesPaginated"
  59. :add-item="false"
  60. :show-search-field="true"
  61. />
  62. </div>
  63. </div>
  64. </template>
  65. <script setup>
  66. import { ref, computed, onMounted, useTemplateRef } from "vue";
  67. import { useQuasar } from "quasar";
  68. import { useI18n } from "vue-i18n";
  69. import DefaultHeaderPage from "src/components/layout/DefaultHeaderPage.vue";
  70. import DefaultTableServerSide from "src/components/defaults/DefaultTableServerSide.vue";
  71. import {
  72. getRelatorioCounters,
  73. getNovoAssociadosPaginated,
  74. getContatosAssociadosPaginated,
  75. getExclusoesMesPaginated,
  76. exportRelatorio,
  77. } from "src/api/relatorio.js";
  78. const $q = useQuasar();
  79. const { t } = useI18n();
  80. const activeTab = ref("novos-associados");
  81. const tableKey = ref(0);
  82. const exportLoading = ref(false);
  83. const tableRef = useTemplateRef("tableRef");
  84. const counters = ref({
  85. novos_associados: undefined,
  86. contatos: undefined,
  87. exclusoes_mes: undefined,
  88. });
  89. const tabs = computed(() => [
  90. {
  91. name: "novos-associados",
  92. label: t("relatorio.novos_associados"),
  93. icon: "mdi-account-multiple-outline",
  94. counterKey: "novos_associados",
  95. },
  96. {
  97. name: "contatos-associados",
  98. label: t("relatorio.contatos"),
  99. icon: "mdi-phone-outline",
  100. counterKey: "contatos",
  101. },
  102. {
  103. name: "exclusoes-mes",
  104. label: t("relatorio.exclusoes_mes"),
  105. icon: "mdi-account-remove-outline",
  106. counterKey: "exclusoes_mes",
  107. },
  108. ]);
  109. const columnsNovosAssociados = computed(() => [
  110. {
  111. name: "name",
  112. label: t("common.terms.name"),
  113. field: "name",
  114. align: "left",
  115. sortable: true,
  116. },
  117. {
  118. name: "cpf",
  119. label: t("associado.cpf"),
  120. field: "cpf",
  121. align: "left",
  122. sortable: false,
  123. },
  124. {
  125. name: "created_at",
  126. label: t("relatorio.col.cadastro"),
  127. field: "created_at",
  128. align: "left",
  129. sortable: false,
  130. },
  131. ]);
  132. const columnsContatos = computed(() => [
  133. {
  134. name: "name",
  135. label: t("common.terms.name"),
  136. field: "name",
  137. align: "left",
  138. sortable: true,
  139. },
  140. {
  141. name: "phone",
  142. label: t("associado.phone"),
  143. field: "phone",
  144. align: "left",
  145. sortable: false,
  146. },
  147. {
  148. name: "email",
  149. label: t("associado.email"),
  150. field: "email",
  151. align: "left",
  152. sortable: false,
  153. },
  154. ]);
  155. const columnsExclusoes = computed(() => [
  156. {
  157. name: "name",
  158. label: t("common.terms.name"),
  159. field: "name",
  160. align: "left",
  161. sortable: true,
  162. },
  163. {
  164. name: "cpf",
  165. label: t("associado.cpf"),
  166. field: "cpf",
  167. align: "left",
  168. sortable: false,
  169. },
  170. {
  171. name: "excluded_at",
  172. label: t("relatorio.col.exclusao"),
  173. field: "excluded_at",
  174. align: "left",
  175. sortable: false,
  176. },
  177. ]);
  178. const selectTab = (name) => {
  179. activeTab.value = name;
  180. tableKey.value++;
  181. };
  182. const onExport = async () => {
  183. exportLoading.value = true;
  184. try {
  185. const search = tableRef.value?.getFilter() || undefined;
  186. await exportRelatorio(activeTab.value, search);
  187. } catch {
  188. $q.notify({ type: "negative", message: t("http.errors.failed") });
  189. } finally {
  190. exportLoading.value = false;
  191. }
  192. };
  193. onMounted(async () => {
  194. try {
  195. const data = await getRelatorioCounters();
  196. counters.value = data;
  197. } catch {
  198. // counters permanecem como undefined, exibindo '—'
  199. }
  200. });
  201. </script>
  202. <style lang="scss" scoped>
  203. @use "src/css/quasar.variables.scss" as vars;
  204. .relatorio-tabs-row {
  205. display: flex;
  206. gap: 12px;
  207. }
  208. .relatorio-tab-card {
  209. flex: 1;
  210. display: flex;
  211. align-items: center;
  212. gap: 12px;
  213. padding: 14px 20px;
  214. border-radius: 8px;
  215. border: 1.5px solid vars.$color-border;
  216. background: vars.$surface;
  217. cursor: pointer;
  218. transition: border-color 0.15s, background 0.15s;
  219. user-select: none;
  220. &:hover:not(.active) {
  221. border-color: vars.$violet-light-active;
  222. background: vars.$violet-light;
  223. }
  224. &.active {
  225. border-color: vars.$violet-normal;
  226. background: vars.$violet-light;
  227. }
  228. }
  229. .tab-body {
  230. display: flex;
  231. align-items: baseline;
  232. gap: 8px;
  233. }
  234. .tab-count {
  235. font-size: 1.375rem;
  236. font-weight: 700;
  237. color: vars.$violet-normal;
  238. line-height: 1;
  239. }
  240. .tab-label {
  241. font-size: 0.875rem;
  242. color: vars.$color-text-2;
  243. font-weight: 400;
  244. }
  245. .btn-export {
  246. background: linear-gradient(90deg, #4d1658 0%, #8b30a5 100%) !important;
  247. color: white !important;
  248. border-radius: 8px !important;
  249. }
  250. .btn-export :deep(.q-icon) {
  251. color: white !important;
  252. }
  253. </style>