From 70ef728405d7d363625902012dd2a8513b0a1d98 Mon Sep 17 00:00:00 2001 From: wangxiaoxian <1094175543@qq.com> Date: Wed, 4 Mar 2026 15:14:11 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/rental/Detail.vue | 124 +++++++++++++++++++++++++++++++----- 1 file changed, 108 insertions(+), 16 deletions(-) diff --git a/src/views/rental/Detail.vue b/src/views/rental/Detail.vue index f9b6b35..2a23b28 100644 --- a/src/views/rental/Detail.vue +++ b/src/views/rental/Detail.vue @@ -69,6 +69,17 @@ +
+ + +
@@ -96,6 +107,17 @@ +
+ + +
@@ -192,6 +214,14 @@ export default { activeTab: 'rental', // 保存返回时的查询参数 returnQuery: {}, + // 分页相关 - 租赁档案 + currentPage: 1, + pageSize: 10, + total: 0, + // 分页相关 - 水费记录 + waterCurrentPage: 1, + waterPageSize: 10, + waterTotal: 0, waterBillDialogVisible: false, waterBillForm: { id: '', @@ -239,6 +269,16 @@ export default { this.returnQuery = this.$route.query this.loadData() }, + watch: { + activeTab: function() { + // 当tab切换时,刷新对应的数据 + if (this.activeTab === 'rental') { + this.loadRentalHistory() + } else if (this.activeTab === 'water') { + this.loadWaterBills() + } + } + }, methods: { async loadData() { this.isLoading = true @@ -259,34 +299,86 @@ export default { this.room.apartmentName = apartment ? apartment.name : '' } - // 加载租房数据 - const rentalsResponse = await rentalApi.getAll() - this.rentals = rentalsResponse.data || rentalsResponse - - // 加载水费数据 - const waterBillsResponse = await waterBillApi.getAll({ roomId }) - this.waterBills = (waterBillsResponse.data || waterBillsResponse) - .sort((a, b) => new Date(b.createTime) - new Date(a.createTime)) - // 加载租赁历史 - this.loadRentalHistory() + await this.loadRentalHistory() + + // 如果当前激活的是水费tab,加载水费数据 + if (this.activeTab === 'water') { + await this.loadWaterBills() + } } catch (error) { this.$message.error('加载数据失败') } finally { this.isLoading = false } }, - loadRentalHistory() { - const roomId = this.$route.params.id - this.rentalHistory = this.rentals - .filter(r => r.roomId == roomId) - .map(rental => { + async loadWaterBills() { + this.isLoading = true + try { + const roomId = this.$route.params.id + // 调用API获取水费记录,支持分页 + const response = await waterBillApi.getAll({ + roomId, + page: this.waterCurrentPage, + pageSize: this.waterPageSize + }) + + // 处理返回数据 + this.waterBills = response.data || response + + // 设置总数 + this.waterTotal = response.total || 0 + } catch (error) { + this.$message.error('加载水费记录失败') + } finally { + this.isLoading = false + } + }, + async loadRentalHistory() { + this.isLoading = true + try { + const roomId = this.$route.params.id + // 调用API获取当前房间的租赁记录,支持分页 + const response = await rentalApi.getAll({ + roomId, + page: this.currentPage, + pageSize: this.pageSize + }) + + // 处理返回数据 + const data = response.data || response + this.rentalHistory = data.map(rental => { return { ...rental, tenantName: rental.Tenant ? rental.Tenant.name : '' } }) - .sort((a, b) => new Date(b.createTime) - new Date(a.createTime)) + + // 设置总数 + this.total = response.total || 0 + } catch (error) { + this.$message.error('加载租赁历史失败') + } finally { + this.isLoading = false + } + }, + handleSizeChange(size) { + this.pageSize = size + this.currentPage = 1 + this.loadRentalHistory() + }, + handleCurrentChange(current) { + this.currentPage = current + this.loadRentalHistory() + }, + handleWaterSizeChange(size) { + this.waterPageSize = size + this.waterCurrentPage = 1 + this.loadWaterBills() + }, + handleWaterCurrentChange(current) { + this.waterCurrentPage = current + this.loadWaterBills() }, getStatusType(status) { switch (status) {