|
|
@@ -0,0 +1,140 @@
|
|
|
+<template>
|
|
|
+ <q-dialog ref="dialogRef" @hide="onDialogHide">
|
|
|
+ <q-card style="min-width: 640px; max-width: 95vw">
|
|
|
+ <DefaultDialogHeader
|
|
|
+ :title="() => title"
|
|
|
+ icon="mdi-trash-can-outline"
|
|
|
+ @close="onClose"
|
|
|
+ />
|
|
|
+
|
|
|
+ <q-separator />
|
|
|
+
|
|
|
+ <q-card-section class="q-pa-none">
|
|
|
+ <div v-if="loading" class="flex flex-center q-pa-xl">
|
|
|
+ <q-spinner color="violet-normal" size="40px" />
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <DefaultTable
|
|
|
+ v-else
|
|
|
+ v-model:rows="rows"
|
|
|
+ :columns="columns"
|
|
|
+ no-api-call
|
|
|
+ :show-search-field="false"
|
|
|
+ >
|
|
|
+ <template #body-cell-actions="{ row }">
|
|
|
+ <q-btn
|
|
|
+ outline
|
|
|
+ dense
|
|
|
+ no-caps
|
|
|
+ color="violet-normal"
|
|
|
+ icon="mdi-restore"
|
|
|
+ :label="$t('parceiro.restore')"
|
|
|
+ :loading="restoringId === row.id"
|
|
|
+ :disable="!!restoringId"
|
|
|
+ @click.prevent.stop="onRestore(row)"
|
|
|
+ />
|
|
|
+ </template>
|
|
|
+ </DefaultTable>
|
|
|
+ </q-card-section>
|
|
|
+ </q-card>
|
|
|
+ </q-dialog>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script setup>
|
|
|
+import { ref, computed, onMounted } from "vue";
|
|
|
+import { useDialogPluginComponent, useQuasar } from "quasar";
|
|
|
+import { useI18n } from "vue-i18n";
|
|
|
+import { getTrashedPartnerAgreements, restorePartnerAgreement } from "src/api/partnerAgreement";
|
|
|
+
|
|
|
+import DefaultDialogHeader from "src/components/defaults/DefaultDialogHeader.vue";
|
|
|
+import DefaultTable from "src/components/defaults/DefaultTable.vue";
|
|
|
+
|
|
|
+const props = defineProps({
|
|
|
+ entityType: { type: String, required: true },
|
|
|
+});
|
|
|
+
|
|
|
+defineEmits([...useDialogPluginComponent.emits]);
|
|
|
+
|
|
|
+const { t } = useI18n();
|
|
|
+const $q = useQuasar();
|
|
|
+const { dialogRef, onDialogHide, onDialogOK, onDialogCancel } = useDialogPluginComponent();
|
|
|
+
|
|
|
+const rows = ref([]);
|
|
|
+const loading = ref(true);
|
|
|
+const restoringId = ref(null);
|
|
|
+const restoredAny = ref(false);
|
|
|
+
|
|
|
+const title = computed(() =>
|
|
|
+ props.entityType === "agreement"
|
|
|
+ ? t("parceiro.deleted_convenios_title")
|
|
|
+ : t("parceiro.deleted_parceiros_title"),
|
|
|
+);
|
|
|
+
|
|
|
+const columns = computed(() => [
|
|
|
+ {
|
|
|
+ name: "company_name",
|
|
|
+ label: t("parceiro.company_name"),
|
|
|
+ field: "company_name",
|
|
|
+ align: "left",
|
|
|
+ sortable: false,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: "deleted_at",
|
|
|
+ label: t("parceiro.deleted_at"),
|
|
|
+ field: (row) => formatDateTime(row.deleted_at),
|
|
|
+ align: "left",
|
|
|
+ sortable: false,
|
|
|
+ },
|
|
|
+ { name: "actions", label: t("common.terms.actions"), field: "actions", align: "right" },
|
|
|
+]);
|
|
|
+
|
|
|
+const formatDateTime = (value) => {
|
|
|
+ if (!value) return "—";
|
|
|
+ const d = new Date(value.replace(" ", "T"));
|
|
|
+ if (Number.isNaN(d.getTime())) return value;
|
|
|
+ return d.toLocaleString("pt-BR", {
|
|
|
+ day: "2-digit", month: "2-digit", year: "numeric",
|
|
|
+ hour: "2-digit", minute: "2-digit",
|
|
|
+ });
|
|
|
+};
|
|
|
+
|
|
|
+const load = async () => {
|
|
|
+ loading.value = true;
|
|
|
+ try {
|
|
|
+ rows.value = await getTrashedPartnerAgreements({ type: props.entityType });
|
|
|
+ } catch {
|
|
|
+ rows.value = [];
|
|
|
+ $q.notify({ type: "negative", message: t("http.errors.failed") });
|
|
|
+ } finally {
|
|
|
+ loading.value = false;
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
+const onRestore = async (row) => {
|
|
|
+ restoringId.value = row.id;
|
|
|
+ try {
|
|
|
+ await restorePartnerAgreement(row.id);
|
|
|
+ rows.value = rows.value.filter((r) => r.id !== row.id);
|
|
|
+ restoredAny.value = true;
|
|
|
+ $q.notify({ type: "positive", message: t("parceiro.restore_success") });
|
|
|
+
|
|
|
+ if (rows.value.length === 0) {
|
|
|
+ onDialogOK(true);
|
|
|
+ }
|
|
|
+ } catch {
|
|
|
+ $q.notify({ type: "negative", message: t("http.errors.failed") });
|
|
|
+ } finally {
|
|
|
+ restoringId.value = null;
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
+const onClose = () => {
|
|
|
+ if (restoredAny.value) {
|
|
|
+ onDialogOK(true);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ onDialogCancel();
|
|
|
+};
|
|
|
+
|
|
|
+onMounted(load);
|
|
|
+</script>
|