From 0d6ac604594c68d4d9f48c139fdb2712fdd7793b Mon Sep 17 00:00:00 2001 From: morteza-mortezai Date: Tue, 23 Dec 2025 15:52:52 +0330 Subject: [PATCH] pagination for withdraw --- pages/admin/gps/withdraw/index.vue | 90 +++++++++++++++++++++++++++--- 1 file changed, 82 insertions(+), 8 deletions(-) diff --git a/pages/admin/gps/withdraw/index.vue b/pages/admin/gps/withdraw/index.vue index 715139a..41f0926 100644 --- a/pages/admin/gps/withdraw/index.vue +++ b/pages/admin/gps/withdraw/index.vue @@ -91,15 +91,15 @@ - - + + درخواست های برداشت - + @@ -156,6 +156,17 @@ +
+ + +
@@ -167,11 +178,19 @@ export default { layout: 'admin', async asyncData({ $axios, error, query }) { try { - const { data } = await $axios.get('/api/admin/gps/withdraw') - // console.log('data bardasht hahahahhahahah', data) + const page = parseInt(query.page) || 1 + const rows = parseInt(query.rows) || 10 + const { data } = await $axios.get('/api/admin/gps/withdraw', { + params: { + page, + rows + } + }) return { - requestsData: data.data + requestsData: data.data, + totalDocuments: data.totalDocuments || 0, + totalPages: data.totalPages || 1 } } catch (error) { console.log(error) @@ -180,10 +199,13 @@ export default { data() { return { requestsData: [], + totalDocuments: 0, + totalPages: 1, centerDialogVisible: false, requestData: {}, filterText: '', - trackingNumber: null + trackingNumber: null, + pageSize: 10 } }, @@ -207,7 +229,7 @@ export default { const filterText = this.filterText if (!this.filterText.length) return filterUsersByType else { - return this.requestsData.filter(item => { + return filterUsersByType.filter(item => { return ( item.userId.mobile_number.includes(filterText) || item.userId.national_code.includes(filterText) || @@ -217,6 +239,18 @@ export default { }) } }, + totalFilteredItems() { + return this.filteredItems.length + }, + paginatedItems() { + return this.filteredItems + }, + currentPage() { + return parseInt(this.$route.query?.page) || 1 + }, + paginate() { + return this.totalPages > 1 + }, filterType: { get() { return this.$route.query?.filter @@ -226,7 +260,47 @@ export default { } } }, + watch: { + filterText() { + this.fetchData(1) + }, + filterType() { + this.fetchData(1) + }, + '$route.query.page'() { + this.fetchData() + } + }, methods: { + async fetchData(page = null) { + const currentPage = page || this.currentPage + try { + const { data } = await this.$axios.get('/api/admin/gps/withdraw', { + params: { + page: currentPage, + rows: this.pageSize + } + }) + this.requestsData = data.data + this.totalDocuments = data.totalDocuments || 0 + this.totalPages = data.totalPages || 1 + } catch (error) { + console.log(error) + this.$message({ + type: 'error', + message: 'خطا در دریافت اطلاعات' + }) + } + }, + handlePageChange(page) { + this.$router.push({ + name: 'admin-gps-withdraw', + query: { + ...this.$route.query, + page + } + }) + }, showDialog(data) { this.requestData = data this.centerDialogVisible = true