302 lines
10 KiB
Vue
302 lines
10 KiB
Vue
<script setup>
|
|
import Master from "../../layouts/master.vue";
|
|
import { ref, reactive } from 'vue';
|
|
import TableGeneric from "../../components/TableGeneric.vue";
|
|
import { Link } from "@inertiajs/inertia-vue3";
|
|
import { useConfirm } from 'primevue/useconfirm';
|
|
import { useToast } from 'primevue/usetoast';
|
|
import { useDocumentStore } from "../../store/Document.js";
|
|
import { useUserStore } from "../../store/User.js";
|
|
import { usePetStore } from "../../store/Pet.js";
|
|
const documentStore = useDocumentStore();
|
|
const toast = useToast();
|
|
const userStore = useUserStore();
|
|
const petStore = usePetStore();
|
|
const props = defineProps({
|
|
documents: {
|
|
type: Object,
|
|
},
|
|
search: {
|
|
type: String
|
|
},
|
|
status: {
|
|
type: String
|
|
},
|
|
priority: {
|
|
type: String
|
|
},
|
|
pet: {
|
|
type: String
|
|
},
|
|
permissions_edit: {
|
|
type: Boolean
|
|
},
|
|
permissions_delete: {
|
|
type: Boolean
|
|
}
|
|
})
|
|
|
|
const documents = ref(props.documents ?? []);
|
|
const selectedItems = ref([]);
|
|
const searchLoader = ref(false);
|
|
const filterLoader = ref(false);
|
|
|
|
const columns = ref(documentStore.columns)
|
|
|
|
const queryParams = reactive({
|
|
search: props.search ?? '',
|
|
status: props.status ?? '',
|
|
priority: props.priority ?? '',
|
|
pet: props.pet ?? '',
|
|
})
|
|
|
|
const filters = ref({
|
|
status: props.status ?? '',
|
|
priority: props.priority ?? '',
|
|
pet: props.pet ?? '',
|
|
})
|
|
|
|
const confirm = useConfirm();
|
|
|
|
const onPageChange = (event) => {
|
|
documentStore.navigateToPage(event.page + 1);
|
|
};
|
|
|
|
const searchData = () => {
|
|
searchLoader.value = true;
|
|
|
|
const searchParams = {
|
|
...(queryParams.search && { search: queryParams.search }),
|
|
...(queryParams.status && { status: queryParams.status }),
|
|
...(queryParams.priority && { priority: queryParams.priority }),
|
|
...(queryParams.pet && { pet: queryParams.pet }),
|
|
...documentStore.convertFiltersToArrayParams(filters.value)
|
|
};
|
|
documentStore.search(searchParams);
|
|
}
|
|
|
|
const exportData = () => {
|
|
const exportParams = {
|
|
...(queryParams.search && { search: queryParams.search }),
|
|
...(queryParams.status && { status: queryParams.status }),
|
|
...(queryParams.priority && { priority: queryParams.priority }),
|
|
...(queryParams.pet && { pet: queryParams.pet }),
|
|
...documentStore.convertFiltersToArrayParams(filters.value)
|
|
};
|
|
documentStore.exportData(exportParams);
|
|
}
|
|
|
|
const onSelectionChange = (selection) => {
|
|
selectedItems.value = selection;
|
|
};
|
|
|
|
|
|
const onSearchChange = (value) => {
|
|
queryParams.search = value;
|
|
searchData();
|
|
};
|
|
|
|
const showDeleteConfirm = (data) => {
|
|
confirm.require({
|
|
group: 'deleteTemplate',
|
|
header: 'مطمعن هستید؟',
|
|
message: 'اگر به عملیات اطمینان دارید، تأیید کنید.',
|
|
icon: 'fi fi-rr-info',
|
|
rejectProps: {
|
|
label: 'انصراف',
|
|
icon: 'fi fi-rr-ban',
|
|
outlined: true,
|
|
size: 'small',
|
|
class: '!text-xs !flex pt-1 !item-center',
|
|
iconClass: '!flex !text-xs',
|
|
},
|
|
acceptProps: {
|
|
label: 'حذف',
|
|
icon: 'fi fi-rr-check',
|
|
size: 'small',
|
|
class: '!text-xs !flex pt-1 !item-center',
|
|
iconClass: '!flex !text-xs',
|
|
},
|
|
accept: () => {
|
|
documentStore.deleteRecord(data.id);
|
|
},
|
|
reject: () => {
|
|
|
|
}
|
|
});
|
|
}
|
|
|
|
const confirmDeleteSelected = (ids) => {
|
|
confirm.require({
|
|
group: 'deleteTemplate',
|
|
header: 'مطمعن هستید؟',
|
|
message: 'اگر به عملیات اطمینان دارید، تأیید کنید.',
|
|
icon: 'fi fi-rr-info',
|
|
rejectProps: {
|
|
label: 'انصراف',
|
|
icon: 'fi fi-rr-ban',
|
|
outlined: true,
|
|
size: 'small',
|
|
class: '!text-xs !flex pt-1 !item-center',
|
|
iconClass: '!flex !text-xs',
|
|
},
|
|
acceptProps: {
|
|
label: 'حذف',
|
|
icon: 'fi fi-rr-check',
|
|
size: 'small',
|
|
class: '!text-xs !flex pt-1 !item-center',
|
|
iconClass: '!flex !text-xs',
|
|
},
|
|
accept: () => {
|
|
documentStore.bulkDelete(ids);
|
|
},
|
|
reject: () => {
|
|
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
const onFilterChange = (newFilters) => {
|
|
filters.value = { ...newFilters };
|
|
Object.keys(newFilters).forEach(key => {
|
|
if (Array.isArray(newFilters[key])) {
|
|
queryParams[key] = newFilters[key].join(',');
|
|
} else {
|
|
queryParams[key] = newFilters[key] || '';
|
|
}
|
|
});
|
|
};
|
|
|
|
const applyFilters = () => {
|
|
filterLoader.value = true;
|
|
searchData();
|
|
};
|
|
|
|
const clearFilters = () => {
|
|
filters.value = {
|
|
status: null,
|
|
priority: null,
|
|
pet: null,
|
|
};
|
|
queryParams.status = '';
|
|
queryParams.priority = '';
|
|
queryParams.pet = '';
|
|
searchData();
|
|
};
|
|
|
|
</script>
|
|
|
|
<template>
|
|
<master>
|
|
<div class="mb-4 grid grid-cols-2a justify-between items-center bg-white border-[1px] border-client-gray/20 py-4 px-4 rounded-2xl">
|
|
<h2 class="font-bold text-client-Fontcolor">{{ documentStore.indexPageTitle }}</h2>
|
|
<Button severity="secondary" asChild v-slot="slotProps">
|
|
<Link :class="slotProps.class" :href="documentStore.endpoints.create">
|
|
<span class="text-sm">{{ documentStore.pageTitle }}</span>
|
|
<i class="fi fi-rr-plus flex text-sm"></i>
|
|
</Link>
|
|
</Button>
|
|
</div>
|
|
<div class="card border-[1px] border-client-gray/20 bg-white rounded-2xl">
|
|
<TableGeneric
|
|
:data="documents.data"
|
|
:columns="columns"
|
|
:selectable="true"
|
|
:pagination="documents.meta"
|
|
:searchable="true"
|
|
:searchValue="queryParams.search"
|
|
:filters="filters"
|
|
:filterLoader="filterLoader"
|
|
v-model="selectedItems"
|
|
@selection-change="onSelectionChange"
|
|
@page-change="onPageChange"
|
|
@search-change="onSearchChange"
|
|
@filter-change="onFilterChange"
|
|
@clear-filters="clearFilters"
|
|
@apply-filters="applyFilters"
|
|
>
|
|
<template #bulk-action="{ selection }">
|
|
<Button
|
|
v-if="!permissions_delete"
|
|
label="حذف همه"
|
|
size="small"
|
|
:pt="{icon : 'flex'}"
|
|
icon="fi fi-rr-trash"
|
|
severity="danger"
|
|
class="!text-xs !flex"
|
|
outlined
|
|
@click="() => confirmDeleteSelected(selection.map(document => document.id))"
|
|
/>
|
|
</template>
|
|
|
|
<template #toolbar-actions>
|
|
<div class="grid grid-cols-a gap-4 justify-start">
|
|
<Button
|
|
label="خروجی اکسل"
|
|
:pt="{icon : 'flex'}"
|
|
icon="fi fi-rr-file-export"
|
|
class="!text-xs !bg-client-primary"
|
|
@click="exportData"
|
|
/>
|
|
</div>
|
|
</template>
|
|
|
|
<template #column-status="{ data }">
|
|
<Tag
|
|
class="!text-xs"
|
|
:value="data.status"
|
|
:severity="documentStore.getStatusSeverity(data.status)"
|
|
/>
|
|
</template>
|
|
|
|
<template #column-priority="{ data }">
|
|
<Tag
|
|
class="!text-xs"
|
|
:value="data.priority"
|
|
:severity="documentStore.getPrioritySeverity(data.priority)"
|
|
/>
|
|
</template>
|
|
|
|
<template #column-requester="{ data }">
|
|
<div class="grid grid-cols-2a justify-start gap-2">
|
|
<span class="text-right text-sm">{{ data.requester?.fullname }}</span>
|
|
<Link :href="userStore.endpoints.edit(data.requester?.id)" class="text-sm">
|
|
<i class="fi fi-rr-eye flex !text-xs !text-client-Fontcolor/40"></i>
|
|
</Link>
|
|
</div>
|
|
</template>
|
|
|
|
<template #column-pet="{ data }">
|
|
<div class="grid grid-cols-2a justify-start gap-2">
|
|
<span class="text-right text-sm">{{ data.pet?.name }}</span>
|
|
<Link :href="petStore.endpoints.edit(data.pet?.id)" class="text-sm">
|
|
<i class="fi fi-rr-eye flex !text-xs !text-client-Fontcolor/40"></i>
|
|
</Link>
|
|
</div>
|
|
</template>
|
|
|
|
<template #column-actions="{ data }">
|
|
<div class="grid grid-cols-2a justify-start gap-2">
|
|
<Button
|
|
v-if="!permissions_delete"
|
|
type="button"
|
|
class="!w-8 !h-8"
|
|
variant="outlined"
|
|
severity="danger"
|
|
icon="fi fi-rr-trash"
|
|
:pt="{icon : '!mt-2 !text-xs'}"
|
|
@click="showDeleteConfirm(data)"
|
|
/>
|
|
<Button v-if="!permissions_edit" severity="info" variant="outlined" asChild v-slot="slotProps">
|
|
<Link :class="[slotProps.class , '!w-8 !h-8']" :href="documentStore.endpoints.edit(data.id)">
|
|
<i class="fi fi-rr-pen-clip flex !text-xs"></i>
|
|
</Link>
|
|
</Button>
|
|
</div>
|
|
</template>
|
|
</TableGeneric>
|
|
</div>
|
|
</master>
|
|
</template>
|