CalendarPage.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  1. <template>
  2. <q-page class="bg-page q-pb-xl">
  3. <div class="calendar-header row items-center bg-white">
  4. <q-space />
  5. <span class="font16 fontbold gradient-diarista">
  6. {{ $t('provider.dashboard.agenda.title') }}
  7. </span>
  8. <q-space />
  9. </div>
  10. <template v-if="loading">
  11. <div
  12. class="row items-center justify-center full-width"
  13. style="height: 60vh"
  14. >
  15. <q-spinner-dots color="primary" />
  16. </div>
  17. </template>
  18. <template v-else>
  19. <div class="q-mt-md q-mx-md">
  20. <div class="section-title font16 fontbold gradient-diarista q-mb-sm">
  21. {{ $t('provider.dashboard.agenda.upcoming_title') }}
  22. </div>
  23. <template v-if="upcomingSchedules.length > 0">
  24. <q-card
  25. v-for="item in upcomingSchedules"
  26. :key="item.id"
  27. :flat="false"
  28. class="calendar-card bg-surface shadow-card q-mb-sm"
  29. >
  30. <q-card-section class="q-pa-sm">
  31. <div class="row no-wrap items-start q-gutter-x-sm">
  32. <q-avatar size="44px">
  33. <img
  34. v-if="item.customer_photo"
  35. :src="item.customer_photo"
  36. style="object-fit:cover"
  37. />
  38. <span
  39. v-else
  40. class="full-width full-height flex flex-center"
  41. style="border-radius:50%"
  42. :style="avatarColors[item.id % avatarColors.length]"
  43. >
  44. {{ getFirstName(item.client_name)?.slice(0, 2).toUpperCase() ?? '??' }}
  45. </span>
  46. </q-avatar>
  47. <div class="col column text-text">
  48. <span class="font12 fontmedium ellipsis">
  49. {{ getFirstName(item.client_name) }}
  50. </span>
  51. <div class="row items-center no-wrap">
  52. <span class="font9 fontbold">
  53. {{ formatWeekday(item.date) }}
  54. </span>
  55. <span class="font9 fontmedium">
  56. {{ ', ' + formatDayMonth(item.date) }}
  57. </span>
  58. </div>
  59. <span class="font9 fontmedium">
  60. {{ $t('common.from') }}
  61. <span class="font9 fontbold">
  62. {{ item.start_time?.slice(0, 5) }}
  63. </span>
  64. {{ $t('common.to') }}
  65. <span class="font9 fontbold">
  66. {{ item.end_time?.slice(0, 5) }}
  67. </span>
  68. </span>
  69. </div>
  70. <div class="col-auto column items-end">
  71. <q-chip
  72. class="status-chip font9"
  73. dense
  74. square
  75. :color="statusBgColor(item.status)"
  76. :label="statusLabel(item.status)"
  77. :text-color="statusTextColor(item.status)"
  78. />
  79. <span class="text-price font10 fontbold">
  80. {{ formatCurrency(item.total_amount) }}
  81. </span>
  82. <span class="text-period font9 fontmedium">
  83. {{ periodLabel(item.period_type) }}
  84. </span>
  85. </div>
  86. </div>
  87. <div class="row items-center no-wrap q-mt-xs">
  88. <span class="type-label text-primary font10 fontmedium">
  89. {{ item.schedule_type === 'custom' ? $t('provider.dashboard.agenda.type_custom') : $t('provider.dashboard.agenda.type_default') }}
  90. </span>
  91. <q-space />
  92. <q-btn
  93. color="primary"
  94. padding="4px 12px"
  95. rounded
  96. size="xs"
  97. unelevated
  98. :label="$t('provider.dashboard.agenda.btn_view_details')"
  99. @click="openDetailsDialog(item)"
  100. />
  101. </div>
  102. </q-card-section>
  103. </q-card>
  104. </template>
  105. <div v-else class="font16 fontbold text-center text-grey-5 q-py-lg">
  106. {{ $t('provider.dashboard.agenda.empty_upcoming') }}
  107. </div>
  108. </div>
  109. <div class="q-mt-lg q-mx-md">
  110. <div class="section-title font16 fontbold gradient-diarista q-mb-sm">
  111. {{ $t('provider.dashboard.agenda.completed_title') }}
  112. </div>
  113. <template v-if="completedSchedules.length > 0">
  114. <q-card
  115. v-for="item in completedSchedules"
  116. :key="item.id"
  117. :flat="false"
  118. class="calendar-card bg-surface shadow-card q-mb-sm"
  119. >
  120. <q-card-section class="q-pa-sm">
  121. <div class="row no-wrap items-start q-gutter-x-sm">
  122. <q-avatar size="44px">
  123. <img
  124. v-if="item.customer_photo"
  125. :src="item.customer_photo"
  126. style="object-fit:cover"
  127. />
  128. <span
  129. v-else
  130. class="full-width full-height flex flex-center"
  131. style="border-radius:50%"
  132. :style="avatarColors[item.id % avatarColors.length]"
  133. >
  134. {{ getFirstName(item.client_name)?.slice(0, 2).toUpperCase() ?? '??' }}
  135. </span>
  136. </q-avatar>
  137. <div class="col column text-text">
  138. <span class="font12 fontmedium ellipsis">
  139. {{ getFirstName(item.client_name) || '—' }}
  140. </span>
  141. <div class="row items-center no-wrap">
  142. <span class="font9 fontbold">
  143. {{ formatWeekday(item.date) }}
  144. </span>
  145. <span class="font9 fontmedium">
  146. {{ ', ' + formatDayMonth(item.date) }}
  147. </span>
  148. </div>
  149. <span class="font9 fontmedium">
  150. {{ $t('common.from') }}
  151. <span class="font9 fontbold">
  152. {{ item.start_time?.slice(0, 5) }}
  153. </span>
  154. {{ $t('common.to') }}
  155. <span class="font9 fontbold">
  156. {{ item.end_time?.slice(0, 5) }}
  157. </span>
  158. </span>
  159. </div>
  160. <div class="col-auto column items-end">
  161. <q-chip
  162. class="status-chip font9"
  163. dense
  164. square
  165. :color="statusBgColor(item.status)"
  166. :label="statusLabel(item.status)"
  167. :text-color="statusTextColor(item.status)"
  168. />
  169. <span class="text-price font10 fontbold">
  170. {{ formatCurrency(item.total_amount) }}
  171. </span>
  172. <span class="text-period font9 fontmedium">
  173. {{ periodLabel(item.period_type) }}
  174. </span>
  175. </div>
  176. </div>
  177. <div class="row items-center no-wrap q-mt-xs">
  178. <span class="type-label text-primary font10 fontmedium">
  179. {{ item.schedule_type === 'custom' ? $t('provider.dashboard.agenda.type_custom') : $t('provider.dashboard.agenda.type_default') }}
  180. </span>
  181. <q-space />
  182. <q-rating
  183. :model-value="item.provider_reviewed ? item.provider_stars : 0"
  184. :max="5"
  185. class="q-mr-sm"
  186. color="amber"
  187. icon="mdi-star-outline"
  188. icon-selected="mdi-star"
  189. readonly
  190. size="14px"
  191. />
  192. <q-btn
  193. v-if="!item.provider_reviewed"
  194. class="btn-rate"
  195. color="secondary"
  196. no-caps
  197. padding="4px 12px"
  198. rounded
  199. size="xs"
  200. unelevated
  201. :label="$t('provider.dashboard.agenda.btn_rate')"
  202. @click="openRatingDialog(item)"
  203. />
  204. </div>
  205. </q-card-section>
  206. </q-card>
  207. </template>
  208. <div v-else class="text-center text-grey-5 q-py-lg">
  209. {{ $t('provider.dashboard.agenda.empty_completed') }}
  210. </div>
  211. </div>
  212. </template>
  213. </q-page>
  214. </template>
  215. <script setup>
  216. import { formatCurrency, getFirstName } from 'src/helpers/utils';
  217. import { getProviderCalendar } from 'src/api/providerCalendar';
  218. import { labelsPeriodTypes } from 'src/helpers/labelsPeriodTypes.js';
  219. import { onMounted, ref } from 'vue';
  220. import { useI18n } from 'vue-i18n';
  221. import { useQuasar } from 'quasar';
  222. import NextSchedulesDetailsDialog from 'src/components/dashboard/NextSchedulesDetailsDialog.vue';
  223. import ScheduleRatingDialog from 'src/components/dashboard/ScheduleRatingDialog.vue';
  224. const $q = useQuasar();
  225. const { t } = useI18n();
  226. const avatarColors = [
  227. { background: '#ffd5df', color: '#932e57' },
  228. { background: '#d7e8ff', color: '#2158a8' },
  229. { background: '#dfd', color: '#2a7a3b' },
  230. { background: '#ffe5cc', color: '#8a4500' },
  231. ];
  232. const loading = ref(true);
  233. const upcomingSchedules = ref([]);
  234. const completedSchedules = ref([]);
  235. //
  236. const parseLocalDate = (dateStr) => {
  237. if (!dateStr) return null;
  238. const s = String(dateStr);
  239. const iso = s.match(/^(\d{4})-(\d{2})-(\d{2})/);
  240. if (iso) return new Date(+iso[1], +iso[2] - 1, +iso[3]);
  241. const dmy = s.match(/^(\d{2})\/(\d{2})\/(\d{4})/);
  242. if (dmy) return new Date(+dmy[3], +dmy[2] - 1, +dmy[1]);
  243. return null;
  244. };
  245. const formatDayMonth = (dateStr) => {
  246. const d = parseLocalDate(dateStr);
  247. if (!d) return '';
  248. return d.toLocaleDateString('pt-BR', { day: '2-digit', month: '2-digit' });
  249. };
  250. const formatWeekday = (dateStr) => {
  251. const d = parseLocalDate(dateStr);
  252. if (!d) return '';
  253. const w = d.toLocaleDateString('pt-BR', { weekday: 'long' });
  254. return w.charAt(0).toUpperCase() + w.slice(1);
  255. };
  256. //
  257. const periodLabel = (periodType) => {
  258. const found = labelsPeriodTypes.find(l => l.value == periodType);
  259. return found ? t(found.label) : '';
  260. };
  261. const statusBgColor = (status) => {
  262. const map = {
  263. pending: 'warning-bg',
  264. accepted: 'success-bg',
  265. paid: 'success-bg',
  266. started: 'info-bg',
  267. finished: 'neutral-bg',
  268. cancelled: 'secondary-bg',
  269. };
  270. return map[status] ?? 'neutral-bg';
  271. };
  272. const statusLabel = (status) => {
  273. const map = {
  274. pending: t('provider.dashboard.agenda.status_pending'),
  275. accepted: t('provider.dashboard.agenda.status_accepted'),
  276. paid: t('provider.dashboard.agenda.status_paid'),
  277. started: t('provider.dashboard.agenda.status_started'),
  278. finished: t('provider.dashboard.agenda.status_finished'),
  279. cancelled: t('provider.dashboard.agenda.status_cancelled'),
  280. };
  281. return map[status] ?? status;
  282. };
  283. const statusTextColor = (status) => {
  284. const map = {
  285. pending: 'warning',
  286. accepted: 'success',
  287. paid: 'success',
  288. started: 'info',
  289. finished: 'status-finished',
  290. cancelled: 'secondary',
  291. };
  292. return map[status] ?? 'text';
  293. };
  294. //
  295. const loadCalendar = async () => {
  296. const response = await getProviderCalendar();
  297. if (response) {
  298. upcomingSchedules.value = response.upcomingSchedules ?? [];
  299. completedSchedules.value = response.completedSchedules ?? [];
  300. }
  301. };
  302. const openDetailsDialog = (schedule) => {
  303. $q.dialog({
  304. component: NextSchedulesDetailsDialog,
  305. componentProps: { schedule },
  306. }).onOk(async ({ action }) => {
  307. if (action === 'cancelled') {
  308. await loadCalendar();
  309. }
  310. });
  311. };
  312. const openRatingDialog = (schedule) => {
  313. $q.dialog({
  314. component: ScheduleRatingDialog,
  315. componentProps: { schedule },
  316. }).onOk(() => {
  317. loadCalendar();
  318. });
  319. };
  320. onMounted(async () => {
  321. await loadCalendar();
  322. loading.value = false;
  323. });
  324. </script>
  325. <style scoped lang="scss">
  326. .calendar-header {
  327. padding-top: 12px;
  328. padding-bottom: 12px;
  329. box-shadow: 0px 1px 8px rgba(0, 0, 0, 0.08);
  330. }
  331. .calendar-card {
  332. border-radius: 12px;
  333. width: 100%;
  334. }
  335. .type-label {
  336. line-height: 1.2;
  337. }
  338. .text-price {
  339. color: #3a3a4a;
  340. white-space: nowrap;
  341. }
  342. .text-period {
  343. color: #888;
  344. text-align: right;
  345. white-space: nowrap;
  346. }
  347. .status-chip {
  348. height: auto;
  349. }
  350. .btn-rate {
  351. padding: 3px 10px;
  352. }
  353. </style>