CustomSchedulesPage.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <template>
  2. <q-page>
  3. <DefaultHeaderPage />
  4. <DefaultTable
  5. ref="tableRef"
  6. :columns="columns"
  7. :loading="loading"
  8. :api-call="getCustomSchedules"
  9. :add-button-label="$t('opportunities.add')"
  10. :empty-message="$t('opportunities.empty_state')"
  11. :delete-function="deleteCustomSchedule"
  12. :mostrar-selecao-de-colunas="false"
  13. :mostrar-botao-fullscreen="false"
  14. :mostrar-toggle-inativos="false"
  15. :open-item="true"
  16. @on-row-click="onRowClick"
  17. @on-add-item="onAddItem"
  18. >
  19. <template #body-cell-status="template_props">
  20. <q-td :props="template_props">
  21. <q-chip
  22. :label="$t(`schedules.statuses.${template_props.row.schedule?.status}`)"
  23. :color="getStatusColor(template_props.row.schedule?.status)"
  24. text-color="white"
  25. size="sm"
  26. />
  27. </q-td>
  28. </template>
  29. <template #body-cell-price_range="template_props">
  30. <q-td :props="template_props">
  31. {{ formatToBRLCurrency(template_props.row.min_price) }}
  32. {{ formatToBRLCurrency(template_props.row.max_price) }}
  33. </q-td>
  34. </template>
  35. <template #body-cell-period="template_props">
  36. <q-td :props="template_props">
  37. {{ template_props.row.schedule?.period_type }}{{ $t('schedules.hours') }}
  38. </q-td>
  39. </template>
  40. </DefaultTable>
  41. </q-page>
  42. </template>
  43. <script setup>
  44. import { ref, computed } from 'vue'
  45. import { useI18n } from 'vue-i18n'
  46. import { useQuasar } from 'quasar'
  47. import { getCustomSchedules, deleteCustomSchedule } from 'src/api/customSchedule'
  48. import DefaultTable from 'src/components/defaults/DefaultTable.vue'
  49. import AddEditCustomScheduleDialog from './components/AddEditCustomScheduleDialog.vue'
  50. import { formatToBRLCurrency } from 'src/helpers/utils'
  51. import DefaultHeaderPage from 'src/components/layout/DefaultHeaderPage.vue'
  52. const { t } = useI18n()
  53. const $q = useQuasar()
  54. const tableRef = ref(null)
  55. const loading = ref(false)
  56. const columns = computed(() => [
  57. {
  58. name: 'id',
  59. label: 'ID',
  60. align: 'left',
  61. field: row => row.schedule?.id,
  62. sortable: true
  63. },
  64. {
  65. name: 'client_name',
  66. label: t('opportunities.client'),
  67. align: 'left',
  68. field: row => row.schedule?.client_name,
  69. sortable: true
  70. },
  71. {
  72. name: 'service_type',
  73. label: t('opportunities.service_type'),
  74. align: 'left',
  75. field: 'service_type_name',
  76. sortable: true
  77. },
  78. {
  79. name: 'date',
  80. label: t('opportunities.date'),
  81. align: 'left',
  82. field: row => row.schedule?.date,
  83. sortable: true,
  84. },
  85. {
  86. name: 'period',
  87. label: t('opportunities.period'),
  88. align: 'center',
  89. field: row => row.schedule?.period_type + ' h',
  90. sortable: true
  91. },
  92. {
  93. name: 'price_range',
  94. label: t('opportunities.price_range'),
  95. align: 'right',
  96. field: row => `${formatToBRLCurrency(row.min_price)} - ${formatToBRLCurrency(row.max_price)}`,
  97. sortable: false
  98. },
  99. {
  100. name: 'status',
  101. label: t('common.terms.status'),
  102. align: 'center',
  103. field: row => t(`schedules.statuses.${row.schedule?.status}`),
  104. sortable: true
  105. },
  106. {
  107. name: 'actions',
  108. label: t('common.terms.actions'),
  109. align: 'center',
  110. field: 'actions'
  111. }
  112. ])
  113. const getStatusColor = (status) => {
  114. const colors = {
  115. pending: 'orange',
  116. accepted: 'blue',
  117. rejected: 'red',
  118. paid: 'green',
  119. cancelled: 'grey',
  120. started: 'purple',
  121. finished: 'teal'
  122. }
  123. return colors[status] || 'grey'
  124. }
  125. const onAddItem = () => {
  126. $q.dialog({
  127. component: AddEditCustomScheduleDialog,
  128. componentProps: {
  129. title: () => t('opportunities.add')
  130. }
  131. }).onOk((success) => {
  132. if (success) {
  133. tableRef.value.refresh()
  134. }
  135. })
  136. }
  137. const onRowClick = ({ row }) => {
  138. $q.dialog({
  139. component: AddEditCustomScheduleDialog,
  140. componentProps: {
  141. opportunity: row,
  142. title: () => t('opportunities.edit')
  143. }
  144. }).onOk((success) => {
  145. if (success) {
  146. tableRef.value.refresh()
  147. }
  148. })
  149. }
  150. </script>