AppointmentsAdminPage.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  1. <template>
  2. <div>
  3. <DefaultHeaderPage />
  4. <div class="row q-gutter-xs q-mb-md flex-wrap">
  5. <div
  6. v-for="tab in tabs"
  7. :key="tab.name"
  8. :class="['cat-chip', activeTab === tab.name ? 'cat-chip--selected' : 'cat-chip--default']"
  9. @click="selectTab(tab.name)"
  10. >
  11. <span v-if="tab.counterKey !== null" class="cat-chip-count q-mr-xs">
  12. {{ counters[tab.counterKey] !== undefined ? counters[tab.counterKey] : '—' }}
  13. </span>
  14. {{ tab.label }}
  15. </div>
  16. </div>
  17. <div v-if="activeTab === 'nova-solicitacao'" class="q-mt-md">
  18. <q-card flat bordered>
  19. <q-card-section>
  20. <q-form ref="formRef" @submit="submitAppointment">
  21. <div class="row q-col-gutter-sm">
  22. <AssociadoSelect
  23. v-model="form.associado"
  24. :label="$t('agendamento.associado')"
  25. :rules="[inputRules.required]"
  26. class="col-12 input-violet"
  27. />
  28. <PartnerAgreementSelect
  29. v-model="form.partner"
  30. :label="$t('ui.navigation.convenios')"
  31. :rules="[inputRules.required]"
  32. class="col-12 input-violet"
  33. />
  34. <PartnerAgreementServiceSelect
  35. v-model="form.service"
  36. :partner-agreement-id="form.partner?.value"
  37. :label="$t('associado.service')"
  38. :rules="[inputRules.required]"
  39. class="col-12 input-violet"
  40. />
  41. <DefaultInputDatePicker
  42. v-model:untreated-date="form.date"
  43. :label="$t('common.terms.date')"
  44. :rules="[inputRules.required]"
  45. placeholder="dd/mm/aaaa"
  46. lazy-rules
  47. class="col-12 col-md-6"
  48. />
  49. <DefaultInput
  50. v-model="form.time"
  51. :label="$t('common.terms.hour2')"
  52. :rules="[inputRules.required]"
  53. mask="##:##"
  54. placeholder="HH:MM"
  55. class="col-12 col-md-6"
  56. />
  57. <DefaultInput
  58. v-model="form.observations"
  59. :label="$t('associado.notes')"
  60. type="textarea"
  61. autogrow
  62. class="col-12"
  63. />
  64. </div>
  65. <div class="q-mt-md flex justify-end">
  66. <q-btn
  67. color="primary"
  68. type="submit"
  69. :label="$t('agendamento.solicitar')"
  70. :loading="submitting"
  71. />
  72. </div>
  73. </q-form>
  74. </q-card-section>
  75. </q-card>
  76. </div>
  77. <div v-else-if="activeTab === 'visao-geral'" class="q-mt-md">
  78. <div class="counters-row q-mb-md">
  79. <div class="counter-card text-primary">
  80. <span class="counter-value">
  81. <q-icon
  82. name="mdi-clock"
  83. color="primary"
  84. />
  85. {{ counters.pendentes !== undefined ? counters.pendentes : '—' }}
  86. </span>
  87. <span class="counter-label">{{ $t("agendamento.status.pendente") }}</span>
  88. </div>
  89. <div class="counter-card text-primary">
  90. <span class="counter-value">
  91. <q-icon
  92. name="mdi-check"
  93. color="primary"
  94. />
  95. {{ counters.aprovados !== undefined ? counters.aprovados : '—' }}
  96. </span>
  97. <span class="counter-label">{{ $t("agendamento.status.confirmado") }}</span>
  98. </div>
  99. <div class="counter-card text-primary">
  100. <span class="counter-value">
  101. <q-icon
  102. name="mdi-close"
  103. color="primary"
  104. />
  105. {{ counters.recusados !== undefined ? counters.recusados : '—' }}
  106. </span>
  107. <span class="counter-label">{{ $t("agendamento.status.recusado") }}</span>
  108. </div>
  109. </div>
  110. <DefaultTableServerSide
  111. :key="tableKey"
  112. :columns="columnsVisaoGeral"
  113. :api-call="apiFetchAll"
  114. :add-item="false"
  115. :show-search-field="true"
  116. >
  117. <template #body-cell-service_name="{ row }">
  118. <q-td>
  119. {{ excerpt(row.service_name || '—', 35) }}
  120. <q-tooltip v-if="row.service_name">{{ row.service_name }}</q-tooltip>
  121. </q-td>
  122. </template>
  123. <template #body-cell-status="{ row }">
  124. <q-td class="text-center">
  125. <q-chip
  126. outline
  127. :color="statusColor(row.status)"
  128. :label="$t(`agendamento.status.${row.status}`)"
  129. size="sm"
  130. />
  131. </q-td>
  132. </template>
  133. <template #body-cell-acoes="{ row }">
  134. <q-td auto-width>
  135. <div class="row no-wrap items-center" style="gap: 4px">
  136. <q-btn
  137. dense
  138. round
  139. icon="mdi-check"
  140. color="positive"
  141. size="sm"
  142. :unelevated="row.status === 'confirmado'"
  143. :outline="row.status !== 'confirmado'"
  144. :loading="actionId === row.id && actionType === 'approve'"
  145. @click.prevent.stop="onApprove(row)"
  146. />
  147. <q-btn
  148. dense
  149. round
  150. icon="mdi-close"
  151. color="negative"
  152. size="sm"
  153. :unelevated="row.status === 'recusado' || row.status === 'cancelado'"
  154. :outline="row.status !== 'recusado' && row.status !== 'cancelado'"
  155. :loading="actionId === row.id && actionType === 'reject'"
  156. @click.prevent.stop="onReject(row)"
  157. />
  158. </div>
  159. </q-td>
  160. </template>
  161. </DefaultTableServerSide>
  162. </div>
  163. <div v-else-if="activeTab === 'aprovados'" class="q-mt-md">
  164. <DefaultTableServerSide
  165. :key="tableKey"
  166. :columns="columnsAprovados"
  167. :api-call="apiFetchAprovados"
  168. :add-item="false"
  169. :show-search-field="true"
  170. >
  171. <template #body-cell-service_name="{ row }">
  172. <q-td>
  173. {{ excerpt(row.service_name || '—', 35) }}
  174. <q-tooltip v-if="row.service_name">{{ row.service_name }}</q-tooltip>
  175. </q-td>
  176. </template>
  177. <template #body-cell-status>
  178. <q-td class="text-center">
  179. <q-chip
  180. outline
  181. color="positive"
  182. :label="$t('agendamento.status.confirmado')"
  183. size="sm"
  184. />
  185. </q-td>
  186. </template>
  187. </DefaultTableServerSide>
  188. </div>
  189. </div>
  190. </template>
  191. <script setup>
  192. import { ref, computed, onMounted, useTemplateRef, nextTick } from "vue";
  193. import { useQuasar } from "quasar";
  194. import { useI18n } from "vue-i18n";
  195. import { useInputRules } from "src/composables/useInputRules";
  196. import { excerpt } from "src/helpers/utils";
  197. import DefaultHeaderPage from "src/components/layout/DefaultHeaderPage.vue";
  198. import DefaultTableServerSide from "src/components/defaults/DefaultTableServerSide.vue";
  199. import DefaultInput from "src/components/defaults/DefaultInput.vue";
  200. import DefaultInputDatePicker from "src/components/defaults/DefaultInputDatePicker.vue";
  201. import AssociadoSelect from "src/components/selects/AssociadoSelect.vue";
  202. import PartnerAgreementSelect from "src/components/selects/PartnerAgreementSelect.vue";
  203. import PartnerAgreementServiceSelect from "src/components/selects/PartnerAgreementServiceSelect.vue";
  204. import ApproveAppointmentDialog from "src/components/ApproveAppointmentDialog.vue";
  205. import {
  206. getAdminCounters,
  207. getAdminAppointmentsPaginated,
  208. createAppointment,
  209. approveAppointment,
  210. rejectAppointment,
  211. } from "src/api/appointment";
  212. const $q = useQuasar();
  213. const { t } = useI18n();
  214. const { inputRules } = useInputRules();
  215. const formRef = useTemplateRef("formRef");
  216. const activeTab = ref("nova-solicitacao");
  217. const tableKey = ref(0);
  218. const submitting = ref(false);
  219. const actionId = ref(null);
  220. const actionType = ref(null);
  221. const counters = ref({
  222. pendentes: undefined,
  223. aprovados: undefined,
  224. recusados: undefined,
  225. });
  226. const form = ref({
  227. associado: null,
  228. partner: null,
  229. service: null,
  230. date: "",
  231. time: "",
  232. observations: "",
  233. });
  234. const tabs = computed(() => [
  235. {
  236. name: "nova-solicitacao",
  237. label: t("agendamento.nova_solicitacao"),
  238. icon: "mdi-calendar-plus-outline",
  239. counterKey: null,
  240. },
  241. {
  242. name: "visao-geral",
  243. label: t("agendamento.visao_geral"),
  244. icon: "mdi-calendar-check-outline",
  245. counterKey: "pendentes",
  246. },
  247. {
  248. name: "aprovados",
  249. label: t("agendamento.aprovados_automaticamente"),
  250. icon: "mdi-calendar-star-outline",
  251. counterKey: "aprovados",
  252. },
  253. ]);
  254. const columnsVisaoGeral = computed(() => [
  255. { name: "order_number", label: t("agendamento.col.pedido"), field: "order_number", align: "left" },
  256. { name: "cracha", label: t("associado.cracha"), field: "registration", align: "left" },
  257. { name: "user_name", label: t("common.terms.name"), field: "user_name", align: "left" },
  258. { name: "partner_name", label: t("agendamento.col.parceiro"), field: "partner_name", align: "left" },
  259. { name: "service_name", label: t("agendamento.col.servico"), field: "service_name", align: "left" },
  260. { name: "requested_at", label: t("agendamento.col.solicitacao"), field: "requested_at", align: "left" },
  261. { name: "acoes", label: t("common.terms.actions"), field: "acoes", align: "center" },
  262. { name: "status", label: t("common.terms.status"), field: "status", align: "center" },
  263. ]);
  264. const columnsAprovados = computed(() => [
  265. { name: "order_number", label: t("agendamento.col.pedido"), field: "order_number", align: "left" },
  266. { name: "user_name", label: t("common.terms.name"), field: "user_name", align: "left" },
  267. { name: "partner_name", label: t("agendamento.col.parceiro"), field: "partner_name", align: "left" },
  268. { name: "service_name", label: t("agendamento.col.servico"), field: "service_name", align: "left" },
  269. { name: "requested_at", label: t("agendamento.col.solicitacao"), field: "requested_at", align: "left" },
  270. { name: "status", label: t("common.terms.status"), field: "status", align: "center" },
  271. ]);
  272. const statusColor = (status) => {
  273. const map = {
  274. pendente: "warning",
  275. confirmado: "positive",
  276. recusado: "negative",
  277. cancelado: "grey-6",
  278. concluido: "info",
  279. };
  280. return map[status] ?? "grey-6";
  281. };
  282. const apiFetchAll = (params) => getAdminAppointmentsPaginated(params);
  283. const apiFetchAprovados = (params) =>
  284. getAdminAppointmentsPaginated({ ...params, status: "confirmado" });
  285. const selectTab = (name) => {
  286. activeTab.value = name;
  287. tableKey.value++;
  288. };
  289. const loadCounters = async () => {
  290. try {
  291. counters.value = await getAdminCounters();
  292. } catch {
  293. // silent
  294. }
  295. };
  296. const resetForm = async () => {
  297. form.value = {
  298. associado: null,
  299. partner: null,
  300. service: null,
  301. date: "",
  302. time: "",
  303. observations: "",
  304. };
  305. await nextTick();
  306. formRef.value?.resetValidation();
  307. };
  308. const submitAppointment = async () => {
  309. const valid = await formRef.value?.validate();
  310. if (!valid) return;
  311. submitting.value = true;
  312. try {
  313. await createAppointment({
  314. user_id: form.value.associado.value,
  315. partner_agreement_id: form.value.partner.value,
  316. partner_agreement_service_id: form.value.service.value,
  317. time: form.value.time,
  318. date: form.value.date,
  319. observations: form.value.observations || null,
  320. });
  321. await resetForm();
  322. await loadCounters();
  323. } catch {
  324. // silent
  325. } finally {
  326. submitting.value = false;
  327. }
  328. };
  329. const onApprove = (row) => {
  330. if (row.status !== "pendente") return;
  331. $q.dialog({ component: ApproveAppointmentDialog }).onOk(async ({ date, time }) => {
  332. actionId.value = row.id;
  333. actionType.value = "approve";
  334. try {
  335. await approveAppointment(row.id, { date, time });
  336. tableKey.value++;
  337. await loadCounters();
  338. } catch {
  339. // silent
  340. } finally {
  341. actionId.value = null;
  342. actionType.value = null;
  343. }
  344. });
  345. };
  346. const onReject = (row) => {
  347. if (row.status !== "pendente") return;
  348. $q.dialog({
  349. title: t("common.ui.messages.confirm_action"),
  350. message: t("agendamento.confirm_reject"),
  351. cancel: true,
  352. persistent: true,
  353. }).onOk(async () => {
  354. actionId.value = row.id;
  355. actionType.value = "reject";
  356. try {
  357. await rejectAppointment(row.id);
  358. tableKey.value++;
  359. await loadCounters();
  360. $q.notify({ type: "positive", message: t("http.success") });
  361. } catch {
  362. $q.notify({ type: "negative", message: t("http.errors.failed") });
  363. } finally {
  364. actionId.value = null;
  365. actionType.value = null;
  366. }
  367. });
  368. };
  369. onMounted(() => {
  370. loadCounters();
  371. });
  372. </script>
  373. <style lang="scss" scoped>
  374. @use "src/css/quasar.variables.scss" as vars;
  375. .cat-chip {
  376. display: inline-flex;
  377. align-items: center;
  378. justify-content: center;
  379. height: 28px;
  380. padding: 0 12px;
  381. border-radius: 5px;
  382. font-size: 12px;
  383. font-weight: 500;
  384. cursor: pointer;
  385. user-select: none;
  386. transition: background 0.15s, color 0.15s;
  387. &--default {
  388. background: #c9a3dc;
  389. color: #fff;
  390. }
  391. &--selected {
  392. background: #4d1658;
  393. color: #fff;
  394. }
  395. }
  396. .cat-chip-count {
  397. font-weight: 700;
  398. }
  399. .counters-row {
  400. display: flex;
  401. gap: 12px;
  402. }
  403. .counter-card {
  404. flex: 1;
  405. display: flex;
  406. flex-direction: column;
  407. align-items: center;
  408. padding: 16px;
  409. border-radius: 8px;
  410. border: 1.5px solid vars.$color-border;
  411. background: vars.$surface;
  412. }
  413. .counter-value {
  414. font-size: 1.75rem;
  415. font-weight: 700;
  416. line-height: 1;
  417. margin-bottom: 4px;
  418. }
  419. .counter-label {
  420. font-size: 0.85rem;
  421. }
  422. </style>