InhabitantClassificationsTab.vue 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <template>
  2. <DefaultTable
  3. v-model:rows="rows"
  4. description="faixas"
  5. title="Faixas"
  6. :add-item="true"
  7. :columns="columns"
  8. :female="true"
  9. :no-api-call="true"
  10. :show-search-field="true"
  11. @on-add-item="onAdd"
  12. >
  13. <template #body-cell-actions="{ row }">
  14. <q-td align="center">
  15. <div class="row no-wrap" style="gap: 4px">
  16. <q-btn
  17. dense
  18. flat
  19. icon="mdi-eye-outline"
  20. round
  21. size="sm"
  22. @click="onView(row)"
  23. />
  24. <q-btn
  25. dense
  26. flat
  27. icon="mdi-file-edit-outline"
  28. round
  29. size="sm"
  30. @click="onEdit(row)"
  31. />
  32. </div>
  33. </q-td>
  34. </template>
  35. </DefaultTable>
  36. </template>
  37. <script setup>
  38. import { getInhabitantClassifications } from "src/api/inhabitant_classification";
  39. import { onMounted, ref } from "vue";
  40. import { useQuasar } from "quasar";
  41. import AddEditInhabitantClassificationDialog from "src/pages/tbr/components/AddEditInhabitantClassificationDialog.vue";
  42. import ViewInhabitantClassificationDialog from "src/pages/tbr/components/ViewInhabitantClassificationDialog.vue";
  43. import DefaultTable from "src/components/defaults/DefaultTable.vue";
  44. const $q = useQuasar();
  45. const rows = ref([]);
  46. const columns = [
  47. { name: "id", label: "ID", field: "id", align: "left" },
  48. {
  49. name: "description",
  50. label: "Descrição",
  51. field: "description",
  52. align: "left",
  53. },
  54. { name: "start", label: "Início", field: "start", align: "left" },
  55. { name: "end", label: "Fim", field: "end", align: "left" },
  56. {
  57. name: "tbr_percentage",
  58. label: "%",
  59. field: "tbr_percentage",
  60. align: "left",
  61. format: (val) => `${(val * 100).toFixed(2)}%`,
  62. },
  63. { name: "actions", label: "Ações", field: "actions", align: "center" },
  64. ];
  65. const loadData = async () => {
  66. rows.value = await getInhabitantClassifications();
  67. };
  68. const onAdd = () => {
  69. $q.dialog({ component: AddEditInhabitantClassificationDialog }).onOk(() =>
  70. loadData(),
  71. );
  72. };
  73. const onEdit = (row) => {
  74. $q.dialog({
  75. component: AddEditInhabitantClassificationDialog,
  76. componentProps: { item: row },
  77. }).onOk(() => loadData());
  78. };
  79. const onView = (row) => {
  80. $q.dialog({
  81. component: ViewInhabitantClassificationDialog,
  82. componentProps: { item: row },
  83. });
  84. };
  85. onMounted(loadData);
  86. </script>