ContractsTab.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <template>
  2. <div class="q-pa-md">
  3. <DefaultTable
  4. ref="tableRef"
  5. :columns="columns"
  6. :api-call="loadContracts"
  7. :show-search-field="true"
  8. :add-item="true"
  9. :female="false"
  10. title="Contratos"
  11. description="Contratos"
  12. @on-add-item="openCreateDialog"
  13. >
  14. <template #body-cell-contract_dates="{ row }">
  15. <q-td>{{ formatDateYMDtoDMY(row.start_date) }} - {{ formatDateYMDtoDMY(row.end_date) }}</q-td>
  16. </template>
  17. <template #body-cell-tbr_fixed_value="{ row }">
  18. <q-td>{{ formatToBRLCurrency(row.tbr_fixed_value) }}</q-td>
  19. </template>
  20. <template #body-cell-actions="{ row: contract }">
  21. <q-td align="center">
  22. <div class="row no-wrap" style="gap: 4px">
  23. <q-btn
  24. flat
  25. round
  26. dense
  27. icon="mdi-file-edit-outline"
  28. size="sm"
  29. @click="openEditDialog(contract)"
  30. />
  31. <q-btn
  32. flat
  33. round
  34. dense
  35. icon="mdi-trash-can-outline"
  36. size="sm"
  37. color="negative"
  38. @click="confirmDelete(contract)"
  39. />
  40. </div>
  41. </q-td>
  42. </template>
  43. </DefaultTable>
  44. </div>
  45. </template>
  46. <script setup>
  47. import { ref, defineAsyncComponent } from "vue";
  48. import { useQuasar } from "quasar";
  49. import DefaultTable from "src/components/defaults/DefaultTable.vue";
  50. import {
  51. getFranchiseeContractsByUnit,
  52. deleteFranchiseeContract,
  53. } from "src/api/franchisee_contract";
  54. import { formatDateYMDtoDMY, formatToBRLCurrency } from "src/helpers/utils";
  55. const CreateContractDialog = defineAsyncComponent(
  56. () => import("src/pages/unit/components/CreateContractDialog.vue"),
  57. );
  58. const EditContractDialog = defineAsyncComponent(
  59. () => import("src/pages/unit/components/EditContractDialog.vue"),
  60. );
  61. const props = defineProps({
  62. unitId: {
  63. type: Number,
  64. default: null,
  65. },
  66. });
  67. const $q = useQuasar();
  68. const tableRef = ref(null);
  69. const loadContracts = () => getFranchiseeContractsByUnit(props.unitId);
  70. function openCreateDialog() {
  71. $q.dialog({
  72. component: CreateContractDialog,
  73. componentProps: { unitId: props.unitId },
  74. }).onOk(() => {
  75. tableRef.value?.refresh();
  76. });
  77. }
  78. function openEditDialog(contract) {
  79. $q.dialog({
  80. component: EditContractDialog,
  81. componentProps: { unitId: props.unitId, contract },
  82. }).onOk(() => {
  83. tableRef.value?.refresh();
  84. });
  85. }
  86. function confirmDelete(contract) {
  87. $q.dialog({
  88. title: "Excluir contrato",
  89. message: `Deseja excluir o contrato #${contract.protocol}?`,
  90. ok: { color: "negative", label: "Excluir" },
  91. cancel: { color: "primary", outline: true, label: "Cancelar" },
  92. }).onOk(async () => {
  93. await deleteFranchiseeContract(contract.id);
  94. tableRef.value?.refresh();
  95. });
  96. }
  97. const columns = [
  98. {
  99. name: "protocol",
  100. label: "Contrato",
  101. field: "protocol",
  102. align: "left",
  103. },
  104. {
  105. name: "contract_dates",
  106. label: "Data Inicial - Final",
  107. field: "start_date",
  108. align: "left",
  109. },
  110. {
  111. name: "tbr_fixed_value",
  112. label: "TBR",
  113. field: "tbr_fixed_value",
  114. align: "left",
  115. },
  116. {
  117. name: "actions",
  118. label: "Ações",
  119. field: "actions",
  120. align: "center",
  121. },
  122. ];
  123. </script>