diff --git a/src/service/BelongingService.js b/src/service/BelongingService.js
index da7623d..9ffd5d9 100644
--- a/src/service/BelongingService.js
+++ b/src/service/BelongingService.js
@@ -27,6 +27,33 @@ export const BelongingService = {
console.log(err);
}
},
+ searchBelongings: async (query) => {
+ const config = {
+ method: 'get',
+ url: '/api/belongings/admin/search',
+ withCredentials: true,
+ params: query
+ };
+ try {
+ const response = await axios(config);
+ return response.data;
+ } catch (err) {
+ console.log(err);
+ }
+ },
+ indexBelongings: async () => {
+ const config = {
+ method: 'post',
+ url: '/api/belongings/admin/index-all',
+ withCredentials: true
+ };
+ try {
+ const response = await axios(config);
+ return response.data;
+ } catch (err) {
+ console.log(err);
+ }
+ },
createBelonging: async (data) => {
const config = {
method: 'post',
diff --git a/src/views/pages/Belonging/CreateBelonging.vue b/src/views/pages/Belonging/CreateBelonging.vue
index 2bba81a..a03c9d1 100644
--- a/src/views/pages/Belonging/CreateBelonging.vue
+++ b/src/views/pages/Belonging/CreateBelonging.vue
@@ -288,7 +288,7 @@ const formatDate = (dateString) => {
-
+
@@ -299,8 +299,8 @@ const formatDate = (dateString) => {
{{ belonging.name }}
-
-
+
+
@@ -349,7 +349,7 @@ const formatDate = (dateString) => {
-
+
{
:globalFilterFields="['type', 'status', 'value', 'date', 'description']"
>
-
-
تراکنشها
+
-
-
+
+
@@ -416,7 +415,7 @@ const formatDate = (dateString) => {
-
+
diff --git a/src/views/pages/Belonging/ListBelongings.vue b/src/views/pages/Belonging/ListBelongings.vue
index 1463c8e..ab4f9e7 100644
--- a/src/views/pages/Belonging/ListBelongings.vue
+++ b/src/views/pages/Belonging/ListBelongings.vue
@@ -2,12 +2,16 @@
import { ProductService } from '@/service/ProductService';
import { FilterMatchMode } from '@primevue/core/api';
import { useToast } from 'primevue/usetoast';
-import { onMounted, ref } from 'vue';
+import { onMounted, ref, watch } from 'vue';
import { BelongingService } from '@/service/BelongingService';
-import { useRouter } from 'vue-router';
+import { useRouter, useRoute } from 'vue-router';
+import Chip from 'primevue/chip';
+import InputIcon from 'primevue/inputicon';
+import IconField from 'primevue/iconfield';
+import LoadingCheck from '@/components/LoadingCheck.vue';
onMounted(() => {
- BelongingService.getAllBelongings().then((data) => (belongings.value = data));
+ loadData();
});
const toast = useToast();
@@ -23,12 +27,6 @@ const filters = ref({
});
const submitted = ref(false);
-function openNew() {
- product.value = {};
- submitted.value = false;
- productDialog.value = true;
-}
-
function hideDialog() {
productDialog.value = false;
submitted.value = false;
@@ -40,69 +38,115 @@ function editBelonging(belongingId) {
router.push('/belonging/edit-belonging/' + belongingId);
}
-function confirmDeleteProduct(prod) {
- product.value = prod;
- deleteProductDialog.value = true;
-}
+const route = useRoute();
+const searchPhrase = ref(route.query.query);
+const page = ref(Number(route.query.page) || 1);
+const per_page = ref(Number(route.query.per_page) || 20);
+const totalCount = ref(0);
+const pagesCount = ref(0);
-function deleteProduct() {
- products.value = products.value.filter((val) => val.id !== product.value.id);
- deleteProductDialog.value = false;
- product.value = {};
- toast.add({ severity: 'success', summary: 'Successful', detail: 'Product Deleted', life: 3000 });
-}
+let searchTimeout;
-function findIndexById(id) {
- let index = -1;
- for (let i = 0; i < products.value.length; i++) {
- if (products.value[i].id === id) {
- index = i;
- break;
+// Update your search watcher
+watch(searchPhrase, (newPhrase, oldPhrase) => {
+ if (newPhrase !== oldPhrase) {
+ // Debounce search to avoid too many requests
+ if (searchTimeout) clearTimeout(searchTimeout);
+ searchTimeout = setTimeout(() => {
+ router.push({
+ query: {
+ ...route.query,
+ query: newPhrase || undefined,
+ page: 1 // Reset to first page on new search
+ }
+ });
+ }, 300);
+ }
+});
+
+watch(
+ () => route.query,
+ () => {
+ page.value = Number(route.query.page) || 1;
+ per_page.value = Number(route.query.per_page) || 20;
+ searchPhrase.value = route.query.query || '';
+ loadData();
+ },
+ { deep: true }
+);
+const handleRemoveSearch = () => {
+ removeFromQuery('searchPhrase'); // Ensure 'searchPhrase' is the correct key
+ searchPhrase.value = '';
+};
+
+const removeFromQuery = (queryToRemove) => {
+ const newQuery = { ...route.query };
+
+ delete newQuery[queryToRemove];
+
+ router.replace({ query: newQuery }).catch((err) => {
+ if (err.name !== 'NavigationDuplicated') {
+ console.error(err);
}
+ });
+};
+
+const onPageChange = (event) => {
+ const newPage = event.page + 1;
+ const newPerPage = event.rows;
+
+ if (page.value !== newPage || per_page.value !== newPerPage) {
+ router.push({
+ query: {
+ ...route.query,
+ page: newPage,
+ per_page: newPerPage
+ }
+ });
}
+};
- return index;
-}
+const loadData = () => {
+ BelongingService.searchBelongings(route.query)
+ .then((response) => {
+ console.log('response', response);
+ belongings.value = response.belongings || response;
+ totalCount.value = response.totalCount || response.length || 0;
+ pagesCount.value = Math.ceil(totalCount.value / per_page.value);
+ })
+ .catch((error) => {
+ toast.add({ severity: 'error', summary: 'Error', detail: 'Failed to load data', life: 3000 });
+ console.error('Error loading data:', error);
+ });
+};
-function createId() {
- let id = '';
- var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
- for (var i = 0; i < 5; i++) {
- id += chars.charAt(Math.floor(Math.random() * chars.length));
+const loading = ref(false);
+const indexingFinished = ref(false);
+const indexingMessage = ref('در حال ایندکس...');
+const animationKey = ref(0);
+
+// Function to handle indexing
+const indexBelongings = async () => {
+ loading.value = true;
+ indexingFinished.value = false;
+
+ try {
+ // Your indexing logic here
+ // await new Promise((resolve) => setTimeout(resolve, 2000)); // Simulate API call
+ await BelongingService.indexBelongings();
+ // When indexing completes
+ indexingFinished.value = true;
+ indexingMessage.value = 'ایندکس با موفقیت انجام شد';
+ } catch (error) {
+ indexingMessage.value = 'خطا در ایندکس';
+ } finally {
+ // Reset after some time
+ setTimeout(() => {
+ loading.value = false;
+ animationKey.value++; // Force re-render of animation
+ }, 3000);
}
- return id;
-}
-
-function exportCSV() {
- dt.value.exportCSV();
-}
-
-function confirmDeleteSelected() {
- deleteProductsDialog.value = true;
-}
-
-function deleteSelectedBelongings() {
- belonging.value = belonging.value.filter((val) => !selectedBelongings.value.includes(val));
- deleteProductsDialog.value = false;
- selectedBelongings.value = null;
- toast.add({ severity: 'success', summary: 'Successful', detail: 'Products Deleted', life: 3000 });
-}
-
-function getStatusLabel(status) {
- switch (status) {
- case 'INSTOCK':
- return 'success';
-
- case 'LOWSTOCK':
- return 'warn';
-
- case 'OUTOFSTOCK':
- return 'danger';
-
- default:
- return null;
- }
-}
+};
@@ -110,8 +154,18 @@ function getStatusLabel(status) {
-
-
+
+
@@ -123,35 +177,39 @@ function getStatusLabel(status) {
:value="belongings"
dataKey="id"
:paginator="true"
- :rows="20"
+ :rows="per_page"
:filters="filters"
+ :total-records="totalCount"
+ :current-page="page - 1"
+ @page="onPageChange($event)"
paginatorTemplate="FirstPageLink PrevPageLink PageLinks NextPageLink LastPageLink CurrentPageReport RowsPerPageDropdown"
:rowsPerPageOptions="[20, 40, 80]"
currentPageReportTemplate="نمایش {first} تا {last} از {totalRecords} دارایی"
>
-
+
مدیریت اموال
-
+
+
-
+
- {{ slotProps.data.category?.nativeName }}
+ {{ slotProps.data.category?.nativeName || slotProps.data.nativeCategory }}
@@ -163,63 +221,6 @@ function getStatusLabel(status) {
-
-