PaymentsPage.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <template>
  2. <q-page class="q-pa-md">
  3. <DefaultHeaderPage />
  4. <DefaultTable
  5. ref="tableRef"
  6. :columns="columns"
  7. :api-call="getPayments"
  8. :add-item="false"
  9. :open-item="true"
  10. @on-row-click="onRowClick"
  11. >
  12. <template #body-cell-status="templateProps">
  13. <q-td :props="templateProps">
  14. <q-chip
  15. :label="statusLabel(templateProps.row.status)"
  16. :color="paymentStatusColor(templateProps.row.status)"
  17. text-color="white"
  18. size="sm"
  19. />
  20. </q-td>
  21. </template>
  22. <template #body-cell-payment_method="templateProps">
  23. <q-td :props="templateProps">
  24. {{ paymentMethodLabel(templateProps.row.payment_method) }}
  25. </q-td>
  26. </template>
  27. <template #body-cell-gross_amount="templateProps">
  28. <q-td :props="templateProps">
  29. {{ formatToBRLCurrency(templateProps.row.gross_amount) }}
  30. </q-td>
  31. </template>
  32. <template #body-cell-created_at="templateProps">
  33. <q-td :props="templateProps">
  34. {{ formatDateTime(templateProps.row.created_at) }}
  35. </q-td>
  36. </template>
  37. </DefaultTable>
  38. </q-page>
  39. </template>
  40. <script setup>
  41. import { computed, defineAsyncComponent, ref } from "vue";
  42. import { useI18n } from "vue-i18n";
  43. import { useQuasar } from "quasar";
  44. import { getPayments } from "src/api/payment";
  45. import DefaultHeaderPage from "src/components/layout/DefaultHeaderPage.vue";
  46. import DefaultTable from "src/components/defaults/DefaultTable.vue";
  47. import { formatToBRLCurrency } from "src/helpers/utils";
  48. import { format, parseISO } from "date-fns";
  49. const ViewPaymentDialog = defineAsyncComponent(
  50. () => import("src/pages/payment/components/ViewPaymentDialog.vue"),
  51. );
  52. const { t } = useI18n();
  53. const $q = useQuasar();
  54. const tableRef = ref(null);
  55. // const idLabel = "ID";
  56. const columns = computed(() => [
  57. // {
  58. // name: "id",
  59. // label: idLabel,
  60. // align: "left",
  61. // field: "id",
  62. // required: true,
  63. // sortable: true,
  64. // },
  65. {
  66. name: "schedule_id",
  67. label: t("payments.schedule_id"),
  68. align: "left",
  69. field: (row) => formatByType(row),
  70. sortable: true,
  71. },
  72. {
  73. name: "client_name",
  74. label: t("payments.client"),
  75. align: "left",
  76. field: (row) => row.client_name || row.client_id || "-",
  77. sortable: true,
  78. },
  79. {
  80. name: "provider_name",
  81. label: t("payments.provider"),
  82. align: "left",
  83. field: (row) => row.provider_name || row.provider_id || "-",
  84. sortable: true,
  85. },
  86. {
  87. name: "payment_method",
  88. label: t("payments.payment_method"),
  89. align: "left",
  90. field: "payment_method",
  91. format: paymentMethodLabel,
  92. sortable: true,
  93. },
  94. {
  95. name: "status",
  96. label: t("common.terms.status"),
  97. align: "center",
  98. field: "status",
  99. format: statusLabel,
  100. sortable: true,
  101. },
  102. {
  103. name: "gross_amount",
  104. label: t("payments.gross_amount"),
  105. align: "right",
  106. field: "gross_amount",
  107. format: formatToBRLCurrency,
  108. sortable: true,
  109. },
  110. {
  111. name: "created_at",
  112. label: t("common.terms.created_at"),
  113. align: "left",
  114. field: "created_at",
  115. format: formatDateTime,
  116. sortable: true,
  117. },
  118. ]);
  119. function paymentMethodLabel(method) {
  120. return method ? t(`payments.payment_methods.${method}`) : "-";
  121. }
  122. function statusLabel(status) {
  123. return status ? t(`payments.statuses.${status}`) : "-";
  124. }
  125. function paymentStatusColor(status) {
  126. const colors = {
  127. pending: "orange",
  128. processing: "blue",
  129. authorized: "indigo",
  130. paid: "green",
  131. failed: "negative",
  132. cancelled: "grey",
  133. };
  134. return colors[status] || "grey";
  135. }
  136. function formatDateTime(value) {
  137. return value ? format(parseISO(value), "dd/MM/yyyy HH:mm") : "-";
  138. }
  139. const onRowClick = ({ row }) => {
  140. $q.dialog({
  141. component: ViewPaymentDialog,
  142. componentProps: {
  143. payment: row,
  144. title: () => t("payments.view_title"),
  145. },
  146. });
  147. };
  148. const formatByType = (row) => {
  149. if (row.schedules[0]?.schedule_type === 'custom') {
  150. return t('ui.navigation.opportunities') + ' - ' + row.schedules[0]?.id
  151. } else if (row.schedules[0]?.schedule_type === 'default') {
  152. return t('ui.navigation.schedules') + ' - ' + row.schedules[0]?.id
  153. }
  154. }
  155. </script>